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.
Get XSLT, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.