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

RE: Calculating cumulative values - another call for h

Subject: RE: Calculating cumulative values - another call for help
From: "Simon Shutter" <simon@xxxxxxxxxxx>
Date: Wed, 29 Aug 2007 11:03:03 -0700
RE:  Calculating cumulative values - another call for h
Andrew,

Thank you very much - I look forward to trying this out.

Simon 

-----Original Message-----
From: Andrew Welch [mailto:andrew.j.welch@xxxxxxxxx] 
Sent: August 29, 2007 9:03 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Calculating cumulative values - another call for help

Here's my attempt that uses a key and does it in one pass:

<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xs">

<xsl:key name="point-by-set-id-and-x" match="point"
  use="concat(parent::set/@id,'-',@x)"/>

<xsl:template match="@*|node()">
	<xsl:copy>
		<xsl:apply-templates select="@*|node()"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="point">
	<xsl:copy>
		<xsl:copy-of select="@*"/>
		<xsl:attribute name="y2">
    	<xsl:value-of select="sum(@y1|preceding-sibling::point[@x =
current()/@x]/@y1)"/>
  	</xsl:attribute>
  	<xsl:attribute name="y3">
   		<xsl:value-of select="sum((@y1, preceding-sibling::point[@x
=
current()/@x]/@y1)) + sum(for $x in 1 to xs:integer(parent::set/@id - 1)
return key('point-by-set-id-and-x',
  concat($x, '-', current()/@x))/@y1)"/>
  	</xsl:attribute>
	</xsl:copy>
</xsl:template>

</xsl:stylesheet>

It could be re-written in pure 1.0 if you replaced the "for $x in to
xs:integer(parent::set/@id - 1)" with a recursive named template... if you
could be bothered :)

cheers
andrew
--
http://andrewjwelch.com

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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
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-2007 All Rights Reserved.