xmlxsltxslt-2.0xslt-3.0xslt-grouping

XSLT Group by using 3 different elements from different node level


I'm new to XSLT, for the below XML, I'm trying to implement this transformation logic: If <wd:candidate>,<wd:CF_LRV_Requisition_ID> and <wd:Stage> have the same combination of values, then sort using <wd:Last_Functionally_Updated> and only output the most recent one.

To achieve this, I'm trying to group 3 elements first: <wd:candidate>, <wd:CF_LRV_Requisition_ID>, and <wd:Stage>. I have no problem grouping <wd:candidate>, <wd:CF_LRV_Requisition_ID>, but <wd:Stage> is from a different node "<wd:Job_Application_Process_Statuses_group>" and that's where I encountered problems.

Below is the test XML file

<?xml version='1.0' encoding='UTF-8'?>
<wd:Report_Data xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
    <wd:Report_Entry>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-03-14T02:02:07.778-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0000000001</wd:candidate>
        <wd:CF_LRV_Requisition_ID>R-0000000412</wd:CF_LRV_Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-04-08T08:12:00.622-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-04-08T08:12:00.622-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Rejected">
                <wd:ID wd:type="WID">9a35fa5882c24620a777de1dbcf34d3c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REJECTED</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0000000089</wd:candidate>
        <wd:CF_LRV_Requisition_ID>R-0000000528</wd:CF_LRV_Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-03-17T12:06:51.499-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-03-22T12:23:48.080-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-03-24T14:21:08.613-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-03-28T15:12:33.101-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-04-04T11:15:39.337-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Interview">
                <wd:ID wd:type="WID">3317e4265cf94b91873b7015881a0e9c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">INTERVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-04-07T11:01:59.639-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Offer">
                <wd:ID wd:type="WID">868a8156682541f2aadc2fe90268b75f</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">OFFER</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-05-13T10:39:08.947-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Background Check">
                <wd:ID wd:type="WID">be56571f9f6f45ca82871c8bec853f5e</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">BACKGROUND</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-05-13T10:39:08.947-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Ready for Hire">
                <wd:ID wd:type="WID">edd55803e2ec49c3a6eb01daadfc9bf9</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">HIRED</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0000000119</wd:candidate>
        <wd:CF_LRV_Requisition_ID>R-0000005173</wd:CF_LRV_Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-04-08T08:12:00.622-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-04-08T08:12:00.622-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Rejected">
                <wd:ID wd:type="WID">9a35fa5882c24620a777de1dbcf34d3c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REJECTED</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0000000051</wd:candidate>
        <wd:CF_LRV_Requisition_ID>R-0000000528</wd:CF_LRV_Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-06-28T11:07:50.328-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-07-26T10:11:23.868-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Screen">
                <wd:ID wd:type="WID">2d0e4a68825d4d2a8c507af7542d3f15</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">SCREEN</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2022-07-26T10:11:23.868-07:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Rejected">
                <wd:ID wd:type="WID">9a35fa5882c24620a777de1dbcf34d3c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REJECTED</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0000000051</wd:candidate>
        <wd:CF_LRV_Requisition_ID>R-0000000549</wd:CF_LRV_Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:40:39.473-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:40:56.234-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Screen">
                <wd:ID wd:type="WID">2d0e4a68825d4d2a8c507af7542d3f15</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">SCREEN</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:41:12.816-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:41:30.312-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Assessment">
                <wd:ID wd:type="WID">bb01594c858710000e4d46d2b7220034</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">ASSESSMENT</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:41:51.302-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:42:10.857-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Interview">
                <wd:ID wd:type="WID">3317e4265cf94b91873b7015881a0e9c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">INTERVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:46:07.095-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Offer (Employment Agreement)">
                <wd:ID wd:type="WID">1d57fbe8504d100015945d2b2704006a</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">EMPLOYMENT_AGREEMENT</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:47:24.651-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Background Check">
                <wd:ID wd:type="WID">be56571f9f6f45ca82871c8bec853f5e</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">BACKGROUND</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:47:24.651-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Ready for Hire">
                <wd:ID wd:type="WID">edd55803e2ec49c3a6eb01daadfc9bf9</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">HIRED</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0001721064</wd:candidate>
        <wd:CF_LRV_Requisition_ID>R-0000106401</wd:CF_LRV_Requisition_ID>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:50:50.192-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:51:21.591-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Screen">
                <wd:ID wd:type="WID">2d0e4a68825d4d2a8c507af7542d3f15</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">SCREEN</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:51:46.584-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Assessment">
                <wd:ID wd:type="WID">bb01594c858710000e4d46d2b7220034</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">ASSESSMENT</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:52:16.212-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Review">
                <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:52:46.050-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Screen">
                <wd:ID wd:type="WID">2d0e4a68825d4d2a8c507af7542d3f15</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">SCREEN</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:53:13.106-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Assessment">
                <wd:ID wd:type="WID">bb01594c858710000e4d46d2b7220034</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">ASSESSMENT</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:53:38.669-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Interview">
                <wd:ID wd:type="WID">3317e4265cf94b91873b7015881a0e9c</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">INTERVIEW</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T05:58:00.444-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Offer (Employment Agreement)">
                <wd:ID wd:type="WID">1d57fbe8504d100015945d2b2704006a</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">EMPLOYMENT_AGREEMENT</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T06:00:15.762-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Background Check">
                <wd:ID wd:type="WID">be56571f9f6f45ca82871c8bec853f5e</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">BACKGROUND</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:Job_Application_Process_Statuses_group>
            <wd:Last_Functionally_Updated>2024-12-18T06:00:15.762-08:00</wd:Last_Functionally_Updated>
            <wd:Stage wd:Descriptor="Declined by Candidate">
                <wd:ID wd:type="WID">6ceb443402a444b49c9e3060c9daeaeb</wd:ID>
                <wd:ID wd:type="Recruiting_Stage_ID">DECLINED</wd:ID>
            </wd:Stage>
        </wd:Job_Application_Process_Statuses_group>
        <wd:candidate>C-0001721065</wd:candidate>
        <wd:CF_LRV_Requisition_ID>R-0000106401</wd:CF_LRV_Requisition_ID>
    </wd:Report_Entry>
