I have a few items like this one:
-
172
42
In addition to the correct answer by Kirill:
I. XPath 2.0 (XSLT 2.0) solution:
Use this single XPath 2.0 expression from any language hosting XPath 2.0:
sum(/*/*/(quantity*unit-price))
Here is a complete example using XSLT 2.0 as the host of XPath 2.0:
when applied on the following XML document:
-
1
2
7
-
10
20
7
-
100
200
7
the wanted, correct result is produced:
20202
II. XSLT 1.0 solution using the transform-and-sum template/function of FXSL 1.x
when this transformation is applied on the same XML document (above), the same correct result is produced:
20202
Do note: Using FXSL one doesn't need to implement explicit recursion "for the Nth time", the solution is compact and potential errors writing the recursion are eliminated altogether.
As a whole the total development time, readability and flexibility are dramatically improved.