#148 Tail call bug in apply-templates

v7.6.5
closed
Michael Kay
5
2012-10-08
2003-07-14
Michael Kay
No

When a call on apply-templates is the last thing to
happen in a template, tail call optimization kicks in -
the call is performed after the containing template
returns to its caller, reducing the number of calls on
the stack. But when the select expression of the
apply-templates call contains references to variables
(or possibly other aspects of the context such as
position()) then the context information isn't being
saved properly.

The effect is unpredictable, it might be a Java error
such as a NullPointerException or ClassCastException,
or it might be other spurious errors or simply wrong
results.

The workaround is to insert <xsl:value-of select="''"/>
(outputting an empty string) after the tail call of
apply-templates, to stop tail call optimization happening.

Reported by Craeg K Strong [cstrong (at)
arielpartners.com]
.

Not yet fixed. The two possible fixes are to save the
context properly, or to suppress tail call optimization
in this situation.

Discussion