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

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

The rule for
SingleType
is confusing at first sight. It means that the
AtomicType
may optionally be followed by a question mark.

In all these cases, the
AtomicType
must correspond to the name of an atomic type (that is, a simple type that is not a list type or a union type) that is present in the static context for the XPath expression. Most commonly, this will be one of the built-in types such as
xs:integer
or
xs:date
, but it can also be a user-defined type. The type name is written as a
QName
, and its namespace prefix must therefore have been declared to reference the
targetNamespace
of the schema in which the type is defined. If the name has no prefix, the default namespace for elements is used; in XSLT, this will be the null namespace, unless the
xpath-default-namespace
attribute has been set to identify a different namespace.

The concept of the static context was described in Chapter 7. An atomic type will be present in the static context either if it is a built-in type such as
xs:date
, or if it is defined in a schema that has been explicitly imported using the

declaration in XSLT, or its equivalent in a different XPath host language.

A question mark after the type name means that an empty sequence is allowed as the value. For example, the expression
@A
cast
as
xs:integer
will fail if the attribute
A
does not exist, but the expression
@A cast as xs:integer?
will succeed, returning an empty sequence.

The
castable
as
expression returns
true
if the corresponding
cast
as
expression would succeed, and
false
if the corresponding
cast
as
expression would fail. For example, the string
2009-02-29
is not a valid date, so the expression
“2009-02-29”
castable
as
xs:date
returns
false
.

Other books

The Trouble With Moonlight by Donna MacMeans
Kill For Me by M. William Phelps
Haunted by Ella Ardent
Threats by Amelia Gray
Briarwood Cottage by JoAnn Ross
Eternity Road by Jack McDevitt
Mind Blower by Marco Vassi