XPath/XQuery apply function


Makes a dynamic call on a function with an argument list supplied in the form of an array.


$function as function(*),
$array as array(*)
) as item()*


This function is deterministic, context-independent, focus-independent, and higher-order.


The result of the function is obtained by invoking the supplied function $function with arguments taken from the members of the supplied array $array. The first argument of the function call is the first member of $array, the second argument is the second member of $array, and so on.

The arity of the supplied function $function must be the same as the size of the array $array.

The effect of calling fn:apply($f, [$a, $b, $c, ...]) is the same as the effect of the dynamic function call $f($a, $b, $c, ....). For example, the function conversion rules are applied to the supplied arguments in the usual way.


The expression fn:apply(fn:concat#3, ["a", "b", "c"]) returns "abc".

The expression fn:apply($f, array:subarray(["a", "b", "c", "d", "e", "f"], 1, fn:function-arity($f))) calls the supplied function $f supplying the number of arguments required by its arity.

Error Conditions

A dynamic error is raised if the arity of the function $function is not the same as the size of the array $array ().


The function is useful where the arity of a function item is not known statically.