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] XPath 3.1 introduction ?

Hi Christophe,

I'm glad it helps.

If you need something similar for XPath 3.0, here is a very quick intro as well to the main new features (of course, it's much more superficial than a complete course such as Dimitre's).

Higher-order functions:
===============

Create an inline function:
let $function := function($x as xs:integer) as xs:boolean { $x eq 1 }
return $function(2)

Reference a named function with its name and arity:
let $function as function(xs:string, xs:string) as xs:string := fn:concat#2
return $function("foo", "bar")

Partial application (currying):
let $partial-function := fn:concat#2("foo", ?)
return $partial-function("bar")

String concatenation inline
===============
|| can be used to concatenates strings
"foo" || "bar" || "foobar"

Map operator
========
The ! operator is identical to a for-return that binds the context item in turn to each item in the input sequence.
(1 to 10) ! (. * .)

It's also convenient for function call chains:
$node ! local:function1(.) ! local:function2(.) ! local:function3(.)

Extended QNames
============
You can build QNames for XPath navigation without binding a prefix (similar to the Clark notation):

doc("http://www.example.com/schema.xsd")/Q{http://www.w3.org/2001/XMLSchema}schema/Q{http://www.w3.org/2001/XMLSchema}element

Kind regards,
Ghislain



On Wed, Jun 22, 2016 at 11:43 AM, <cmarchand@oxiane.com> wrote:

 

 

Thanks Ghislain ! This is very clear an understandable !

In fact, I need also an introduction to XPath 3.0 ...

 

Best regards,

Christophe

 

Le 2016-06-22 11:35, Ghislain Fourny a écrit :

Hi Christophe
 
The most prominent add to XPath 3.1 is maps and arrays.
 
Here's a very abstract overview (which of course misses plenty of smaller details). It also applies to XQuery 3.1, which supports them as well.
 
In short:
========
- Items in sequences can now also be maps or arrays.
- Maps are associative arrays. Keys are any atomic value. Values are any sequences of items (including arrays and maps, so they can nest).
- Arrays are ordered lists of values. A values is any sequence of items (including arrays and maps, so they can nest).
- Values put into maps and arrays are *not* copied, so you can use maps, say, for indexing. This is different from XML node constructors.
 
To build them:
========
- One syntax for objects, looking a bit like JSON but more generic (since you can of course nest expressions) and with a keyword "map", like node constructors:
 
map { "foo" : "bar", "bar" : (1, 2, 3) }
 
- Two syntaxes for arrays:
 
Syntax 1 similar to that of maps, with an "array" keyword. It simply takes the sequence and each item in it becomes a value of the array (So you can't construct arrays with sequences of more than one item with this one):
array { 1, (2, 3, 4), (), 5 }
creates an array with 5 values, 1, 2, 3, 4 and 5.
 
Syntax 2 similar to JSON, but it's comma-sensitive in the sense that they delimit the values (so it's not a comma expression inside: the commas are part of the constructor)
[ 1, 2, 3, 4, (), (5, 6) ]
creates an array with 5 values : 1, 2, 3, 4, the empty sequence, and the sequence (5,6)
 
Navigation:
========
Alternative 1: Use maps and arrays as function items:
let $map := map { "foo" : "bar" }
return $map("foo")
 
let $array := array { 1, 2, 3 }
return $array(2)
 
Alternative 2: Use the ? operator (for NCNames and integers):
let $map := map { "foo" : "bar" }
return $map?foo
 
let $array := array { 1, 2, 3 }
return $array?2
 
The ? operator works with wildcards to "unbox" arrays or maps to a sequence:
let $array := array { 1, 2, 3 }
return $array?*
 
(it also exists as a unary operator, which implicitly assumes the context item on the left-hand-side)
 
Functions:
========
There are plenty of new functions for maps and arrays documented here: https://www.w3.org/TR/xpath-functions-31/#maps-and-arrays
 
Types:
=======
There are item type notations such as map(*), map(xs:integer, node()), array(xs:integer), array(*), etc.
 
I hope it helps you get started!
 
Feel free to correct me if I got anything wrong in the above.
 
Kind regards,
Ghislain
 
 



[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