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
9.87Mb size Format: txt, pdf, ePub
ads

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


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

Other books

Here's to Forever by Teagan Hunter
Spirit by John Inman
The Secret Lives of Housewives by Joan Elizabeth Lloyd
Still Star-Crossed by Melinda Taub
His Kind of Trouble by Samantha Hunter
To Catch a Cat by Marian Babson