It's not a tail call because the result of the recursive call is processed
by the caller after return: when you do
it's the same as
<xsl:sequence select="xyz, f(xxx)"/>
where the "," is a sequence concatenation operator.
One way around this is to pass xyz as an extra parameter to the recursive
function call, and have the concatenation done by the callee rather than the
In fact the mechanism used for tail-call optimization on templates handles
this situation, because it relies on the code being evaluated in push mode,
where results are written to a Receiver as soon as they are generated, which
means the function/template doesn't actually do a real concatenation. But
functions don't currently work that way. So: no, it's not a bug, just a
limitation of the current design.
From: Cary Millsap [mailto:cary.millsap@...]
Sent: 15 October 2008 17:50
Subject: [saxon] Too many nested template or function calls 126.96.36.199j
Attached is a self-contained, reproducible test case (it includes Saxon
188.8.131.52j) that runs two slightly different XSL transforms. Each causes a
1) Too many nested template or function calls. The stylesheet may be
2) Exception in thread "main" java.lang.StackOverflowError
It seems to us that the function call in the XSLT should qualify as
optimizable tail recursion, but it's seems not to be behaving that way...
Is this a Saxon bug?
Thank you in advance,
From: Michael Kay <mike@sa...> - 2008-10-17 12:27:33
> Ouch, a 2.4-megabyte attachment. No wonder I'm suddenly
> getting quota warnings.
Yes, on Cary's behalf, sorry about that. Could I please remind all users to
exercise restraint in the size of attachments. In particular, if you're
submitting a test case, there's no need to include a copy of the Saxon JAR
files! (In fact, just to be really pernicketty, your license doesn't allow
you to do so - the JAR files must never be distributed without the
accompanying legal notices and acknowledgements.)
If anyone knows Sourceforge or Mailman better than I do, and knows how to
limit the size of attachments, then please let me know. I can't see a way of
On the rare occasions when there really is a need to supply large amounts of
test material, it can either be sent to me direct, or uploaded to the
"Support Requests" tracker on SourceForge.