Re: [xsl] Trying to undestand why template works

Subject: Re: [xsl] Trying to undestand why template works
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 23 Feb 2006 13:02:29 -0500
Hi Eric,

At 01:08 PM 2/23/2006, you wrote:
Doesn't "position() &gt; 1" evaluate to either 0 or 1?

Not quite: it's either "true()" or "false()" (Boolean values). In your case, since it's used as a predicate, it has the effect of selecting all the members of the set $node except the first one.


Presumably, when your template is called, a set of nodes is passed in as the parameter $node; the recursion trims this set down one node at a time.

Cheers,
Wendell

<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.



====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

Current Thread