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

xsl:sort by a sum()?

Subject: xsl:sort by a sum()?
From: "Juan Gril" <juangril@xxxxxxxxxxxxx>
Date: Thu, 11 Apr 2002 17:03:28 -0300
juan gril
Hello everybody. Here is a question from a non programmer: I'm trying to
sort elements by a sum operation. Here is an XML structurally similar to the
one I'm using:

<FruitBasket location="kitchen">
<Fruit name="Apples" amount="10"/>
<Fruit name="Oranges" amount="20"/>
</FruitBasket>
<FruitBasket location="bedroom">
<Fruit name="Apples" amount="8"/>
<Fruit name="Oranges" amount="7"/>
</FruitBasket>

And the following <xsl:for-each>:

<xsl:for-each select="//Fruit[@name and not(@name=preceding::Fruit/@name)]">
<xsl:variable name="currentFruit" select="@name"/>
<xsl:value-of select="$currentFruit"><xsl:text> : </xsl:text><xsl:value-of
select="sum(//Fruit[@name=$currentFruit]/@amount)"/><br/>
</xsl:for-each>

After processing with Saxon 6.5.1 I get this:
Apples: 18
Oranges: 27

Which is fine and dandy, but I've got 25 FruitBaskets with different amount
of fruits each, so I need to sort them by the sum of each Fruit among
FruitBaskets. Is there an Xpath expression that could achieve that? I had
tried many, and also searched in the list, but I couldn't find something
similar to my case.

Many thanks in advance for the tip.

Cheers,

Juan



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

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.