[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: function definitions in XPath 3.x expressions

  • From: "Ghislain Fourny" <gfourny@inf.ethz.ch>
  • To: Mukul Gandhi <gandhi.mukul@gmail.com>
  • Date: Fri, 22 Jun 2018 09:02:12 +0000

Re:  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:


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]:


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 }
let $y := count#1
return $y($x(2, 3))

Does it help you further?

Kind regards,

[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]


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.

Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.