[Home] [By Thread] [By Date] [Recent Entries]

  • From: Mukul Gandhi <gandhi.mukul@g...>
  • To: Ghislain Fourny <gfourny@i...>
  • Date: Fri, 22 Jun 2018 15:08:03 +0530

Hi Ghislain,
   Thanks for the answer.

It does help me. Now its more clear to me.

On Fri, Jun 22, 2018 at 2:32 PM, Ghislain Fourny <gfourny@i...> wrote:
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 

 



--
Regards,
Mukul Gandhi


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member