XQuery 4.0

From BaseX Documentation
Revision as of 14:50, 16 November 2023 by Holu (talk | contribs)
Jump to navigation Jump to search

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