Dear Mukul,
Indeed, XPath 3.0 supports higher-order functions.
The data model is extended with functions, meaning that items can be not only atomic items or nodes, but also functions [1].
XPath 3.0 supports a new kind of expression for defining functions [2], that looks like so (example from the specification):
function($a as xs:double, $b as xs:double) as xs:double { $a * $b }
The above expression returns a sequence of one item, which is a function.
XPath 3.0 also has a new kind of expression for calling functions dynamically [3]. If $x is bound with a function with arity 1 taking a string and returning an integer, for example, then:
$x("foo")
returns an integer.
It is also possible to create a function from a declared function (named function, builtin or user-defined) with its name and arity [4]:
math:sin#1
fn:string-join#2
Both of the above expressions return a function item.
This can be combined into more complicated XPath 3.0 queries like so:
let $x := function($a as xs:double, $b as xs:double) as xs:double { $a * $b }
return
let $y := count#1
return $y($x(2, 3))
Does it help you further?
Kind regards,
Ghislain
[1] https://www.w3.org/TR/xpath-datamodel-30/#function-items
[2] https://www.w3.org/TR/xpath-30/#id-inline-func
[3] https://www.w3.org/TR/xpath-30/#id-dynamic-function- invocation
[4] https://www.w3.org/TR/xpath-30/#id-named-function-ref