There's no fixed limit to the stack depth in Saxon. Saxon is merely catching the "stack limit exceeded" exception thrown by Java. My experience is that this limit tends to be hit after about 250-500 template calls. Note that this doesn't depend on how many variables and parameters the templates have, because these are not actually stored on the Java stack. But it does depend on the nesting of instructions within the templates - each nested instruction uses Java stack space.
 
The best way to reduce stack usage is to look for opportunities to make your code tail-recursive. There may also be opportunities to use divide-and-conquer recursion.
 
Michael Kay
http://www.saxonica.com/


From: Roberto Cisternino [mailto:roberto.cisternino@gmail.com]
Sent: 16 January 2009 11:24
To: saxon-help@lists.sourceforge.net
Subject: Re: [saxon] allocate more stack space [was: Saxon B 9.1.0.2]

Hi Michael,
this is the same issue I experienced:
http://www.oxygenxml.com/forum/post9782.html

Using Oxygen I can successfully perform the transformation.

I am not sure to understand the Maximum depth in templates stack however.

Before I badly reported 6-10 nested calls of templates, but that was just the XSD Element nesting, so the real depth in templates stack seems to be near 252 but for sure lower than 300.

The Oxygen limit is by default 300.

Are there any fixed max depth in Saxon ?

I cannot easely simplify or reduce my templates, because the OOP structure of UBL is naturally causing similar depths of complexTypes, extensions, restrictions, sequences, so on...

I think UBL is a good sample of an XML contextualization for the business, and its complexity could be a good sample to test XSLT and other XML related tools for real cases.

I really hope you can help me about this issue.

Thanks

Roberto

On Fri, Jan 16, 2009 at 10:20 AM, Roberto Cisternino <roberto.cisternino@gmail.com> wrote:
Hi,
thanks for answering so fast.

The stylesheet I am testing is traversing UBL XSDs so I expect there are 6-10 nested calls, but in general to work is more long than complex.

The stylesheets generates a prototypical instance of the UBL 2.0 Invoice XSD, and the result is about 2 Mb.

It is also a porting from an XSLT 1.0 stylesheet designed for Xalan XSLTC, so I admit it is a long stylesheet (63 Kb)

I'll try to play more with the stack space settings on the target VM.

Also I tested both Java 1.5.x and 1.6 (which is using memory more dynamically) but the error is the same.

Thanks for helping

Roberto

Michael Kay wrote:
-------------------------------------------------------------------------------------------------------------
Message: 5
Date: Fri, 16 Jan 2009 09:01:31 -0000
From: "Michael Kay" <mike@saxonica.com>
Subject: Re: [saxon] Saxon B 9.1.0.2
To: "'Mailing list for the SAXON XSLT and XQuery processor'"
       <saxon-help@lists.sourceforge.net>
Message-ID: <CCB29C897F2547F5878AB61DC004446C@Sealion>
Content-Type: text/plain; charset="us-ascii"

I've never been successful trying to allocate more stack space to the Java
VM. The amount of heap space will make no difference to this error.

The most likely explanation for the different behaviour is simply that your
application code is using some of the stack space that would otherwise be
available to Saxon.

I can't really offer any other suggestions without seeing your code. How
deeply nested do you think its calls are?

Michael Kay
http://www.saxonica.com/

(By the way, it's helpful if you can choose a subject line that describes
the problem. If everyone titled their posts as you have done, it would
become very difficult to find your way through the archives or through
digest postings.)

-------------------------

Message: 4
Date: Fri, 16 Jan 2009 07:58:37 +0100
From: "Roberto Cisternino" <roberto.cisternino@gmail.com>
Subject: [saxon] Saxon B 9.1.0.2
To: saxon-help@lists.sourceforge.net
Message-ID:
       <a51969020901152258m7d26c14fjd27ef19e6db5c02c@mail.gmail.com
>
Content-Type: text/plain; charset="utf-8"

Hello,
I need help to understand why Saxon B 9.1.0.2 is behaving differently
depending if I use it from the command line or direclty from a java program.

Using the command-line the stylesheet works perfectly and the transformation
generates as expected a good result.
Using Saxon from a Java program and the same stylesheet caused the below
error:

javax.xml.transform.TransformerException: Too many nested apply-templates
calls. The stylesheet may be looping.; SystemID: ...

For sure the source XML and the stylesheet are enought complex, but I am
surprised I cannot obtain the same result using one of the two methods
described.

I tuned the VM to provide more heap memory or stack, but the result was
always the above error.

The error appears too early in the transformation, and this surprise me more
and more as the transformation is enough long (less than half a minute)
using the command-line.

What are the default memory settings for the Saxon B command-line ?

Any ideas ?

I will appreciate very much any suggestions

Thank you in advance

--
Roberto Cisternino
-------------- next part --------------
An HTML attachment was scrubbed...





--
Roberto Cisternino