Reputation: 7290
I want to use XSLT to calculate the summation value of amount
the input is:
<FileHeader>
<Item amount="500" />
<Item amount="600" />
<Item amount="400" />
<Item amount="700" />
<Item amount="100" />
<Item amount="900" />
<Item amount="1000" />
<Item amount="200" />
<Item amount="700" />
</FileHeader>
The output should be:
<Result>
<FileSummary TotalAmount="5100">
</Result>
Thanks,
Upvotes: 2
Views: 1079
Reputation: 48098
Try this :
<Result>
<FileSummary>
<xsl:attribute name="TotalAmount">
<xsl:value-of select="sum(//FileHeader/Item/@amount)" />
</xsl:attribute>
</FileSummary>
</Result>
Upvotes: 1
Reputation: 11612
<Result>
<FileSummary TotalAmount="{sum(/FileHeader/Item/@amount)}" />
</Result>
Tested. Fixed typo. This should work.
Upvotes: 4
Reputation: 2759
Here's an example of how this can be done:
XSLT: Sum of products from multiple nodes
Upvotes: 1