RE: recursion and looping

Subject: RE: recursion and looping
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Thu, 23 Mar 2000 18:11:13 -0000
> Question: is the looping induced by the following stylesheet 
> casued by a failure to shift context node? If so how can one pass a param 
> value that cause a shift in context node? Or is this totally wrong-tree
barking?
> 
> <xsl:param name="nodeset" select="//w[@n=$listname]"/>
> <xsl:param name="nextset" select="//w[@n!=$listname]a"/>

The infinite looping is caused by the fact that on each call of the
template, you process one element, and then call the template to process all
the other elements. There will always be other elements, so this never
terminates. You need to process a diminishing set of elements on each call.
The usual way is to use.

> <xsl:param name="nodeset" select="(//w)[1]"/>
> <xsl:param name="nextset" select="(//w)[position() &gt; 1]a"/>

Incidentally, using //w repeatedly is probably inefficient: set a global
variable to //w before you start.

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread