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

RE: summing 5 largest nodes

Subject: RE: summing 5 largest nodes
From: "Marrow" <marrow@xxxxxxxxxxxxxx>
Date: Fri, 27 Dec 2002 22:22:07 -0000
xsl top 5
Hi Todd,

You could try something like...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <xsl:variable name="top5-ids">
    <xsl:text>|</xsl:text>
    <xsl:for-each select="items/item/value">
      <xsl:sort select="." data-type="number" order="descending"/>
      <xsl:if test="position() &lt; 6">
        <xsl:value-of select="generate-id()"/>
        <xsl:text>|</xsl:text>
      </xsl:if>
    </xsl:for-each>
  </xsl:variable>
  
  <xsl:text>Sum of top 5 is: </xsl:text>
  <xsl:value-of
select="sum(items/item/value[contains($top5-ids,concat('|',generate-id()
,'|'))])"/>
  <xsl:text>&#10;Sum of rest is: </xsl:text>
  <xsl:value-of
select="sum(items/item/value[not(contains($top5-ids,concat('|',generate-
id(),'|')))])"/>
</xsl:template>
</xsl:stylesheet>



Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator


-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Todd Binder
Sent: 27 December 2002 21:18
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  summing 5 largest nodes

I am attempting to sum the certain groupings of nodes, based on the max
and
min values contained in the nodes.

For example, if there are 20 node elements, sum the 5 largest and the
other
15 values (ending with 2 values)

using POSITION(), I can determine what the 5 largest (or 15 other values
are), but I can't seem to determine how to sum these values.

my XML looks like

<items>
<item>
    <value>6</value>
</item>
<item>
    <value>3</value>
</item>
<item>
    <value>7</value>
</item>
</items>

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





 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.