Recursion Isn’t Necessary Nearly as Often
In XSLT 1.0 stylesheets, tail recursion was a common
technique. String replacement, for example, requires a recursive
template that replaces the first instance of a substring, and then
reinvokes itself with the remainder of the string. In XSLT 2.0, you
can use the replace() function.
Recursive templates are much more difficult to write and maintain; if
you can replace them with simpler code in an XSLT 2.0 stylesheet, it’s
worth it. See the section [2.0] Using the XPath 2.0 replace() Function to Avoid
Recursion” in
Chapter 5 for a more detailed example. Another
good example is in the section Doing Math Without Recursion” in
Chapter 8.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access