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
3.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

A Vampire's Claim by Joey W. Hill
Hollywood Animal by Joe Eszterhas
Sure of You by Armistead Maupin
Demon (GAIA) by Varley, John
Now You See Her by Cecelia Tishy
Inbetween Days by Vikki Wakefield
Doctor Mirabilis by James Blish