foreach - XSLT Group by using 2 different elements -


i'm new xslt. i'm trying group 2 different elements. first worker, pay code. please see amounts sum because of group paycode. below before sample xsl, sample after xsl output.

before:

<?xml version='1.0' encoding='utf-8'?> <file   xmlns:is="java:com.workday.esb.intsys.xpath.parsedintegrationsystemfunctions"     xmlns:tv="java:com.workday.esb.intsys.typedvalue">     <worker>         <detail>             <employeeid>0008765</employeeid>             <firstname>robert</firstname>             <paycode>rsvest</paycode>             <amount>5572.800000</amount>         </detail>         <detail>             <employeeid>0008765</employeeid>             <firstname>robert</firstname>             <paycode>fica</paycode>             <amount>40.000000</amount>         </detail>     </worker>     <worker>         <detail>             <employeeid>0008765</employeeid>             <firstname>robert</firstname>             <paycode>rsvest</paycode>             <amount>13545.000000</amount>         </detail>     </worker>     <worker>         <detail>             <employeeid>00012345</employeeid>             <firstname>russell</firstname>             <paycode>rsvest</paycode>             <amount>84811.050000</amount>         </detail>     </worker> </file> 

what output, grouping first worker, group pay code. amounts sum because of grouping:

<?xml version='1.0' encoding='utf-8'?> <file xmlns:xs="http://www.w3.org/2001/xmlschema"     xmlns:tv="java:com.workday.esb.intsys.typedvalue">     <worker>         <detail>             <employeeid>0008765</employeeid>             <firstname>robert</firstname>             <paycode>rsvest</paycode>             <amount>19117.800000</amount>         </detail>         <detail>             <employeeid>0008765</employeeid>             <firstname>robert</firstname>             <paycode>fica</paycode>             <amount>40.000000</amount>          </detail>     </worker>     <worker>         <detail>             <employeeid>00012345</employeeid>             <firstname>russell</firstname>             <paycode>rsvest</paycode>             <amount>84811.050000</amount>         </detail>     </worker> </file> 

below xsl doesn't work:

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" exclude-result-prefixes="xsl wd xsd env"     xmlns:wd="urn:com.workday/bsvc"      xmlns:xsd="http://www.w3.org/2001/xmlschema"     xmlns:xsl="http://www.w3.org/1999/xsl/transform"      xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"     xmlns:this="urn:this-stylesheet">      <xsl:output indent="yes" method="xml"/>        <xsl:template match="/">               <file>             <worker>                 <xsl:for-each-group select="file" group-by="worker">                     <detail>                                       <employeeid><xsl:value-of select="worker/current-group()/employeeid"></xsl:value-of></employeeid>                         <firstname><xsl:value-of select="//current-group()//firstname"></xsl:value-of></firstname>                         <paycode><xsl:value-of select="paycode"></xsl:value-of></paycode>                         <amount><xsl:value-of select="format-number(sum(current-group()/number(translate(amount,',',''))),'######.00')"></xsl:value-of></amount>                     </detail>                   </xsl:for-each-group>             </worker>         </file>     </xsl:template> </xsl:stylesheet> 

can please put sl transform above desired output?
i've been working on hours , waving white flag lol.

thank you!

if want have group each employeeid, , within each such group subgroup each paycode, need nest two xsl:for-each-group instructions. , nodes need grouping detail elements, not root file element of there one.

xslt 2.0

<xsl:stylesheet version="2.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>  <xsl:template match="/file">           <xsl:copy>         <xsl:for-each-group select="worker/detail" group-by="employeeid">             <worker>                 <xsl:for-each-group select="current-group()" group-by="paycode">                     <detail>                                       <xsl:copy-of select="employeeid | firstname | paycode"/>                         <amount>                             <xsl:value-of select="format-number(sum(current-group()/amount),'#.000000')"/>                         </amount>                     </detail>                   </xsl:for-each-group>             </worker>         </xsl:for-each-group>     </xsl:copy> </xsl:template>  </xsl:stylesheet> 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -