Subject: Re: XSL and infinite loops
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 26 Aug 2004 18:07:28 +0100
|
> Thanks! I'm having trouble picturing a scenario in which for-each --
> by itself -- could cause an infinite loop under XSLT 1.0/XPath
> 1.0. Did you have a specific case in mind?
>
Not really, in fact for some definitions of "by itself" then it provably
doesn't loop as all node sets are finite and it just iterates over that
finite set.
I think what I had in mind is that it can be used to avoid certain
simple minded restrictions that you may put on apply-templates to avoud
looping.
apply-templates will only directly cause looping if it is used with a
reverse axis (including self:: axis)
apply-templates select="."
so if you are trying to avoid DOS attacks you could try to restrict the
select attribute so it only uses Xpaths that select descendent children
but then a for-each with select="/" would get you back up the tree with a
potential for looping again.
in a stylesheet that just has:
<xsl:stylesheet...>
<xsl:template match="*">
<xsl:for-each select="/">
<xsl:apply-templates/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
you will loop but whether you say it is the apply-templates or the
for-each that causes the looping is a matter of taste, if you take
either of them out it doesn't loop any more.
David
________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
|