Here is my function:
<func:function name="entry-check">
<xsl:param name="bunch"/>
<xsl:param name="history"/>
<xsl:param name="index"/>
<xsl:param name="depth"/>
<xsl:variable name="member" select="$bunch[$index]"/>
<xsl:variable name="vipmember" select="key('member-any',$member/@i)[check-vipmember(.)]"/>
<xsl:choose>
<xsl:when test="not($member)">
<func:result select="$bunch[$history]"/>
</xsl:when>
<xsl:when test="$vipmember">
<func:result select="pp:tern($history,set:trailing($bunch,$member),$vipmember[1])"/>
</xsl:when>
<xsl:when test="$member/self::cmt">
<func:result select="entry-check($bunch,$history,$index -1,$depth)"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="next" select="pp:version-bunch(key('i',$member[$depth]/@from)/..)"/>
<func:result select="entry-check($next,$history,count($next),$depth -1)|$bunch[$history]"/>
</xsl:otherwise>
</xsl:choose>
</func:function>
bunch is actually a set of nodes, history is always true(), depth is always 3 when this function is called. index = (number of nodes in bunch) -1
If index > 1000 it fails with error message: detected a recursion xmlXPathCompiledEval: 3 objects left on stack. Only this line fails: <func:result select="entry-check($bunch,$history,$index -1,$depth)"/>
I'm using 1.0 xslt processor. Tried to rewrite it to tail-recursive, but result was the same (I exchanged the two recursive calls within the function).
Please, provide some help how to change it so as not crash after 1000 iteration (overall number of iteration is between 1000 and 100 000). I checked some examples of DVC recursion, they were very simple compared to my function, so based on these examples Im not sure if it can be changed to DVC. Any other working idea is also appreciated.
Thanks in advance!