Subject: Re: [xsl] sort and sum From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 30 Nov 2001 17:24:06 +0000 |
Hi Maneshi, > i want to get the sum for elements after 10 top elements The easiest way to do this is with a two-step transformation. First sort the rows into the order that they should be in: <xsl:variable name="sorted-rows-rtf"> <xsl:for-each select="row"> <xsl:sort select="col" data-type="number" order="descending" /> <xsl:copy-of select="." /> </xsl:for-each> </xsl:variable> Then convert that result tree fragment into a node set using a node-set() extension function (which one you use depends on what processor you're using): <xsl:variable name="sorted-rows" select="exsl:node-set($sorted-rows-rtf)/row" /> And then sum the top ten with the sum() function: <xsl:value-of select="sum($sorted-rows[position() <= 10]/col)" /> If you don't want to use an extension function, then the 'pure' way is either using two stylesheets or a recursive template that steps through the rows one by one, keeping track of their sum as you go. Let us know if you need help putting that together. I think that Dimitre also has a generic template for doing sorting and summing... Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] sort and sum, Maneshi Tuli | Thread | [xsl] Newbie - simple selection pro, JWALLIS |
RE: [xsl] Default template match, Michael Kay | Date | [xsl] Newbie - simple selection pro, JWALLIS |
Month |