XSLT - Is Tail Recursion possible here

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all,
I have a recursive template where I dont really know before hand how many levels deep the recursive method can go down. To eliminate the possibility of getting a stack overflow exception I would like to make use of tail recursion. Looking at my template
below, is it possible to apply tail recursion here?

<div style="color:black; background-color:white
<pre><span style="color:blue <<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 template <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ChildNodes<span style="color:black " <span style="color:blue >
<span style="color:blue <<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 param <span style="color:red name <span style="color:blue =<span style="color:black "<span style="color:blue level<span style="color:black "<span style="color:blue ><span style="color:blue </<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 param<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 param <span style="color:red name <span style="color:blue =<span style="color:black "<span style="color:blue number<span style="color:black "<span style="color:blue ><span style="color:blue </<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 param<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 param <span style="color:red name <span style="color:blue =<span style="color:black "<span style="color:blue Companies<span style="color:black "<span style="color:blue ><span style="color:blue </<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 param<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 for-each <span style="color:red select <span style="color:blue =<span style="color:black "<span style="color:blue $Companies<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 if <span style="color:red test<span style="color:blue =<span style="color:black "<span style="color:blue msxsl:string-compare($number,SIG:ParentCompanyNo) = 0<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Group<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Name<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 value-of <span style="color:red select<span style="color:blue =<span style="color:black "<span style="color:blue SIG:Country<span style="color:black " <span style="color:blue />
<span style="color:blue </<span style="color:#a31515 Name<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Level<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 value-of <span style="color:red select<span style="color:blue =<span style="color:black "<span style="color:blue $level<span style="color:black "<span style="color:blue />
<span style="color:blue </<span style="color:#a31515 Level<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Groups<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 call-template <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue ChildNodes<span style="color:black "<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 with-param <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue number<span style="color:black " <span style="color:red select<span style="color:blue =<span style="color:black "<span style="color:blue SIG:SubsidiaryCompanyNo<span style="color:black "<span style="color:blue ><span style="color:blue </<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 with-param<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 with-param <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue Companies<span style="color:black " <span style="color:red select<span style="color:blue =<span style="color:black "<span style="color:blue $Companies[position() >1]<span style="color:black "<span style="color:blue ><span style="color:blue </<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 with-param<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 with-param <span style="color:red name<span style="color:blue =<span style="color:black "<span style="color:blue level<span style="color:black " <span style="color:red select<span style="color:blue =<span style="color:black "<span style="color:blue $level+1<span style="color:black "<span style="color:blue ><span style="color:blue </<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 with-param<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 call-template<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 Groups<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 Group<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 if<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 for-each<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 xsl<span style="color:blue :<span style="color:#a31515 template<span style="color:blue >
[/code]


<br/>
The Hierarchical XML I am trying to create is below...

<div style="color:black; background-color:white
<pre><span style="color:blue <<span style="color:#a31515 Groups<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Group<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Name<span style="color:blue >...<span style="color:blue </<span style="color:#a31515 Name<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Level<span style="color:blue >1<span style="color:blue </<span style="color:#a31515 Level<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Groups<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Group<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Name<span style="color:blue >...<span style="color:blue </<span style="color:#a31515 Name<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Level<span style="color:blue >2<span style="color:blue </<span style="color:#a31515 Level<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 Group<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Group<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Name<span style="color:blue >...<span style="color:blue </<span style="color:#a31515 Name<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Level<span style="color:blue >2<span style="color:blue </<span style="color:#a31515 Level<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Groups<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Name<span style="color:blue >...<span style="color:blue </<span style="color:#a31515 Name<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Level<span style="color:blue >3<span style="color:blue </<span style="color:#a31515 Level<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 Groups<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 Group<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 Groups<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 Group<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Group<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Name<span style="color:blue >...<span style="color:blue </<span style="color:#a31515 Name<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Level<span style="color:blue >1<span style="color:blue </<span style="color:#a31515 Level<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 Group<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 Groups<span style="color:blue >
[/code]

<br/>
Thanks in advance.

<
Tryst<br/>

View the full article
 
Back
Top