[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] result = node1 * node2 and then get total of all the result from whole document at the end


Subject: RE: [xsl] result = node1 * node2 and then get total of all the result from whole document at the end
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 2 Jan 2002 12:04:17 -0000

> Hello everybody,I am new to this forum and new to xslt as
> well.I have been
> stuck with this problem for several days.
> what I want to do is,to go through an xml file multiply rate
> with value at
> each level and print the product.

It's a familiar problem...

In XPath 2.0 the answer is

   sum(for $r in //rate return $r/@value * $r/@quantity)

That will work in Saxon 7.0; but with any other processor you'll need at
XSLT 1.0 solution. Which basically means writing a recursive named template.
This should be called with a parameter that's a set of nodes; it should
compute @value*@quantity for the first node, and add the result to the total
for the remaining nodes, obtained by means of a recursive call.

An alternative solution is to construct a temporary tree (result tree
fragment) containing the computed values of @value*@quantity, and then use
the sum() function over the nodes in this RTF, which you will need to
process using the xx:node-set() extension function provided by your
favourite XSLT processor.

Mike Kay

>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords