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

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

If the
as
attribute is omitted, then the supplied value may be of any type.

The value that is actually supplied by the caller must be suitable for the required type. The value is converted if necessary using the standard conversion rules described on page 505, and it is a fatal error if this conversion fails. Because the ability to specify a type on

is new in XSLT 2.0, the 1.0 compatibility rules are never used even if the stylesheet version is set to
1.0
. In summary, this means that the only conversions allowed are:

  • Atomization (that is, extraction of the typed values of nodes, when the required type is an atomic value or a sequence of atomic values)
  • Numeric promotion; for example, conversion of
    xs:integer
    to
    xs:double
  • Promotion of
    xs:anyURI
    to
    xs:string
  • Casting of
    xs:untypedAtomic
    values (which normally arise as a result of atomizing a node in a document that has not been schema-validated)

If the supplied parameter is the wrong type, then the error may be detected either at compile time or at runtime. With stylesheet parameters, however, the supplied value isn't known until runtime, so this is when the error will occur.

The
as
attribute on

also serves a second purpose. Like the
as
attribute on

, it is used when the

element has a contained sequence constructor to distinguish whether the default value is the sequence obtained by evaluating the sequence constructor, or the result of building a temporary document using this sequence to provide the content. For example:

Madrid

declares a parameter whose default value is a temporary tree consisting of a document node, which owns a text node whose string value is
Madrid
; while:

Madrid

declares a parameter whose required type is a single string, and whose default value is the string
Madrid
. If you really need to say that the required type is a document node, and to supply a temporary document as the default value, then you can write it like this:


    Madrid


Other books

Heartsong by James Welch
Aegis Rising by S.S.Segran
Social Blunders by Tim Sandlin
Mistaken Identity by Montgomery, Alyssa J.
Dewey's Nine Lives by Vicki Myron
0765332108 (F) by Susan Krinard
George's Grand Tour by Caroline Vermalle
Unbound by Emily Goodwin