XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] function definitions in XPath 3.x expressions

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@inf.ethz.ch> 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]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS