[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: result = node1 * node2 and then get total of all t

Subject: RE: 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
RE:  result = node1 * node2 and then get total of all t
> 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


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.