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

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 


> On 22 Jun 2018, at 07:54, Mukul Gandhi <gandhi.mukul@gmail.com> wrote:
> 
> Hi all,
>    I've come to know that, XPath 3.0 has introduced defining functions in XPath expressions, and calling these functions in the expression itself.
> 
> To understand this better, I'm looking for some examples of this. Can someone, please point me to some resources for this? Or may be, explaining with examples in this thread itself.
> 
> 
> 
> -- 
> 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