|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: sort and sum
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
|
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
|

Cart








