Type promotion
Type promotion is a process that converts an atomic value from its original type to the type that is expected by an expression. XPath uses type promotion during the evaluation of function calls and operators that accept numeric or string operands.
XPath permits type promotion and subtype substitution. Type promotion
and subtype substitution differ in the following ways:
- For type promotion, the atomic value is actually converted from its original type to the type that is expected by an expression.
- For subtype substitution, an expression that expects a specific type can be invoked with a value that is derived from that type. However, the value retains its original type.
- Numeric type promotion:
- A value of type xs:decimal (or any type that is derived by restriction
from xs:decimal) can be promoted to xs:double. The result of this
promotion is created by casting the original value to the required
type.In the following example, the xs:double value 13.54e-2 is added to the xs:decimal value 100. The xs:decimal is promoted to xs:double to do the arithmetic and a result with a type of xs:double is returned:
xs:double(13.54e-2) + xs:decimal(100)