XML technologies / XSLT / Reference: XSLT 1.0 and 2.0 elements / Forward and backward compatibility
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 6.)
The distinction between backward-compatible and forward-compatible processing depends on perspective. The underlying idea is that every XSLT processor, regardless of version, should be able to execute any XSLT stylesheet, also regardless of version, at least rudimentarily.
Compatibility matters when the stylesheet is not XSLT 2.0, or not all of its instructions are version 2.0. The processor can switch modes as needed, even locally, while processing a stylesheet.
Each XSLT instruction can be processed in a forward-compatible or backward-compatible mode, or be an XSLT 2.0 instruction handled normally without special measures.
From XSLT 2.0’s perspective:
Backward-compatible processing
Older XSLT processors should ignore new elements in XSLT 2.0 stylesheets, for declarations using unknown top-level elements, or execute appropriate xsl:fallback templates for unrecognized instructions inside templates.
An XSLT 2.0 stylesheet must supply alternative instructions or expressions using XSLT 1.0 and XPath 1.0 syntax inside the activated fallback templates. Values using XPath 2.0 data types are converted to corresponding XPath 1.0 types as needed.
Instead of xsl:fallback, use xsl:choose to choose between instruction blocks, controlled using functions function-available() or element-available(). Function system-property() can also query the XSLT processor’s version.
Alternatively, backward-compatible processing can be forced for an instruction and its contents, including attributes and descendant XSLT instructions, by giving it a version attribute with a value less than "2.0".
If the version attribute applicable to the instruction, set either on it or on an ancestor, is at least "2.0", backward-compatible mode cannot be enabled.
Forward-compatible stylesheet processing
Stylesheets with a version newer than the processor supports generally use forward-compatible processing. The processor should still process the stylesheet if possible, ignoring unknown instructions and attributes or executing corresponding fallback blocks.
If instructions or expressions are unknown and no fallback exists, an error should not be reported immediately. Static errors, normally detected while reading the stylesheet, are ignored and provisionally downgraded to dynamic errors. An error then occurs only when an unknown or uninterpretable expression is actually evaluated, as a runtime error.
Forward-compatible processing can also be forced by supplying a version attribute with a value greater than "2.0". This applies to the instruction and its contents, including attributes and descendant XSLT instructions.
If an applicable version attribute has a value less than or equal to "2.0", forward-compatible mode cannot take effect.
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from “XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn