XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (55 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
9.75Mb size Format: txt, pdf, ePub

If you specify
version = “1.0”
in the stylesheet, then you are signaling the fact that the stylesheet was designed to be run under XSLT 1.0, and that in some specific cases where XSLT 2.0 defines different behavior from 1.0, the 1.0 behavior should be used. For example, if you supply a sequence of nodes as the value of the
select
attribute of

, the XSLT 1.0 behavior is to output the first value in the sequence and ignore the others; the XSLT 2.0 behavior is to output all the values, space separated.

Specifying
version = “1.0”
does
not
mean that you cannot use facilities that were newly introduced in XSLT 2.0. It only means that an XSLT 2.0 processor should use the 1.0 behavior in certain specific cases where there are incompatibilities.

XSLT 2.0 processors are not required to implement backward-compatibility mode. If they don't provide this feature, they must reject any stylesheet that specifies
version = “1.0”
. Some products, such as XMLSpy, use the version number to decide whether to invoke an XSLT 1.0 processor or an XSLT 2.0 processor.

If you specify
version = “2.0”
in a stylesheet, and then run it under an XSLT 1.0 processor, you are indicating that the stylesheet makes use of facilities that were newly introduced in XSLT 2.0, and that the 1.0 processor should not treat these constructs as an error unless they are actually evaluated. The stylesheet can use various mechanisms to avoid evaluating the constructs that depend on XSLT 2.0 when these features are not available. This only works, of course, because the need for it was anticipated in the XSLT 1.0 specification, and even though no details were known of what new features would be introduced in a later version of the language, XSLT 1.0 processors were required to behave in a particular way (called forward-compatibility mode) when the
version
attribute was set to a value other than
1.0
. XSLT 2.0 similarly carries forward these provisions so that when the time comes, stylesheets that take advantage of new features in XSLT 3.0 or beyond will still be able to run under an XSLT 2.0 processor.

If you use facilities defined in XSLT version 1.0 only, but want your stylesheet to run under both XSLT 1.0 and 2.0 processors, then you should specify
version = “1.0”
, and every conformant XSLT processor will then handle the stylesheet correctly, provided (a) that you're not using an XSLT 2.0 processor without support for backward-compatible mode, and (b) that you're not using one of the few constructs that are incompatible even in backward-compatible mode. There is a list of these in Appendix C, and for the most part they are things that reasonable users would not do.

Other books

Death Be Not Proud by John J. Gunther
Room for Love by Sophie Pembroke
Stalking Ivory by Suzanne Arruda
The Lost Weekend by Charles Jackson
Chaser by Miasha
Demon's Bride by Zoe Archer
Dawn Annis by Highlander's Ransom
Requiem by Celina Grace
Buddha Da by Donovan, Anne