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

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

This mode has static scope rather than dynamic scope: it affects the instructions in the stylesheet that are textually within the element that carries the relevant
version
attribute. It only affects the behavior of the compiler; it does not alter the way that any instruction or expression is evaluated at runtime.

In forward-compatible mode, the XSLT processor must assume that the stylesheet is using XSLT facilities defined in a version of the standard that has been published since the software was released. The processor, of course, won't know what to do with these constructs, but it must assume that the stylesheet author is using them deliberately. It treats them in much the same way as vendor extensions that it doesn't understand:

  • It must report an error for XSLT elements it doesn't understand only if they are actually evaluated, and if there is no child

    instruction.
  • It must ignore attributes whose name it doesn't recognize. One particular consequence of this is that if the stylesheet specifies
    version = “2.0”
    , then an XSLT 1.0 processor will ignore any
    use-when
    attributes that it finds on XSLT elements.
  • In XSLT 1.0, there were some additional rules for forward-compatible mode that have been dropped in 2.0:
    • If an XPath expression uses a function that's not defined in XPath 1.0, an XSLT 1.0 processor running in forward-compatible mode must report an error only if the function is actually called. You can avoid this error condition by using
      function-available()
      to test whether the function exists before calling it.
    • Similarly if an XPath expression uses syntax that isn't allowed in XPath 1.0, the processor must report an error only if the expression is actually evaluated.
    • There's also a provision in XSLT 1.0 that the processor should ignore optional attributes whose value isn't recognized, for example

      . It seems that many XSLT 1.0 processors ignored this rule, so it might be unwise to rely on it.

This behavior occurs only if the

element specifies a version other than
1.0
(or for XSLT 2.0, a value greater than
2.0
). Forward-compatible mode can also be specified for a portion of a stylesheet by specifying the
xsl:version
attribute on any literal result element, and in the case of XSLT 2.0, by specifying the
version
attribute on any XSLT element. If forward-compatible mode is not enabled, then any use of an XSLT element, attribute, or function that isn't in the version of XSLT that the processor supports, or any use of XPath syntax that isn't in the corresponding XPath specification, is an error and must be reported, whether it is actually executed or not.

If you specify
version = “1.0”
and then use XSLT 2.0 facilities such as

, then an XSLT 1.0 processor will reject this as an error. An XSLT 2.0 processor, however, will process your stylesheet successfully. An XSLT 2.0 processor when given a stylesheet that specifies
version = “1.0”
is not expected to check that the stylesheet actually conforms to XSLT 1.0.

Other books

Born Again by Rena Marks
Wounded (In My Dreams) by Erin R Flynn
Her Alien Masters by Ann Jacobs
Hold Fast by Olivia Rigal, Shannon Macallan
Courage Tree by Diane Chamberlain
Flamebound by Tessa Adams