Hi,
> I would have thought the following templates should produce the same
> result, one uses choose/when, one uses if, however the value-of at the
> end of template t2 seems to keep track of the whole string...
> if I step
> through the code the debugger stays on that line the number
> of times the
> template has been recursively called - which is a bit strange...
>
> Using this data:
>
> <node>1 | 2 | 3 | 4 | 5</node>
>
> I would expect this result:
>
> 1 2 3 4 5
>
> which is what t1 gives me, whereas t2 produces:
>
> 1 2 3 4 5 4 | 5 3 | 4 | 5 2 | 3 | 4 | 51 | 2 | 3 | 4 | 5
>
> why is this? saxon and msxml4 both produce the same so Im
> guessing its a
> gap in my understanding rather than a processor issue...
>
> <xsl:template name="t1">
> <xsl:param name="string" select="''"/>
> <xsl:choose>
> <xsl:when test="contains($string,'|')">
> <xsl:value-of select="substring-before($string,'|')"/>
> <xsl:call-template name="t1">
> <xsl:with-param name="string"
> select="substring-after($string,'|')"/>
> </xsl:call-template>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="$string"/>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
>
> <xsl:template name="t2">
> <xsl:param name="string" select="''"/>
> <xsl:if test="contains($string,'|')">
> <xsl:value-of select="substring-before($string,'|')"/>
> <xsl:call-template name="t2">
> <xsl:with-param name="string"
> select="substring-after($string,'|')"/>
> </xsl:call-template>
> </xsl:if>
> <xsl:value-of select="$string"/>
Because here you're outputting the value of $string every time the template is called.
Santtu
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|