Question

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,

Was it helpful?

Solution

<Result>
    <FileSummary TotalAmount="{sum(/FileHeader/Item/@amount)}" />
</Result>

Tested. Fixed typo. This should work.

OTHER TIPS

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top