Saxon traps Java's "stack overflow" error and this is its attempt to explain it in terms of what is happening at the XSLT level. Java's -Xmx option increases the heap space available but not the stack space. In principle, depending on the JVM in use, you can increase the stack space using the -Xss option.

It would be interesting to see the recursive function/template in question to see whether there is an easy way it can be made tail-recursive, which will stop Saxon consuming extra stack space for each recursive call.

Michael Kay

On 21/11/2011 20:48, Adcock, Stephen W wrote:
"Too many nested template ..." error

I am using Saxon 9.1 to convert OpenOffice ODT documents to XHTML, using XSLT files that are included in the OpenOffice distribution.  I have run into problems with a particularly complicated document that contains several hundred styles.  Saxon is giving the error message Too many nested template or function calls. The stylesheet may be looping.  The problem is with a recursive template, which is failing after 505 calls.  I tried to fix the problem by increasing the amount of memory via the Java Xmx option.  But the transformation continues to fail at exactly the same point, regardless of how much memory I specify.

Does Saxon have a fixed limit for the number of recursions, or is my problem more subtle?


Steve Adcock


Geological Survey of Canada

All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.

saxon-help mailing list archived at