|
[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSL Running 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() >
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()
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|
|||||||||

Cart








