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

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

With XPath 2.0, if your source documents have gone through schema validation, the elements and attributes will be annotated with a type. This label tells the system what operations are legitimate on the type, and may also be used to select different ways of implementing the same operation. For example, testing
@A < @B
will give different results depending on whether the attributes
A
and
B
have been defined in the schema as strings, numbers, or durations.

Data labeled as
xs:untypedAtomic
continues to behave as all data did in XPath 1.0; it has no intrinsic type of its own and is converted to whatever the default type is for the context in which it is used. If you supply an
xs:untypedAtomic
value as an argument to a function call, it is converted (cast) to the type defined in the function signature. If you use it as an operand of an arithmetic operator such as
+
then the system tries to convert it to a number (actually, an
xs:double
). If you use it as an operand of
=
or
<
then it first tries to convert it to the type of the other operand, which means that
@A > 4
and
@A > ‘4’
may give you different answers (if the attribute value is
10
, for example, the first test will return
true
, the second
false
). If both operands are of type
xs:untypedAtomic
, then they will be compared using the rules for strings.

Other books

Girl 6 by J. H. Marks
Fashion Faux Paw by Judi McCoy
Walk the Sky by Swartwood, Robert, Silva, David B.
Coming Home to You by Liesel Schmidt
Mediterranean Summer by David Shalleck
Amanda Scott by Madcap Marchioness
Ride It Out by Lowe, Aden, Wheels, Ashley