OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] XSL Running total help

[ Lists Home | Date Index | Thread Index ]

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="http://www.w3.org/1999/XSL/Transform"; 
        <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


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS