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

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

Usage

If your stylesheet only uses features from XSLT 1.0, it is probably best to specify
version=“1.0”
on the

element. Then it will work with any XSLT processor that conforms to XSLT 1.0 or a later version of the standard. (It will fail, however, on an XSLT 2.0 processor that doesn't support backward-compatibility mode. If such processors become common, this advice may need to change.)

If the stylesheet uses 2.0 features, you should specify
version=“2.0”
on the

element. An XSLT 2.0 processor that encounters a stylesheet with
version=“1.0”
at the start of the principal stylesheet module is supposed to give you a warning about possible incompatibilities and then process the stylesheet as if it were a 2.0 stylesheet, but with backward-compatibility mode switched on. (This doesn't guarantee 100% compatibility, but it's pretty close.)

If your stylesheet says
version=“1.0”
this won't stop you from using XSLT 2.0 features; an XSLT 2.0 processor isn't expected to look at every construct you use and decide whether it would have been allowed in XSLT 1.0. But for certain specific features, it causes XSLT 2.0 and XPath 2.0 to behave differently. The main examples of this is the “first item” rule mentioned earlier, where XSLT 1.0 takes the first item of a sequence and ignores the rest. This is most commonly encountered with the

instruction, described on page 495. Other differences are more rarified, for example
10 div 0
gives you Infinity in backward-compatibility mode, but throws an error in 2.0 mode.

XSLT 2.0 allows you to put the
version
attribute on any element in the stylesheet, and at first sight a nice idea would be to flag any template rule that uses XSLT 2.0 features by labeling it with the attribute
version=“2.0”
. Unfortunately, however, XSLT 1.0 doesn't allow the
version
attribute to appear on the

element, so if you want your stylesheet to still work with 1.0, this won't work. A better idea is probably to put all the template rules that depend on XSLT 2.0 in a separate module, and label this module with
version=“2.0”
at the

level. Of course, you will still need to provide 1.0 fallback behavior whenever you use a 2.0 construct.

Other books

John Lutz Bundle by John Lutz
The Bourne Betrayal by Lustbader, Eric Van, Ludlum, Robert
Ink Reunited by Carrie Ann Ryan
Blindfold by Patricia Wentworth
The Wald by Born, Jason
Hammerjack by Marc D. Giller