Function calls
DB2® XPath supports calls to built-in XPath functions.
Built-in XPath functions are in the namespace http://www.w3.org/2003/11/xpath-functions. If the function name in the function call has no namespace prefix, the function is considered to be in the default function namespace.
DB2 XPath uses the following process to evaluate functions:
- DB2 XPath evaluates each expression that is passed as an argument in the function call and returns a value for each expression.
- The value that is returned for each argument is converted to the
data type that is expected for that argument. When the expected type
is a sequence of zero or more atomic types, DB2 XPath uses the following rules to convert
the value to its expected type:
- The given value is atomized into a sequence of atomic values.
- Each item in the atomic sequence that is of type
xs:untypedAtomicis cast to the expected atomic type. For built-in functions where the expected type is specified asnumeric, arguments of typexs:untypedAtomicare cast toxs:double. - Numeric type promotion is applied to any numeric item in the atomic
sequence that can be promoted to the expected atomic type through
numeric type promotion. Numeric items include items of type
xs:integer,xs:decimal, orxs:double.
- The function is evaluated using the converted values of its arguments. The result of the function call is either an instance of the function's declared return type or an error.
Example
The following example retrieves
the first three characters of the pid attribute of a product document:
declare namespace pos="http://posample.org";
fn:substring(/pos:product/@pid, 1, 3)