Manage Learn to apply best practices and optimize your operations.

Migrating to XSLT 2.0

Many will find the extensions they built off of XSLT 1.0 aren't compatible with XSLT 2.0. Ed Tittel recommends dropping the homegrown code in favor of sticking with the ongoing standard.

Those of you who follow my tips know I mentioned that a new XSLT 2.0 recommendation was approved by the W3C in January, more than seven years after version 1.0 made the scene. In fact, it may have been that mention that prompted questions about any differences there might be between extended versions of XSLT (usually based on the 1.0 recommendation) and the new and presumably improved XSLT 2.0. The baldest version of the problem might be stated as "Should I stick with my hand-crafted extensions or drop them in favor of what XSLT 2.0 provides?"

The short answer to that question goes something like this: "That depends: XSLT 1.0 and 2.0 are both inherently extensible, so many of the extensions crafted for 1.0 should also work for 2.0." But as is usual when the rules for any game get changed, there are a few potential gotchas lurking in the weeds. Programmed XSLT 1.0 extensions are subject to the provisos in Section J at the end of the 2.0 Recommendation, which talk about incompatible changes from the 1.0 to 2.0 implementations and start to make sense to readers who've created XSLT 1.0 extensions in terms of what will and won't migrate from 1.0 to 2.0 without some effort and rework on their part (and perhaps some judicious tossing of new functionality that's part of 2.0 that some developers will have crafted in some form or fashion for themselves).

From a "migrating extensions from 1.0 to 2.0" perspective, if the extensions in question replicate or resonate with new functionality in 2.0, it's probably best to drop older, home-made code or capabilities in favor of newer, standard code or capabilities that fall under the recommendation's coverage. Though this may be painful, it will require less maintenance work going forward, in that you can count on the team that keeps up XSLT 2.0 to deal with future changes to standard features and functions rather than having to keep with an entire code base and markup handling components of your own crafting. Some of these changes are mostly organizational and terminological (including items like keys, xsl:number, the format-number function, and xsl:import handling). Support for the XDM data model has also affected how looping and sorting constructs (xsl:for-each, xsl:value-of, and xsl:sort) are handled, and include a new xsl:sequence instruction as well.

The biggest change is that instructions no longer write their outputs to a result tree, rather, they now return sequences of values. Here again, this may be viewed by some as restating existing functionality in new terms, but this approach lets XSLT stylesheets now handle arbitrary sequences of text and data, even those with parentless elements or attribute nodes. Likewise, the concepts of current node and current node list used when navigating a tree are now supplanted with XPath context items, context positions and context sizes. Integration of XML Schema into XPath 2.0 and its widespread use with XSLT 2.0 also means stronger data typing is available, but also that backward compatibility with older typing mechanisms is maintained. Variable and parameter types may now be specified explicitly, while schema validation may be applied to result sequences and for attributed and elements in temporary sequences as well. Finally, error handling has been cleaned up and rules regarding how errors and exceptions are signaled have been tightened up and made more explicit.

Only those who have XSLT 1.0-based applications who have built extensions to the underlying markup language can really decide if they should keep going with what they've got, or re-craft that code base in light of what XSLT 2.0 brings to the table. Because much of the new stuff really is clearer and offers broader functionality, I have to believe that in many such analyses, developers will decide to migrate and trade in their proprietary extensions for new or similar capabilities that come standard in XSLT 2.0.

About the author

Ed Tittel is a full-time writer and trainer whose interests include XML and development topics, along with IT Certification and information security topics. Among his many XML projects are XML For Dummies, 4th edition, (Wylie, 2005) and the Shaum's Easy Outline of XML (McGraw-Hill, 2004). E-mail Ed at with comments, questions or suggested topics or tools for review.

Dig Deeper on Topics Archive

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.