[Home] [By Thread] [By Date] [Recent Entries]


On Thu, Oct 21, 2004 at 01:42:48PM -0700, Ryan Ness wrote:
> Here's my XML snip:
> 

<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;
        8]/@weight)"/>

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="http://www.w3.org/1999/XSL/Transform" 
                    version="1.0">
        <xsl:output method="text"/>

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

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

Take care,

    John L. Clark

PGP signature


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member