i'm new xslt, , i'm attempting summarize amounts each worker same ssn , account_type. i'd group ssn , account_type summarize amount based on grouping.
xml:
<?xml version='1.0' encoding='utf-8'?> <wd:report_data xmlns:wd="urn:com.test"> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>475-84-3556</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>judith</wd:firstname> <wd:lastname>richardson</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>100.00</wd:amount> <wd:account_type>hcra</wd:account_type> </wd:report_entry> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>475-84-3556</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>judith</wd:firstname> <wd:lastname>richardson</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>75.00</wd:amount> <wd:account_type>hcra</wd:account_type> </wd:report_entry> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>475-84-3556</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>judith</wd:firstname> <wd:lastname>richardson</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>25.00</wd:amount> <wd:account_type>hcra</wd:account_type> </wd:report_entry> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>475-84-3556</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>judith</wd:firstname> <wd:lastname>richardson</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>50.00</wd:amount> <wd:account_type>lhcra</wd:account_type> </wd:report_entry> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>001-60-4288</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>gail</wd:firstname> <wd:lastname>sweatt</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>76.92</wd:amount> <wd:account_type>hcra</wd:account_type> </wd:report_entry> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>001-60-4288</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>gail</wd:firstname> <wd:lastname>sweatt</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>26.92</wd:amount> <wd:account_type>hcra</wd:account_type> </wd:report_entry> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>021-58-1885</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>robin</wd:firstname> <wd:lastname>bixby hyland</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>15.38</wd:amount> <wd:account_type>hcra</wd:account_type> </wd:report_entry> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>034-74-5241</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>meaghan</wd:firstname> <wd:lastname>mullen</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>38.46</wd:amount> <wd:account_type>hcra</wd:account_type> </wd:report_entry> </wd:report_data>
xslt:
<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.test" exclude-result-prefixes="xs" > <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="report_entry"> <report_entry> <xsl:for-each-group select="report_entry" group-by= "concat(wd:worker/wd:ssn, '+', wd:account_type)"> <worker> <xsl:copy-of select= "current-group()[1]/*[starts-with(name(),'key')]"/> <amount> <xsl:value-of select="sum(current-group()/wd:amount)"/> </amount> </worker> </xsl:for-each-group> </report_entry> </xsl:template> </xsl:stylesheet>
desired output:
<wd:report_data xmlns:wd="urn:com.test"> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>475-84-3556</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>judith</wd:firstname> <wd:lastname>richardson</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>200.00</wd:amount> <wd:account_type>hcra</wd:account_type> </wd:report_entry> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>475-84-3556</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>judith</wd:firstname> <wd:lastname>richardson</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>50.00</wd:amount> <wd:account_type>lhcra</wd:account_type> </wd:report_entry> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>001-60-4288</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>gail</wd:firstname> <wd:lastname>sweatt</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>103.84</wd:amount> <wd:account_type>hcra</wd:account_type> </wd:report_entry> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>021-58-1885</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>robin</wd:firstname> <wd:lastname>bixby hyland</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>15.38</wd:amount> <wd:account_type>hcra</wd:account_type> </wd:report_entry> <wd:report_entry> <wd:constant_d>d</wd:constant_d> <wd:worker> <wd:ssn>034-74-5241</wd:ssn> <wd:constant_ee>ee</wd:constant_ee> <wd:firstname>meaghan</wd:firstname> <wd:lastname>mullen</wd:lastname> </wd:worker> <wd:deductioneffectivedate>20170216</wd:deductioneffectivedate> <wd:amount>38.46</wd:amount> <wd:account_type>hcra</wd:account_type> </wd:report_entry> </wd:report_data>
Comments
Post a Comment