Search code examples
xmlxsltxslt-1.0xsl-fo

XSLT - Sum of node values using For each


I have the following XML

    <T1>
    <amount>100</amount>
    </T1>

    <T1>
    <amount>100</amount>
    <T1>
...

Now I'm supposed to sum all the amount node values to a single variable or element

I'm very new to this domain

kindly suggest the possible XSLT1.0 code please

i'm expecting the output as <total>200</total>


Solution

  • With sum() and catch all amount nodes

    <xsl:value-of select="sum(//amount[. != ''])"/>