Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2009, 12:38 PM
Authorized User
 
Join Date: Aug 2009
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
Default add a value in each iteration

the XML (part)
--------------------
<ruler>
<point rel="0"/>
<point rel="100"/>
<point rel="45"/>
......
</ruler>
--------------------
the XSLT (part)
--------------------
<xsl:for-each select="point">
<xsl:value-of select="????????"/><br/>
</xsl:for-each>
--------------------
How can I write the XSLT above to get these results?
Basically I want to get absolute positions from relative positions.
results
--------------------
0
100
145
......
--------------------
 
Old August 29th, 2009, 12:46 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You could use

Code:
select="sum(@rel | preceding-sibling::point/@ref)"
but that's not going to perform well if the number of points is large.

A better solution is to use recursion:

Code:
<xsl:template match="ruler">
  <xsl:apply-templates select="point[1]">
     <xsl:with-param name="total" select="0"/>
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="point">
  <xsl:param name="total"/>
  <xsl:value-of select="$total + @rel"/><br/>
  <xsl:apply-templates select="following-sibling::point[1]">
     <xsl:with-param name="total" select="$total + @rel"/>
  </xsl:apply-templates>
</xsl:template>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 29th, 2009, 02:19 PM
Authorized User
 
Join Date: Aug 2009
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
Default

you are the coolest man on planet...





Similar Threads
Thread Thread Starter Forum Replies Last Post
iteration bostek Excel VBA 5 August 30th, 2006 01:23 AM
iteration movenext weazy Excel VBA 0 June 9th, 2006 05:56 PM
Picture iteration bahachin Excel VBA 3 September 28th, 2005 12:44 PM
Iteration in struts sridevi Servlets 2 July 1st, 2005 07:01 AM
Iteration through a dropdown. tryxxter PHP How-To 1 February 9th, 2005 11:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.