Replace Awkward XSLT 1.0 Code with XSLT 2.0 Features
A less drastic way to migrate to XSLT 2.0 is to look through
your stylesheets for templates that could be replaced with XSLT 2.0
features. For example, if you have a recursive template to do string
replacement, replacing that with the new replace() function will simplify your
code. (It’s likely it will perform better as well.) Anything that uses
recursion or extension functions is a candidate for replacement with
XSLT 2.0.
Another thing to look for is using variables extensively. If you use a variable to store the result
generated by a named template, consider replacing the named template
with an <xsl:function>. Using
an XSLT 2.0 function means you can invoke the code inside an XPath
expression. The function call can replace the variable and the named
template with a single step.
If the templates in your stylesheet pass many parameters, consider using tunnel parameters. As stylesheets grow in complexity and power, it’s common for every template to accept one or more parameters, and then pass those parameters on to any templates it invokes. The stylesheet needs to pass those parameters to every template in case they’re needed somewhere. Tunnel parameters make your code much cleaner and simplify maintenance.
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