Difference between revisions of "XQuery 4.0"

From BaseX Documentation
Jump to navigation Jump to search
Line 113: Line 113:
 
=Maps=
 
=Maps=
  
20 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
+
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>fn:atomic-equal</code></li>
 
 
<li><code>map:build</code></li>
 
<li><code>map:build</code></li>
<li><code>map:contains</code></li>
 
<li><code>map:entries</code></li>
 
<li><code>map:entry</code></li>
 
 
<li><code>map:filter</code></li>
 
<li><code>map:filter</code></li>
<li><code>map:find</code></li>
 
<li><code>map:for-each</code></li>
 
<li><code>map:get</code></li>
 
<li><code>map:keys</code></li>
 
<li><code>map:merge</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:pairs</code></li>
 
<li><code>map:put</code></li>
 
<li><code>map:remove</code></li>
 
 
<li><code>map:replace</code></li>
 
<li><code>map:replace</code></li>
<li><code>map:size</code></li>
 
 
<li><code>map:substitute</code></li>
 
<li><code>map:substitute</code></li>
<li><code>map:values</code></li>
 
 
</ul>
 
</ul>
  
Line 142: Line 128:
 
=Arrays=
 
=Arrays=
  
30 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
+
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
  
 
<ul>
 
<ul>
<li><code>array:append</code></li>
 
 
<li><code>array:build</code></li>
 
<li><code>array:build</code></li>
<li><code>array:empty</code></li>
 
<li><code>array:exists</code></li>
 
<li><code>array:filter</code></li>
 
<li><code>array:flatten</code></li>
 
<li><code>array:fold-left</code></li>
 
<li><code>array:fold-right</code></li>
 
 
<li><code>array:foot</code></li>
 
<li><code>array:foot</code></li>
<li><code>array:for-each</code></li>
 
<li><code>array:for-each-pair</code></li>
 
<li><code>array:get</code></li>
 
<li><code>array:head</code></li>
 
<li><code>array:index-where</code></li>
 
<li><code>array:insert-before</code></li>
 
<li><code>array:join</code></li>
 
 
<li><code>array:members</code></li>
 
<li><code>array:members</code></li>
 
<li><code>array:of-members</code></li>
 
<li><code>array:of-members</code></li>
<li><code>array:put</code></li>
 
<li><code>array:remove</code></li>
 
 
<li><code>array:replace</code></li>
 
<li><code>array:replace</code></li>
<li><code>array:reverse</code></li>
 
<li><code>array:size</code></li>
 
 
<li><code>array:slice</code></li>
 
<li><code>array:slice</code></li>
<li><code>array:sort</code></li>
 
 
<li><code>array:split</code></li>
 
<li><code>array:split</code></li>
<li><code>array:subarray</code></li>
 
<li><code>array:tail</code></li>
 
 
<li><code>array:trunk</code></li>
 
<li><code>array:trunk</code></li>
<li><code>array:values</code></li>
+
</ul>
 +
 
 +
1 array function has been updated:
 +
 
 +
<ul>
 +
<li><li><code>array:subarray</code></li></li>
 
</ul>
 
</ul>
  
Line 183: Line 153:
 
;Version 11.0
 
;Version 11.0
  
* Added {{Code|otherwise}} operator
+
* Added operator {{Code|otherwise}}  
 +
* Added map function <code>map:build</code>
 +
* Added map function <code>map:filter</code>
 +
* Added map function <code>map:of-pairs</code>
 +
* Added map function <code>map:pair</code>
 +
* Added map function <code>map:replace</code>
 +
* Added map function <code>map:substitute</code>
 +
* Added array function <code>array:build</code>
 +
* Added array function <code>array:foot</code>
 +
* Added array function <code>array:members</code>
 +
* Added array function <code>array:of-members</code>
 +
* Added array function <code>array:replace</code>
 +
* Added array function <code>array:slice</code>
 +
* Added array function <code>array:split</code>
 +
* Added array function <code>array:trunk</code>

Revision as of 21:35, 14 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

$a otherwise $b

… is equivalent to …

if(exists($a)) then $a else $b

Braced if, optional else

if($a) { $b } else { $c }

if($a) { if($b) { $c } }

Arrow map operator

"The cat sat on the mat" => tokenize() =!> concat(".") =!> upper-case() => string-join(" ")

Numeric literals

1_048_576

0xFC00

0b111000

Abbreviated function syntax

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)

let $inc := fn { . + 1 } return $inc(99)

fn:filter($integers, fn { . > 5 })

fn:iterate-while($number, fn { . < 100 }, fn { . * . })

Optional arguments

declare function strings:get( $value, $default := "EMPTY" ) { $value otherwise $default } strings:get('john')

Keyword arguments

declare function coordinates( $x := 0, $y := 0 ) { map { "x" : $x, "y" : $y } } coordinates(y := 123)

String templates

`Name: { $name }, { $age }`

… is equivalent to …

"Name: " || $name || ", " || $age

… or …

``[Name: `{ $name }`, `{ $age }`]``

Union node tests

/xml/child::(a|b)

/xml/element::(c|d)

Compact lookup syntax

$address?$name, $city?"city code"

… is equivalent to …

$address?($name), $city?("city code")

Maps

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

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

Version 11.0
  • Added operator otherwise
  • Added map function map:build
  • Added map function map:filter
  • Added map function map:of-pairs
  • Added map function map:pair
  • Added map function map:replace
  • Added map function map:substitute
  • Added array function array:build
  • Added array function array:foot
  • Added array function array:members
  • Added array function array:of-members
  • Added array function array:replace
  • Added array function array:slice
  • Added array function array:split
  • Added array function array:trunk