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

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

How does backward compatibility actually affect the results of the stylesheet? One thing that it does
not
do is to say “process this according to the rules in the XSLT 1.0 specification.” This wouldn't work, because the parts of the stylesheet that use 2.0 facilities and the parts that use backward-compatibility mode need to work with the same data model, and the data model used by an XSLT 2.0 processor is the 2.0 data model, not the 1.0 data model. Instead, backward-compatibility mode changes the behavior of a small number of specific XSLT and XPath constructs, in quite specific ways.

Here is a checklist of the things that are done differently. The left-hand column indicates the normal XSLT 2.0 (or XPath 2.0) behavior, the right-hand column the behavior in backward-compatibility mode.

First, the differences covered by the XSLT 2.0 specification are given as follows.

2.0 Behavior
1.0 Behavior
When the value selected by the

instruction is a sequence, all the values are output, separated by spaces.
When the value selected by the

instruction is a sequence, the first value is output, and the rest are ignored.
When the value produced by an expression in an attribute value template is a sequence, all the values are output, separated by spaces.
When the value produced by an expression in an attribute value template is a sequence, the first value is output, and the rest are ignored.
When the value returned by the expression in the
value
attribute of

is a sequence, all the numbers in the sequence are output, according to the format described in the format attribute.
When the value returned by the expression in the
value
attribute of

is a sequence, the first number in the sequence is output, and the rest are discarded.
When the value of a sort key is a sequence containing more than one item, a type error is reported.
When the value of a sort key is a sequence containing more than one item, the first item is used as the sort key, and remaining items are ignored.
When

supplies a parameter that's not defined in the template being called, a static error is reported.
When

supplies a parameter that's not defined in the template being called, the extra parameter is ignored.
Values used as keys are compared as supplied, for example as numbers or dates.
When keys are used, values are always converted to strings before being compared.
When the first element output is an

element in the XHTML namespace, the output method defaults to XHTML.
When the first element output is an

element in the XHTML namespace, the output method defaults to XML.

Backward-compatibility mode also affects the way that XPath expressions in the stylesheet are evaluated. Here are the differences.

2.0 Behavior
1.0 Behavior
When a function expects a single node or a single item as an argument, and the supplied value of the argument is a sequence containing more than one item, a type error is reported.
When a function expects a single node or a single item as an argument, and the supplied value of the argument is a sequence containing more than one item, all items except the first are ignored.
When a function expects a string or a number as an argument, and the supplied value is of the wrong type, a type error is reported.
When a function expects a string or a number as an argument, and the supplied value is of the wrong type, the system converts the supplied value using the
string()
or
number()
function as appropriate.
When one of the operands to an operator such as
=
or
<
is a number, and the other is not, a type error is reported.
When one of the operands to an operator such as
=
or
<
is a number, and the other is not, the non-numeric operand is converted to a number using the
number()
function.
When one of the operands of an arithmetic operator such as
+
or
*
is a sequence containing more than one item, a type error is reported.
When one of the operands of an arithmetic operator such as
+
or
*
is a sequence containing more than one item, all items except the first are ignored.

Other books

Valley Thieves by Max Brand
Dead Over Heels by MaryJanice Davidson
A Rogue by Any Other Name by Sarah MacLean
Lifestyles of the Rich and Shameless by NOIRE, Swinson, Kiki
Forbidden Embrace by Charlotte Blackwell
Pushing Ice by Alastair Reynolds
Tori Phillips by Lady of the Knight