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

Trying to undestand why template works

Subject: Trying to undestand why template works
From: yguaba@xxxxxxxxxxxx
Date: Thu, 23 Feb 2006 15:08:43 -0300
template works
Hello,

After some digging and experimenting, I finally got a stylesheet to 
do what I wanted. Among other things, it uses the template below. 
Problem is, I don't really understand WHY this template works, and 
would very much like to.

Here's the template:

<xsl:template name="sum-value">
	<xsl:param name="node"/>
	<xsl:param name="hourVal"/>
	<xsl:choose>
		<xsl:when test="$node">
			<xsl:variable name="recursive_result">
				<xsl:call-template name="sum-value">
					<xsl:with-param name="node" select="$node[position() &gt; 1]"/>
					<xsl:with-param name="hourVal" select="$hourVal"/>
				</xsl:call-template>
			</xsl:variable>
		<xsl:value-of select="$recursive_result + number($node[1]/@time * 
$hourVal)"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="0"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

I just don't understand how the select="$node[position() &gt; 1]" bit 
works. I assume that with each recursion this is selecting the next 
child of the input node (param "node"), but have no idea how or why. 

Doesn't "position() &gt; 1" evaluate to either 0 or 1? If so, where 
is the input node becoming the next child of the original input node 
(at the first level of the recursion)? Or, if my question doesn't 
make any sense, how the heck is the recursion moving on to the next 
child of the input node in order to add them all up?

Thanks in advance to anyone who can shed any light on this issue.

Erik

		
_______________________________________________________
Yahoo! Acesso Gratis - Internet rapida e gratis. Instale o discador agora!
http://br.acesso.yahoo.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

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