|
Subject: RE: [xsl] How to sum() with multiplaction From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Wed, 11 Dec 2002 09:12:44 -0000 |
>
> <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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] How to sum() with multiplacti, Joshua J Sm | Thread | RE: [xsl] How to sum() with multipl, Joshua J Sm |
| RE: [xsl] Severe limitation of the , Michael Kay | Date | RE: [xsl] superfluous namespace dec, Michael Kay |
| Month |