[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: sort and sum

Subject: Re: sort and sum
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 30 Nov 2001 17:24:06 +0000
sort 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() &lt;= 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
  • sort and sum
    • Maneshi Tuli - Fri, 30 Nov 2001 12:01:21 -0500 (EST)
      • Jeni Tennison - Fri, 30 Nov 2001 12:23:07 -0500 (EST) <=

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.