I tried the muenchian method, but I still can't sum the quantity nodes...
My XSLT is now like this:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:key name="unike-prod-ids" match="Item" use="ProductId" />
<xsl:template match="/">
<TransactionId>
<xsl:value-of select="ContainerComplete/TransactionId"/>
</TransactionId>
<Container>
<Ssccid>
<xsl:value-of select="ContainerComplete/Container/Ssccid"/>
</Ssccid>
<xsl:apply-templates select = "/ContainerComplete/Container/Items"/>
</Container>
</xsl:template>
<xsl:template match="Items">
<Items>
<!--Only find the 'first' instance of each Item-->
<xsl:for-each select="Item[count(. | key('unike-prod-ids', ProductId)[1]) = 1]">
<xsl:sort select="ProductId" />
<ProductId>
<xsl:value-of select="ProductId" />
</ProductId>
<Quantity>
<xsl:for-each select="key('unike-prod-ids', ProductId)">
<xsl:sort select="Quantity" />
<xsl:value-of select="Quantity" />
<xsl:text>, </xsl:text>
</xsl:for-each>
</Quantity>
</xsl:for-each>
</Items>
</xsl:template>
</xsl:stylesheet>
<!-- Resulting xml:
<TransactionId>123</TransactionId>
<Container>
<Ssccid>11776</Ssccid>
<ContainerVolume/>
<Items>
<ProductId>702</ProductId>
<Quantity>2.000, 40.000, 90.000, </Quantity>
<ProductId>703</ProductId>
<Quantity>1.000, 2.000, </Quantity>
<ProductId>704</ProductId>
<Quantity>13.000, </Quantity>
</Items>
</Container>
-->
I tried to change the for-each block where I now write the quantity to this:
Code:
<Quantity>
<xsl:for-each select="key('unike-prod-ids', ProductId)">
<xsl:value-of select="sum(Quantity)"/>
</xsl:for-each>
</Quantity>
But this did not give the correct sum. The result was like this:
<Item>
<ProductId>702</ProductId>
<Quantity>40902</Quantity>
<ProductId>703</ProductId>
<Quantity>21</Quantity>
<ProductId>704</ProductId>
<Quantity>13</Quantity>
</Item>
The correct sums should've been:
For ProductId 702: 132
For ProductId 703: 3
For ProductId 704: 13
So can anybody help with how to sum this up correctly??