XSLT processing recursion depth?

This can happen when processing a very long sequence with primitive recursion.

This can happen when processing a very long sequence with primitive recursion. Imagine implementing the sum() function with a recursive named template: 1"/> when applied on the following XML document: 01 02 03 04 05 06 07 08 09 10 the result is: 55 Now, imagine that nums has 1000000 (1M) num children. This would be a legitimate attempt to find the sum of one million numbers, however most XSLT processors typically crash at a recursion depth at or around 1000.

The solution: Use tail-recursion (a special kind of recursion where the recursive call is the last instruction in the template). Some XSLT processors recognize tail recursion and optimize it internally to iteration, so there is no recursion and no stack overflow. Use DVC-style recursion (Divide and Conquer).

This works with all XSLT processors. The maximum recursion depth is log2(N) and is feasible for most practical purposes. For example, processing a sequence of 1M items requires a stack depth of only 19.

Here is a DVC implementation of the sum template: $vHalf)"/> $vHalf"/> Using this template to find the sum of one million numbers takes some time, but produces the correct result without crashing.

1, this is what I was looking for. A legitimate processing that leads to a deep recursion. Again, not having any experience with XSLT: would you say that if one starts hitting StackOverflow exceptions it is time to study and optimize the template?(as opposed to increasing the -Xss to a ridiculously huge number (like 700megs) to get around them?) – finrod Mar 27 at 0:36 asked some weird questions before and then could not follow up and validate myself that's about it.

– finrod Mar 27 at 9:40.

It's most likely a bug in the XSLT that's resulting in infinite recursion (where "infinite" is defined as "right up until you run out of memory"). Consider the following template: The only template in the document matches the root element and then calls apply-templates on itself, which starts a process that will never terminate.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions