[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: How to sum() with 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|