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

Re: apply template within call template

Subject: Re: apply template within call template
From: Joerg Pietschmann <joerg.pietschmann@xxxxxx>
Date: Fri, 11 Jan 2002 10:06:39 +0100
xsl call template apply 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


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