Altova Mailing List Archives

Re: [xml-dev] XSL Running total help

From: "John L. Clark" <jlc6@--.----.--->
To: xml-dev@-----.---.---
Date: 10/21/2004 9:29:00 PM
On Thu, Oct 21, 2004 at 01:42:48PM -0700, Ryan Ness wrote:
> Here's my XML snip:


> What I need is to display the largest 8 weight values (in a text file)
> and then instead of continuing to display the remaining assetWeights,
> I want to add them up, and display the total...

It looks like you have the first 8 values, and just want help with the
total.  I did it with this line:

    <xsl:value-of select="sum(assetWeights[position() &gt;

Obviously, in the context of the <snip/> root.  You'd have to rewrite it
slightly to work in your for-each block, but I think you should ditch
the for-each and work directly from templates called from the parent so
as to (easily) avoid the repetition across every child with position
greater than 8.

Here's my full test stylesheet:

    <xsl:stylesheet xmlns:xsl="" 
        <xsl:output method="text"/>

        <xsl:template match="/snip">
            <xsl:value-of select="sum(assetWeights[position() 
                &gt; 8]/@weight)"/>

Which returns 0.727.  Also obviously, I'm temporarily ignoring the
sorting requirement, but your code looks like it already takes care of

Take care,

    John L. Clark

PGP signature


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.