[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] xsl:sort by a sum()?
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
|
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
|