I'm trying to sum the qty field in my xml using xslt 2.0 and it's outputting the qty of one of my pieces of equipment with multiple entries without summing by the equipment group. Any ideas about how this can be fixed?
This is the XSLT I'm using:
<xsl:for-each-group select="//node()" group-by="*[local-name()='lin_id']/text()">
<Results>
<xsl:element name="LIN_ID"><xsl:value-of select="*[local-name()='lin_id']"/></xsl:element>
<xsl:element name="Count"><xsl:value-of select="sum(current-group()/*[local-name()='qty'])"/></xsl:element>
</Results>
</xsl:for-each-group>
Here's the source XML file:
<Equipment>
<lin_id>C18312</lin_id>
<qty>5</qty>
</Equipment>
<Equipment>
<lin_id>C18345</lin_id>
<qty>22</qty>
</Equipment>
<Equipment>
<lin_id>C18378</lin_id>
<qty>43</qty>
</Equipment>
<Equipment>
<lin_id>C18378</lin_id>
<qty>208</qty>
</Equipment>
And here's what the output is currently:
<Results>
<LIN_ID>C18312</LIN_Name>
<Count>5</Count>
</Results>
<Results>
<LIN_ID>C18345</LIN_Name>
<Count>22</Count>
</Results>
<Results>
<LIN_ID>C18378</LIN_Name>
<Count>43</Count>
</Results>
So you can see that it's doing the grouping but for LIN_ID C18378 it should be summing the qty of the 2 entries and outputting a count of 251 but it instead it's just displaying one of the values.