</wd:Report_Data>

below is the XSLT using:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application"
    exclude-result-prefixes="wd">
    
    <xsl:output method="text" omit-xml-declaration="no"/>
    
    <xsl:key name="recordKey" match="wd:Report_Entry" use="concat(wd:Stage/@wd:Descriptor, '-', wd:candidate, '-', wd:CF_LRV_Requisition_ID)"/>
    <xsl:variable name="RECORD-DELIMITER">
        <xsl:text>&#xd;&#xa;</xsl:text>
    </xsl:variable>
    <xsl:param name="Dilim">","</xsl:param>
    <xsl:param name="Quote">"</xsl:param>
    <xsl:param name="Comma">,</xsl:param>
    <xsl:variable name="FIELD-DELIMITER">
        <xsl:value-of select="$Dilim"/>
    </xsl:variable>
    <xsl:variable name="STARTING-QUOTE">
        <xsl:value-of select="$Quote"/>
    </xsl:variable>
    
    <xsl:template match="wd:Report_Data">
        <Header>
            <HeaderItem1>"time_stamp"</HeaderItem1>
            <xsl:value-of select="$Comma"/>
            <HeaderItem2>"event"</HeaderItem2>
            <xsl:value-of select="$Comma"/>
            <HeaderItem3>"applyflow_id"</HeaderItem3>
            <xsl:value-of select="$Comma"/>
            <HeaderItem4>"job_id"</HeaderItem4>
        </Header>
        <xsl:value-of select="$RECORD-DELIMITER"/>

        <xsl:for-each-group select="wd:Report_Entry" group-by="concat(wd:candidate, '|', wd:CF_LRV_Requisition_ID, '|', wd:Job_Application_Process_Statuses_group/wd:Stage/wd:ID)">
            
            <xsl:for-each select="current-group()[1]">
                <xsl:value-of select="$STARTING-QUOTE"/>
                    <time_stamp>
                        <xsl:value-of select="current-group()[1]/wd:Job_Application_Process_Statuses_group/wd:Last_Functionally_Updated"/>
                    </time_stamp>
                <xsl:value-of select="$FIELD-DELIMITER"/>
                     <event>
                         <xsl:value-of select="current-group()[1]/wd:Job_Application_Process_Statuses_group/wd:Stage/@wd:Descriptor"/>
                     </event>
                <xsl:value-of select="$FIELD-DELIMITER"/>
                    <applyflow_id>
                        <xsl:value-of select="current-group()[1]/wd:candidate"/>
                    </applyflow_id>  
                <xsl:value-of select="$FIELD-DELIMITER"/>
                    <job_id>
                        <xsl:value-of select="current-group()[1]/wd:CF_LRV_Requisition_ID"/>
                    </job_id>
                <xsl:value-of select="$STARTING-QUOTE"/>
                <xsl:value-of select="$RECORD-DELIMITER"/>
            </xsl:for-each>
        </xsl:for-each-group>
    </xsl:template>
