RE: [xsl] Complex recursion in XSLT 1.0

Subject: RE: [xsl] Complex recursion in XSLT 1.0
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 18 Feb 2008 13:36:26 -0000
> Could you elucidate a little on the concept of a 'stack'. I 
> can only dream of such a thing. What mechanism would you use? 
> and... does that not sound like we need to have a list of all 
> entries first - is that another infinite loop?

OK. You're processing A, and it contains

<topic ref="X"/>
<topic ref="Y"/>

then when you make the call to process X, you pass it a $stack containing
<topic ref="Y"/>.

In X you find

<topic ref="P"/>
<topic ref="Q"/>

so you make a recursive call to process P, passing it a $stack containing
the previous $stack plus <topic ref="Q"/>

When you've finished processing P, you select the last thing on the stack
(which is Q), you process that, passing a stack from which Q has been
removed. Then when you finish processing Q, you select the last thing on the
stack (which is Y) and process that, passing a stack which is now empty.
When you finish processing Y you are done.
> 
> All these Catch 22's are piling up and I'm starting to think 
> that this is fundamentally impossible in XSLT 1.0 because we 
> are not party to essential information about what went 
> before. 

It's absolutely not fundamentally impossible because XSLT is
Turing-complete. I agree it might be a bit mind-bending when you're not used
to this style of coding.

One reason I published the knight's tour stylesheet in my XSLT Programmer's
Reference was to convince people that problems like this could be solved.

Michael Kay
http://www.saxonica.com/

Current Thread