|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: apply template within call template
"cutlass" <cutlass@xxxxxxxxxxx> wrote:
[rearranged]
> sometimes people confuse recursion with circular references, the above is a
> circular reference.
Jim, i thought you knew better! The code snippet
<xsl:template name="test">
<xsl:call-template name="test"/>
</xsl:template>
is perfectly legal, and it's recursion. Of course, it would
run forever provided infinite ressources. In order to make it
useful, a method for termination should be provided:
for example a counter:
<xsl:template name="test">
<xsl:param name="counter"/>
<xsl:if test="$counter > 0">
<xsl:call-template name="test">
<xsl:with-param name="counter" select="$counter - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
or processing a node set:
<xsl:template name="test">
<xsl:param name="nodes"/>
<xsl:if test="count($nodes) > 1">
<xsl:call-template name="test">
<xsl:with-param name="nodes" select="$nodes[position() > 1]"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
> for example x=x+1 could be thought of as recursive, but in actuality it goes
> on 'forever'.... which means that the function never bottoms out...
> recursion always bottoms out ( c'mon u GEB readers.... ).
Wrong analogy. BTW i've never met anyone who thought of
x=x+1 as recursive (it's a perfectly valid non-recursive
expression in most programming languages and something
quite different in mathematics).
As for circular references, i think in XSLT they can be produced
only with global variables
<xsl:variable name="foo">
<xsl:copy-of select="$bar"/>
</xsl:variable>
<xsl:variable name="bar">
<xsl:copy-of select="$foo"/>
</xsl:variable>
It is of course a fatal error to do this.
HTH
J.Pietschmann
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|

Cart








