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

Re: XSL Running total help


total help
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


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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.