Difference between revisions of "XQuery 4.0"
(Created page with "This article is part of the XQuery Portal. It provides a summary of the most important features of the [https://qt4cg.org/specifications/xpath-functions-40/Overview...") |
|||
| (4 intermediate revisions by the same user not shown) | |||
| Line 29: | Line 29: | ||
=Arrow map operator= | =Arrow map operator= | ||
| − | <p> | + | <p style="white-space: pre-wrap;padding: 1em; border: 1px solid #eaecf0; background-color: #f8f9fa; color: #000; font-family: monospace;">"The cat sat on the mat" |
| − | + | => tokenize() | |
| − | "The cat sat on the mat" | + | <span style="color:#C00000">=!></span> concat(".") |
| − | => tokenize() | + | <span style="color:#C00000">=!></span> upper-case() |
| − | <span style="color:#C00000">=!></span> concat(".") | + | => string-join(" ") |
| − | <span style="color:#C00000">=!></span> upper-case() | ||
| − | => string-join(" ") | ||
| − | |||
</p> | </p> | ||
| Line 60: | Line 57: | ||
<p><code>fn:iterate-while($number, <span style="color:#C00000">fn { . </span> < 100 <span style="color:#C00000">}</span>, <span style="color:#C00000">fn { . </span> * <span style="color:#C00000">. }</span>)</code></p> | <p><code>fn:iterate-while($number, <span style="color:#C00000">fn { . </span> < 100 <span style="color:#C00000">}</span>, <span style="color:#C00000">fn { . </span> * <span style="color:#C00000">. }</span>)</code></p> | ||
| + | |||
| + | =Optional arguments= | ||
| + | |||
| + | <p style="white-space: pre-wrap;padding: 1em; border: 1px solid #eaecf0; background-color: #f8f9fa; color: #000; font-family: monospace;">declare function strings:get( | ||
| + | $value, | ||
| + | $default <span style="color:#C00000">:= "EMPTY"</span> | ||
| + | ) { | ||
| + | $value otherwise $default | ||
| + | } | ||
| + | strings:get('john') | ||
| + | </p> | ||
| + | |||
| + | =Keyword arguments= | ||
| + | |||
| + | <p style="white-space: pre-wrap;padding: 1em; border: 1px solid #eaecf0; background-color: #f8f9fa; color: #000; font-family: monospace;">declare function coordinates( | ||
| + | $x := 0, | ||
| + | $y := 0 | ||
| + | ) { | ||
| + | map { "x" : $x, "y" : $y } | ||
| + | } | ||
| + | coordinates(<span style="color:#C00000">y :=</span> 123) | ||
| + | </p> | ||
| + | |||
| + | =String templates= | ||
| + | |||
| + | <p><code><span style="color:#C00000">`</span>Name: <span style="color:#C00000">{</span> $name <span style="color:#C00000">}</span>, <span style="color:#C00000">{</span> $age <span style="color:#C00000">}`</span> | ||
| + | </code></p> | ||
| + | |||
| + | … is equivalent to … | ||
| + | |||
| + | <p><code>"Name: " || $name || ", " || $age</code></p> | ||
| + | |||
| + | … or … | ||
| + | |||
| + | <p><code>``[Name: `{ $name }`, `{ $age }`]``</code></p> | ||
| + | |||
| + | =Union node tests= | ||
| + | |||
| + | <p><code>/xml/child::<span style="color:#C00000">(a|b)</span></code></p> | ||
| + | |||
| + | <p><code>/xml/element::<span style="color:#C00000">(c|d)</span></code></p> | ||
| + | |||
| + | =Compact lookup syntax= | ||
| + | |||
| + | <p style="white-space: pre-wrap;padding: 1em; border: 1px solid #eaecf0; background-color: #f8f9fa; color: #000; font-family: monospace;">$address<span style="color:#C00000">?$name</span>, | ||
| + | $city<span style="color:#C00000">?"city code"</span> | ||
| + | </p> | ||
| + | |||
| + | … is equivalent to … | ||
| + | |||
| + | <p style="white-space: pre-wrap;padding: 1em; border: 1px solid #eaecf0; background-color: #f8f9fa; color: #000; font-family: monospace;">$address?($name), | ||
| + | $city?("city code") | ||
| + | </p> | ||
=Maps= | =Maps= | ||
| − | + | 6 new map functions have been added in [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#maps XPath and XQuery Functions and Operators 4.0], namely | |
<ul> | <ul> | ||
| − | |||
<li><code>map:build</code></li> | <li><code>map:build</code></li> | ||
| − | |||
| − | |||
| − | |||
<li><code>map:filter</code></li> | <li><code>map:filter</code></li> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
<li><code>map:of-pairs</code></li> | <li><code>map:of-pairs</code></li> | ||
<li><code>map:pair</code></li> | <li><code>map:pair</code></li> | ||
| − | |||
| − | |||
| − | |||
<li><code>map:replace</code></li> | <li><code>map:replace</code></li> | ||
| − | |||
<li><code>map:substitute</code></li> | <li><code>map:substitute</code></li> | ||
| − | |||
</ul> | </ul> | ||
| Line 92: | Line 128: | ||
=Arrays= | =Arrays= | ||
| − | + | 8 new array functions have been added in [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#array XPath and XQuery Functions and Operators 4.0], namely | |
| + | |||
| + | * [[Array_Module#array:build|{{Code|array:build}}]] | ||
| + | * [[Array_Module#array:foot|{{Code|array:foot}}]] | ||
| + | * <code>array:members</code> | ||
| + | * <code>array:of-members</code> | ||
| + | * <code>array:replace</code> | ||
| + | * <code>array:slice</code> | ||
| + | * <code>array:split</code> | ||
| + | * <code>array:trunk</code></li> | ||
| + | |||
| + | 1 array function has been updated: | ||
<ul> | <ul> | ||
| − | <li> | + | <li><li><code>array:subarray</code></li></li> |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | <li><code>array:subarray</code></li | ||
| − | |||
| − | |||
| − | |||
</ul> | </ul> | ||
| Line 133: | Line 151: | ||
;Version 11.0 | ;Version 11.0 | ||
| − | * Added {{Code|otherwise}} | + | * Added operator {{Code|otherwise}} |
| + | * Added function <code>map:build</code> | ||
| + | * Added function <code>map:filter</code> | ||
| + | * Added function <code>map:of-pairs</code> | ||
| + | * Added function <code>map:pair</code> | ||
| + | * Added function <code>map:replace</code> | ||
| + | * Added function <code>map:substitute</code> | ||
| + | * Added function [[Array_Module#array:build|{{Code|array:build}}]] | ||
| + | * Added function [[Array_Module#array:foot|{{Code|array:foot}}]] | ||
| + | * Added function <code>array:members</code> | ||
| + | * Added function <code>array:of-members</code> | ||
| + | * Added function <code>array:replace</code> | ||
| + | * Added function <code>array:slice</code> | ||
| + | * Added function <code>array:split</code> | ||
| + | * Added function <code>array:trunk</code> | ||
Latest revision as of 15:35, 16 November 2023
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.
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:buildmap:filtermap:of-pairsmap:pairmap:replacemap: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:buildarray:footarray:membersarray:of-membersarray:replacearray:slicearray:splitarray: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