</xsl:stylesheet>

I tried to group the three fields using <xsl:for-each-group select="wd:Report_Entry" group-by="concat(wd:candidate, '|', wd:CF_LRV_Requisition_ID, '|', wd:Job_Application_Process_Statuses_group/wd:Stage/wd:ID)">, but the xslt simply didn't run


Solution

  • Your requirement is difficult to understand as Report_Entrys have sometimes several Job_Application_Process_Statuses_group children so on which elements you want to group is not clear and furthermore Stage elements seem to have to ID children where it is also not clear which one or ones you want to use for grouping.

    Your current code also does no sorting although your textual description mentions sorting.

    To give you an (XSLT 3) example of grouping and sorting the Job_Application_Process_Statuses_group elements with a composite grouping key ../candidate, ../CF_LRV_Requisition_ID , Stage/ID and then sorting each group and process only the last element in sort order see

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="3.0"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      exclude-result-prefixes="#all"
      xpath-default-namespace="urn:com.workday.report/AS_TEST_Job_Application"
      expand-text="yes">
    
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:mode on-no-match="shallow-skip"/>
      
      <xsl:template match="Report_Data">
        <xsl:for-each-group select="Report_Entry/Job_Application_Process_Statuses_group" composite="yes" group-by="../candidate, ../CF_LRV_Requisition_ID , Stage/ID">
          <xsl:apply-templates select="(current-group() => sort((), function($j) { $j/Last_Functionally_Updated }))[last()]"/>
        </xsl:for-each-group>
      </xsl:template>
      
      <xsl:template match="Job_Application_Process_Statuses_group">
        <xsl:comment>{current-grouping-key()}</xsl:comment>
        <xsl:sequence select="."/>
      </xsl:template>
    
    </xsl:stylesheet>
    

    I have output the grouping key in a comment to identify which element from the input is output for a group, I get the result shown below, decide for yourself whether that has the grouping and sorting you need and adapt to your needs if needed.

    <?xml version="1.0" encoding="UTF-8"?>
    <!--C-0000000001 R-0000000412 31350d72f899430fb446b410c1e368cd REVIEW-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-03-14T02:02:07.778-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Review">
          <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0000000089 R-0000000528 31350d72f899430fb446b410c1e368cd REVIEW-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-04-08T08:12:00.622-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Review">
          <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0000000089 R-0000000528 9a35fa5882c24620a777de1dbcf34d3c REJECTED-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-04-08T08:12:00.622-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Rejected">
          <wd:ID wd:type="WID">9a35fa5882c24620a777de1dbcf34d3c</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">REJECTED</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0000000119 R-0000005173 31350d72f899430fb446b410c1e368cd REVIEW-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-03-28T15:12:33.101-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Review">
          <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0000000119 R-0000005173 3317e4265cf94b91873b7015881a0e9c INTERVIEW-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-04-04T11:15:39.337-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Interview">
          <wd:ID wd:type="WID">3317e4265cf94b91873b7015881a0e9c</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">INTERVIEW</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0000000119 R-0000005173 868a8156682541f2aadc2fe90268b75f OFFER-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-04-07T11:01:59.639-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Offer">
          <wd:ID wd:type="WID">868a8156682541f2aadc2fe90268b75f</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">OFFER</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0000000119 R-0000005173 be56571f9f6f45ca82871c8bec853f5e BACKGROUND-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-05-13T10:39:08.947-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Background Check">
          <wd:ID wd:type="WID">be56571f9f6f45ca82871c8bec853f5e</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">BACKGROUND</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0000000119 R-0000005173 edd55803e2ec49c3a6eb01daadfc9bf9 HIRED-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-05-13T10:39:08.947-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Ready for Hire">
          <wd:ID wd:type="WID">edd55803e2ec49c3a6eb01daadfc9bf9</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">HIRED</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0000000051 R-0000000528 31350d72f899430fb446b410c1e368cd REVIEW-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-04-08T08:12:00.622-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Review">
          <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0000000051 R-0000000528 9a35fa5882c24620a777de1dbcf34d3c REJECTED-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-04-08T08:12:00.622-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Rejected">
          <wd:ID wd:type="WID">9a35fa5882c24620a777de1dbcf34d3c</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">REJECTED</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0000000051 R-0000000549 31350d72f899430fb446b410c1e368cd REVIEW-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-06-28T11:07:50.328-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Review">
          <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0000000051 R-0000000549 2d0e4a68825d4d2a8c507af7542d3f15 SCREEN-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-07-26T10:11:23.868-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Screen">
          <wd:ID wd:type="WID">2d0e4a68825d4d2a8c507af7542d3f15</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">SCREEN</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0000000051 R-0000000549 9a35fa5882c24620a777de1dbcf34d3c REJECTED-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2022-07-26T10:11:23.868-07:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Rejected">
          <wd:ID wd:type="WID">9a35fa5882c24620a777de1dbcf34d3c</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">REJECTED</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721064 R-0000106401 31350d72f899430fb446b410c1e368cd REVIEW-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T05:41:51.302-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Review">
          <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721064 R-0000106401 2d0e4a68825d4d2a8c507af7542d3f15 SCREEN-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T05:40:56.234-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Screen">
          <wd:ID wd:type="WID">2d0e4a68825d4d2a8c507af7542d3f15</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">SCREEN</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721064 R-0000106401 bb01594c858710000e4d46d2b7220034 ASSESSMENT-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T05:41:30.312-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Assessment">
          <wd:ID wd:type="WID">bb01594c858710000e4d46d2b7220034</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">ASSESSMENT</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721064 R-0000106401 3317e4265cf94b91873b7015881a0e9c INTERVIEW-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T05:42:10.857-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Interview">
          <wd:ID wd:type="WID">3317e4265cf94b91873b7015881a0e9c</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">INTERVIEW</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721064 R-0000106401 1d57fbe8504d100015945d2b2704006a EMPLOYMENT_AGREEMENT-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T05:46:07.095-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Offer (Employment Agreement)">
          <wd:ID wd:type="WID">1d57fbe8504d100015945d2b2704006a</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">EMPLOYMENT_AGREEMENT</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721064 R-0000106401 be56571f9f6f45ca82871c8bec853f5e BACKGROUND-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T05:47:24.651-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Background Check">
          <wd:ID wd:type="WID">be56571f9f6f45ca82871c8bec853f5e</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">BACKGROUND</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721064 R-0000106401 edd55803e2ec49c3a6eb01daadfc9bf9 HIRED-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T05:47:24.651-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Ready for Hire">
          <wd:ID wd:type="WID">edd55803e2ec49c3a6eb01daadfc9bf9</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">HIRED</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721065 R-0000106401 31350d72f899430fb446b410c1e368cd REVIEW-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T05:52:16.212-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Review">
          <wd:ID wd:type="WID">31350d72f899430fb446b410c1e368cd</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">REVIEW</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721065 R-0000106401 2d0e4a68825d4d2a8c507af7542d3f15 SCREEN-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T05:52:46.050-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Screen">
          <wd:ID wd:type="WID">2d0e4a68825d4d2a8c507af7542d3f15</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">SCREEN</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721065 R-0000106401 bb01594c858710000e4d46d2b7220034 ASSESSMENT-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T05:53:13.106-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Assessment">
          <wd:ID wd:type="WID">bb01594c858710000e4d46d2b7220034</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">ASSESSMENT</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721065 R-0000106401 3317e4265cf94b91873b7015881a0e9c INTERVIEW-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T05:53:38.669-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Interview">
          <wd:ID wd:type="WID">3317e4265cf94b91873b7015881a0e9c</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">INTERVIEW</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721065 R-0000106401 1d57fbe8504d100015945d2b2704006a EMPLOYMENT_AGREEMENT-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T05:58:00.444-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Offer (Employment Agreement)">
          <wd:ID wd:type="WID">1d57fbe8504d100015945d2b2704006a</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">EMPLOYMENT_AGREEMENT</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721065 R-0000106401 be56571f9f6f45ca82871c8bec853f5e BACKGROUND-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T06:00:15.762-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Background Check">
          <wd:ID wd:type="WID">be56571f9f6f45ca82871c8bec853f5e</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">BACKGROUND</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>
    <!--C-0001721065 R-0000106401 6ceb443402a444b49c9e3060c9daeaeb DECLINED-->
    <wd:Job_Application_Process_Statuses_group xmlns:wd="urn:com.workday.report/AS_TEST_Job_Application">
       <wd:Last_Functionally_Updated>2024-12-18T06:00:15.762-08:00</wd:Last_Functionally_Updated>
       <wd:Stage wd:Descriptor="Declined by Candidate">
          <wd:ID wd:type="WID">6ceb443402a444b49c9e3060c9daeaeb</wd:ID>
          <wd:ID wd:type="Recruiting_Stage_ID">DECLINED</wd:ID>
       </wd:Stage>
    </wd:Job_Application_Process_Statuses_group>