[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] Re: RE: Find a set of nodes and depending on element values
Subject: [xsl] Re: RE: Find a set of nodes and depending on element values From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Mon, 4 Mar 2002 13:37:58 -0800 (PST) |
Michael Kay wrote: > > Now I want to find all <action> elements with the element > > <loadsize>1</loadsize> and then process the average time > > (<time>xxx</time>) > > for each set of action elements with the same time. > > You'll have to explain yourself more clearly. The average time of a > set of elements with the same time is the average of a set of numbers > that are allthe same. > > I suspect you're trying to do the equivalent of the classic "sum of > price times quantity for all items". Solutions include: > > (a) write a recursive named template > (b) (Saxon extension) saxon:sum(//item, saxon:expression("@price * > @qty")) > (c) (XSLT 2.0, Saxon 7.0) sum(for $i in //item return $i/@price * > $i/@qty) > > Michael Kay The easiest way to perform this, while not having to use extension functions (xxx:node-set() excluded) is to use a foldl/foldr function from the FXSL functional programming library. The article "The functional programming language XSLT" at the end of the section about list processing contains an example of finding the sum of products, where every product can consist of different number of terms. Using a functional programming library eliminates almost completely the need for vendor-supplied libraries of extension functions. Nor have we to wait for XPath 2.0 to come (even when it comes there would be very difficult/awkward tasks that have an elegant solution with a functional programming library). Cheers, Dimitre Novatchev. __________________________________________________ Do You Yahoo!? Yahoo! Sports - sign up for Fantasy Baseball http://sports.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Urgent!Loop_Condition, Jeff Kenton | Thread | [xsl] Program for XML Europe 2002 a, Mulberry Technologie |
Re: [xsl] Multiple attributes prese, Mike Ferrando | Date | [xsl] Program for XML Europe 2002 a, Mulberry Technologie |
Month |
Keywords