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

RE: How to sum() with multiplaction

Subject: RE: How to sum() with multiplaction
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 11 Dec 2002 09:12:44 -0000
multiplaction
> 
> <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.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 


 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.