Trying to undestand why 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() > 1]"/> <xsl:with-param name="hourVal" select="$hourVal"/> </xsl:call-template> </xsl:variable> <xsl:value-of select="$recursive_result + number($node/@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() > 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() > 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
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