I am new to xsl transformations and I have a question.
I am looping through an xml like this:
<PO>
<Items>
<Item>
<Price>2</Price>
<Quantity>5</Quantity>
</Item>
<Item>
<Price>3</Price>
<Quantity>2</Quantity>
</Item>
</Items>
<QuantityTotal></QuantityTotal>
</PO>
Now I want to insert a value in the QuantityTotal node:
The value is the sum of price*quantity of all items, in this case (2*5)+(3*2) = 16
How can I do this, I tried it with a loop and variables, but variables are immutable so I don’t know how I can achieve this.
Thx for your help
Here is an XSLT solution — no extension functions required:
when this transformation is applied on the provided XML document:
the wanted result is produced: