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:

  1. DB2 XPath evaluates each expression that is passed as an argument in the function call and returns a value for each expression.
  2. 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:
    1. The given value is atomized into a sequence of atomic values.
    2. Each item in the atomic sequence that is of type xs:untypedAtomic is cast to the expected atomic type. For built-in functions where the expected type is specified as numeric, arguments of type xs:untypedAtomic are cast to xs:double.
    3. 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, or xs:double.
  3. 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)