<node>
<subnode1>test</subnode1>
<subnode2>test</subnode2>
<Node2>
<test1>2</test1>
<test2>25</test1>
</Node2>
<Node2>
<test1>3</test1>
<test2>50</test1>
</Node2>
I want to get the sum of (in the test case)
2*25 and 3*50
So i want to get a result of 200
How do i do this?
This is a common requirement. Here are the common solutions:
(1) Use a recursive named template (you need to learn to use recursion
to do any advanced programming in XSLT).
(2) Create a temporary tree containing the values you want to sum as the
values of elements or attributes, then use the xx:node-set() extension
and the sum() function to total them.
(3) Use a vendor extension such as saxon:sum(Node2,
saxon:expression("test1 * test2"))
(4) Use a routine in Dimitre Novatchev's FXSL library
(5) Use the XPath 2.0 construct sum(for $n in Node2 return
$n/test1*$n/test2) (available in Saxon 7.x)
Michael Kay
Software AG
home: Michael(_dot_)H(_dot_)Kay(_at_)ntlworld(_dot_)com
work: Michael(_dot_)Kay(_at_)softwareag(_dot_)com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list