This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: possible to mimic while-like behavior?


> e.g., speaking in a Perl-esque way, I want
>   while ($foo != "bar") {
>     blah
>   }
> 
> Is there any way to simulate, hack, or otherwise achieve this?

Pure XSLT is side-effect free, so the value of $foo cannot change within the
loop, therefore this construct would be of limited value. Saxon does provide
the extension element saxon:while, as has been mentioned, but it is only
useful in conjunction with extension functions or extension elements (such
as saxon:assign) that have side-effects. An example:

<div xmlns:tok="java.util.StringTokenizer">
<xsl:variable name="tokens" select="tok:StringTokenizer.new('a bag of
worms')"/>
<saxon:while test="tok:hasMoreTokens()">
   <word><xsl:value-of select="tok:nextToken($tokens)"></word>
</saxon:while>
</div>

Here nextToken() is an extension function that has a side-effect, namely
moving the current position.

Unlike xsl:for-each, saxon:while is strictly sequential. As David Carlisle
mentioned, you can't predict the order of execution of xsl:for-each. I don't
know of an XSLT processor that executes xsl:for-each non-sequentially, but
it's certainly permitted: hence the absence of an <xsl:break> instruction.

Mike Kay



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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]