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

RE: Re[2]: how calculate sum(x*y)

Subject: RE: Re[2]: how calculate sum(x*y)
From: Jarno.Elovirta@xxxxxxxxx
Date: Mon, 7 Oct 2002 12:42:05 +0300
calculate sum
Hi,

> >> how calculate sum(x*y) ??
> >> 
> >> IF i try use sum() it say that need only node-list as argument....
> >> 
> >> I have xml
> >> <root>
> >>   <data>
> >>    <x>2</x>
> >>    <y>3</y>
> >>   </data>
> >>   <data>
> >>    <x>5</x>
> >>    <y>6</y>
> >>   </data>
> >>   .....
> >> <root>
> 
> JEnc> Write a recursive template, that goes through all the 
> data elements, summing the multiplication result to previous 
> result sum, i.e.
> 
> JEnc> template name=sum
> JEnc>   param name=node-set
> JEnc>   param name=sum
> 
> JEnc>   if count($node-set') = 0
> JEnc>   then
> JEnc>     value-of select=$sum
> JEnc>   else
> JEnc>     call-template name=sum
> JEnc>       with-param name=node-set 
> select=$node-set[not(position() = 1)]
> JEnc>       with-param name=sum select=$sum + $node-set[1]/x 
> * $node-set[1]/y
> 
> JEnc> Dimitri probably has some suitable function for the 
> job, see [http://fxsl.sourceforge.net/].
> 
> 
> I try now use function "nodeset" from xalan namespace to 
> build new nodeset
> with result of calculation x*y and then apply function sum for this
> tree.
> can you compare this two variants, what variant more likely to use ?

Well, exslt:node-set is pretty portable these days (latest Xalan implements it), but I don't see any particular reason why you couldn't just use the XSLT 1.0 way of doing it. If you need the intermediate multiplication result set somewhere else, then the RTF->node-set solution will probably be better, but if you just need the multiplication sum, go with the recursive template.

Cheers,

Jarno - Cenobita: Destino Final (Global mix)

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.