Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
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.