xsl to produce summation value for each attribute
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,
<Result>
<FileSummary TotalAmount="{sum(/FileHeader/Item/@amount)}" />
</Result>
Tested. Fixed typo. This should work.
Here's an example of how this can be done:
XSLT: Sum of products from multiple nodes
Try this :
<Result>
<FileSummary>
<xsl:attribute name="TotalAmount">
<xsl:value-of select="sum(//FileHeader/Item/@amount)" />
</xsl:attribute>
</FileSummary>
</Result>
精彩评论