0

I need to sum the amount (wd:Amount) if the ContributionType (wd:ContributionType/@wd:Descriptor) is the same by SSN. Below example, I am expecting the record to be shown: D|123-45-6789|20230315|2023|EE|103.76|ABC|DEF|FSA

Input xml is:

<wd:Report_Data xmlns:wd="urn:com.workday.report/Test_Deductions">
    <wd:Report_Entry>
        <wd:Worker>
            <wd:SSN>123-45-6789</wd:SSN>
            <wd:First_Name>ABC</wd:First_Name>
            <wd:Last_Name>DEF</wd:Last_Name>
            <wd:Deduction_Effective_Date>20230101</wd:Deduction_Effective_Date>
            <wd:CF_HE_FSA_Plan_Year_Date>2023-01-01-08:00</wd:CF_HE_FSA_Plan_Year_Date>
        </wd:Worker>
        <wd:DepositDate>2023-03-15-07:00</wd:DepositDate>
        <wd:Result_Lines>
            <wd:Amount>51.88</wd:Amount>
            <wd:ContributionType wd:Descriptor="FSA">
                <wd:ID wd:type="WID">ed9b8c781ae64a03b14e36702640391e</wd:ID>
                <wd:ID wd:type="Deduction_Code">FSAH</wd:ID>
            </wd:ContributionType>
        </wd:Result_Lines>
        <wd:Result_Lines>
            <wd:Amount>51.88</wd:Amount>
            <wd:ContributionType wd:Descriptor="FSA">
                <wd:ID wd:type="WID">ed9b8c781ae64a03b14e36702640391e</wd:ID>
                <wd:ID wd:type="Deduction_Code">FSAH</wd:ID>
            </wd:ContributionType>
        </wd:Result_Lines>
    </wd:Report_Entry>
</wd:Report_Data>

I tried with the below xslt but need to sum the amount by contribution type:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"
    xmlns:wd="urn:com.workday.report/Test_Deductions"
    exclude-result-prefixes="xsl" version="2.0">

    <xsl:output method="text"/>
    <!--  Define linefeed & delimiter variables  -->
    <xsl:variable name="linefeed" select="'&#xD;&#xA;'"/>
    <xsl:variable name="delimiter" select="'|'"/>
    <xsl:template match="/wd:Report_Data/wd:Report_Entry">
        <xsl:for-each select="wd:Result_Lines">
        <xsl:value-of select="'D'"/>
        <xsl:value-of select="$delimiter"/>
        <xsl:value-of select="../wd:Worker/wd:SSN"/>
        <xsl:value-of select="$delimiter"/>    
            <xsl:value-of select="substring(replace(../wd:DepositDate,'-',''),1,8)"/>
        <xsl:value-of select="$delimiter"/>
        <xsl:value-of select="substring(../wd:Worker/wd:CF_HE_FSA_Plan_Year_Date,1,4)"/>
        <xsl:value-of select="$delimiter"/>
        <xsl:value-of select="'EE'"/>
        <xsl:value-of select="$delimiter"/>
            <xsl:value-of select="format-number(wd:Amount,'#.00')"/>
        <xsl:value-of select="$delimiter"/>
        <xsl:value-of select="../wd:Worker/wd:First_Name"/>
        <xsl:value-of select="$delimiter"/>
        <xsl:value-of select="../wd:Worker/wd:Last_Name"/>
        <xsl:value-of select="$delimiter"/>
        <xsl:choose>
            <xsl:when test="wd:ContributionType/@wd:Descriptor= 'FSA'">
                <xsl:value-of select="'FSA'"/>
            </xsl:when>
            <xsl:when test="wd:ContributionType/@wd:Descriptor = 'Dependent Care FSA'">
                <xsl:value-of select="'DCFSA'"/>
            </xsl:when>
            <xsl:when test="wd:ContributionType/@wd:Descriptor = 'Limited Health Care FSA'">
                <xsl:value-of select="'LPFSA'"/>
            </xsl:when>
        </xsl:choose>
        <xsl:value-of select="$linefeed"/>
        </xsl:for-each>
     </xsl:template>
</xsl:stylesheet>
5
  • Your question is tagged xslt-1.0. Your stylesheet says version="2.0". Grouping methods are very different for the two versions (and your stylesheet makes no attempt to use any one of them). Which version does your processor support? Commented Apr 2, 2023 at 16:30
  • @michael.hor257k version="2.0" Commented Apr 2, 2023 at 16:38
  • Well, then use xsl:for-each-group as explained here and in numerous examples on this site. Commented Apr 2, 2023 at 16:47
  • @michael.hor257k I am able to figure it out. Not need any help. Commented Apr 2, 2023 at 19:29
  • Good. Then you can delete the question. Commented Apr 2, 2023 at 19:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.