Subject: RE: [xsl] summing 5 largest nodes From: "Marrow" <marrow@xxxxxxxxxxxxxx> Date: Fri, 27 Dec 2002 22:22:07 -0000 |
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() < 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> 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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] summing 5 largest nodes, Todd Binder | Thread | [xsl] a number of values, Dionisio Ruiz de Zar |
Re: [xsl] How to select a namespace, Dimitre Novatchev | Date | Re: [xsl] Adding namespaces to outp, Kevin Jones |
Month |