XQuery 4.0
This article is part of the XQuery Portal. It provides a summary of the most important features of the XPath and XQuery Functions and Operators 4.0 W3C Editor's Draft.
Contents
Otherwise operator[edit]
$a otherwise $b
… is equivalent to …
if(exists($a)) then $a else $b
Braced if, optional else[edit]
if($a) { $b } else { $c }
if($a) { if($b) { $c } }
Arrow map operator[edit]
"The cat sat on the mat" => tokenize() =!> concat(".") =!> upper-case() => string-join(" ")
Numeric literals[edit]
1_048_576
0xFC00
0b111000
Abbreviated function syntax[edit]
let $inc := fn($n) { $n + 1 } return $inc(99)
… is equivalent to …
let $inc := function($n) { $n + 1 } return $inc(99)
Focus functions (arity-one)[edit]
let $inc := fn { . + 1 } return $inc(99)
fn:filter($integers, fn { . > 5 })
fn:iterate-while($number, fn { . < 100 }, fn { . * . })
Optional arguments[edit]
declare function strings:get( $value, $default := "EMPTY" ) { $value otherwise $default } strings:get('john')
Keyword arguments[edit]
declare function coordinates( $x := 0, $y := 0 ) { map { "x" : $x, "y" : $y } } coordinates(y := 123)
String templates[edit]
`Name: { $name }, { $age }`
… is equivalent to …
"Name: " || $name || ", " || $age
… or …
``[Name: `{ $name }`, `{ $age }`]``
Union node tests[edit]
/xml/child::(a|b)
/xml/element::(c|d)
Compact lookup syntax[edit]
$address?$name, $city?"city code"
… is equivalent to …
$address?($name), $city?("city code")
Maps[edit]
6 new map functions have been added in XPath and XQuery Functions and Operators 4.0, namely
map:build
map:filter
map:of-pairs
map:pair
map:replace
map:substitute
Map functions are described in Map Module.
Arrays[edit]
8 new array functions have been added in XPath and XQuery Functions and Operators 4.0, namely
array:build
array:foot
array:members
array:of-members
array:replace
array:slice
array:split
array:trunk
1 array function has been updated:
array:subarray
Array functions are described in Array Module.
Changelog[edit]
- Version 11.0
- Added operator
otherwise
- Added function
map:build
- Added function
map:filter
- Added function
map:of-pairs
- Added function
map:pair
- Added function
map:replace
- Added function
map:substitute
- Added function
array:build
- Added function
array:foot
- Added function
array:members
- Added function
array:of-members
- Added function
array:replace
- Added function
array:slice
- Added function
array:split
- Added function
array:trunk