Standard Functions
This page presents all functions of
XQuery in the standard function namespace. Functions that have recently been added or changed in XQuery 4.0 are marked as such in their descriptions.
All functions and errors are in the
http://www.w3.org/2005/xpath-functions namespace, to which the
fn prefix is statically bound.
Some functions require
permissions:
fn:available-environment-variables,
fn:environment-variable,
fn:load-xquery-module and
fn:put require
admin permissions. Functions that retrieve external resources, such as
fn:doc,
fn:collection,
fn:csv-doc,
fn:html-doc,
fn:json-doc,
fn:transform and
fn:unparsed-text, require
create permissions, or
read permissions if the resource is a database.
| Signature | fn:empty( $input as item()*) as xs:boolean |
|---|
| Summary | Returns true if $input is an empty sequence. |
|---|
| Examples | empty(()) Result: true() |
|---|
| Signature | fn:exists( $input as item()*) as xs:boolean |
|---|
| Summary | Returns true if $input contains at least one item. |
|---|
| Examples | exists(1 to 10) Result: true() |
|---|
| Signature | fn:foot( $input as item()*) as item()? |
|---|
| Summary | Returns the last item of $input. Equivalent to $input[last()]. |
|---|
| Examples | foot(reverse(1 to 100)) Result: 1 |
|---|
| Signature | fn:head( $input as item()*) as item()? |
|---|
| Summary | Returns the first item of $input. Equivalent to $input[1]. |
|---|
| Examples | head(1 to 100) Result: 1 |
|---|
| Signature | fn:identity( $input as item()*) as item()* |
|---|
| Summary | Returns $input unchanged. This function isn’t useful on its own, but can be used as an argument to other higher-order functions. |
|---|
| Examples | let $sort := sort(?, (), identity#1)
let $reverse-sort := sort(?, (), fn($x) { -$x })
return string-join((
$sort((1, 5, 3, 2, 4)),
'|',
$reverse-sort((1, 5, 3, 2, 4))
)) Result: '12345|54321'
map:for-each({ 1: 'one', 2: 'two' }, identity#1) Result: 1, 2. map:for-each invokes the supplied function with the key and value of every entry of the supplied map. As identity#1 takes only the first argument (the second argument is ignored, see calling higher-order functions) the result is the sequence of keys of the map. |
|---|
| Signature | fn:insert-before( $input as item()*, $position as xs:integer, $insert as item()*) as item()* |
|---|
| Summary | Inserts $insert into $input before the item at the given $position. Positions before the first and after the last item are adjusted to the respective end of the sequence. |
|---|
| Examples | insert-before(1 to 3, 2, 'x') Result: 1, 'x', 2, 3 |
|---|
Updated: Renamed (before: fn:sequence-join).
| Signature | fn:insert-separator( $input as item()*, $separator as item()*) as item()* |
|---|
| Summary | Inserts a $separator between each item of $input. Equivalent to:
head($input), tail($input) ! ($separator, .)
|
|---|
| Examples | (1 to 3)
=> insert-separator('|')
=> string-join() Result: '1|2|3'
insert-separator((<_>1</_>, <_>2</_>, <_>3</_>), '; ') Inserts semicolon strings between the three input items. |
|---|
| Signature | fn:items-at( $input as item()*, $at as xs:integer*) as item()* |
|---|
| Summary | Returns the items from $input at the positions specified with $at in the given order. Equivalent to:
for $pos in $at
return $input[$pos]
|
|---|
| Examples | items-at(reverse(1 to 5), 1) Result: 5
items-at(('one', 'two'), (2, 1)) Result: 'two', 'one'
items-at(('a', 'b'), 0) Result: () |
|---|
| Signature | fn:remove( $input as item()*, $positions as xs:integer*) as item()* |
|---|
| Summary | Returns a new version of $input that excludes the items at the specified $positions. |
|---|
| Examples | remove(1 to 3, 2) Result: 1, 3
remove(1 to 5, (5, 3, 1)) Result: 2, 4 |
|---|
| Signature | fn:replicate( $input as item()*, $count as xs:nonNegativeInteger) as item()* |
|---|
| Summary | Evaluates $input and returns the result $count times. |
|---|
| Examples | replicate('A', 3) Result: 'A', 'A', 'A'
let $nodes := replicate(<node/>, 2)
return $nodes[1] is $nodes[2]
true is returned, as two instances of the same node are returned. |
|---|
| Signature | fn:reverse( $input as item()*) as item()* |
|---|
| Summary | Returns the items of $input in reverse order. |
|---|
| Examples | reverse(1 to 5) Result: 5, 4, 3, 2, 1 |
|---|
| Signature | fn:slice( $input as item()*, $start as xs:integer? := (), $end as xs:integer? := (), $step as xs:integer? := ()) as item()* |
|---|
| Summary | Returns a new version of $input starting from $start and ending at $end, using the specified $step:
- If no start is specified, the sequence will start with the first item.
- If no end is specified, all remaining items are returned.
- If end is smaller than start, the items are returned in reverse order.
- If a negative start or end is specified, the counter starts from the end of the sequence.
|
|---|
| Examples | slice(1 to 5, 3) Result: 3, 4, 5
slice(1 to 5, 3, 4) Result: 3, 4
slice(1 to 10, -3) Result: 8, 9, 10
slice(1 to 5, 4, 2) Result: 4, 3, 2
slice(1 to 5, step := 2) Result: 1, 3, 5 |
|---|
| Signature | fn:subsequence( $input as item()*, $start as xs:numeric, $length as xs:numeric? := ()) as item()* |
|---|
| Summary | Returns the items of $input starting at the position $start, and at most $length items. Positions outside the range of the sequence are ignored. If $length is omitted or empty, all remaining items are returned. |
|---|
| Examples | subsequence(1 to 10, 8) Result: 8, 9, 10
subsequence(1 to 10, 3, 2) Result: 3, 4
subsequence(1 to 10, -1, 4) Result: 1, 2. Requested positions -1 to 2, of which only 1 and 2 exist. |
|---|
| Signature | fn:tail( $input as item()*) as item()* |
|---|
| Summary | Returns all items of $input except for the first one. Equivalent to $input[position() > 1]. |
|---|
| Examples | tail(1 to 4) Result: 2, 3, 4 |
|---|
| Signature | fn:trunk( $input as item()*) as item()* |
|---|
| Summary | Returns all items of $input except for the last one. Equivalent to $input[position() < last()]. |
|---|
| Examples | trunk(reverse(1 to 4)) Result: 4, 3, 2 |
|---|
| Signature | fn:unordered( $input as item()*) as item()* |
|---|
| Summary | Returns the items of $input in an implementation-dependent order. BaseX returns the sequence unchanged. |
|---|
| Examples | unordered(1 to 3) Result: 1, 2, 3 |
|---|
| Signature | fn:void( $input as item()* := ()) as empty-sequence() |
|---|
| Summary | Absorbs $input and returns an empty sequence. This function is helpful if some (often nondeterministic or side-effecting) code needs to be evaluated but the resulting value is not required. |
|---|
| Examples | void(fetch:binary('http://my.rest.service')) Performs an HTTP request and ignores the result. |
|---|
| Signature | fn:atomic-equal( $value1 as xs:anyAtomicType, $value2 as xs:anyAtomicType) as xs:boolean |
|---|
| Summary | Determines whether the atomic values $value1 and $value2 are equal. |
|---|
| Examples | atomic-equal(1, 1.0) Result: true()
atomic-equal('a', xs:anyURI('a')) Result: true()
atomic-equal(xs:double('NaN'), xs:double('NaN')) Result: true()
atomic-equal(1, '1') Result: false() |
|---|
| Signature | fn:compare( $value1 as xs:anyAtomicType?, $value2 as xs:anyAtomicType?, $collation as xs:string? := fn:default-collation()) as xs:integer? |
|---|
| Summary | Returns -1, 0, or 1, depending on whether $value1 is less than, equal to, or greater than $value2, and using the specified $collation for strings. |
|---|
| Examples | compare(1, 1.0) Result: 0
compare(xs:double('NaN'), 0) Result: -1
compare('a', 'A') Result: 1
compare(
'Strasse',
'Straße',
collation({ 'lang': 'de', 'strength': 'primary' })
) Result: 0
compare(xs:hexBinary('41'), xs:base64Binary('QQ==')) Result: 0 |
|---|
| Signature | fn:contains-subsequence( $input as item()*, $subsequence as item()*, $compare as (fn($a, $b) as xs:boolean)? := fn:deep-equal#2) as xs:boolean |
|---|
| Summary | Determines whether $input contains $subsequence, using the $compare function to compare items. |
|---|
| Examples | contains-subsequence(1 to 10, 4 to 6) Result: true()
contains-subsequence(
('anna', 'berta', 'clara', 'dora'),
('CLARA', 'DORA'),
fn($a, $b) { $a = lower-case($b) }
) Result: true() |
|---|
Updated: Diagnostics via the debug option.
| Signature | fn:deep-equal( $input1 as item()*, $input2 as item()*, $options as (xs:string | map(*))? := { 'collation': default-collation() }) as xs:boolean |
|---|
| Summary | Determines if $input1 and $input2 are deep-equal. The $options can be either a string, denoting a collation, or an options map:
| option | default | description |
|---|
base-uri | false() | Consider base-uri of nodes. | collation | default-collation() | Collation to be used. | comments | false() | Consider comments. | debug | false() | If the result is false(), output the items that were found to be different (see Debugging). | id-property | false() | Consider id property of elements and attributes. | idrefs-property | false() | Consider idrefs property of elements and attributes. | ignore-empty-entries | false() | Ignore map entries and array members whose value is an empty sequence. | in-scope-namespaces | false() | Consider in-scope namespaces. | items-equal | void#0 | Custom function to compare items. If an empty sequence is returned, the standard comparison is applied. | map-order | false() | Consider the order of map entries. | namespace-prefixes | false() | Consider prefixes in QNames. | nilled-property | false() | Consider nilled property of elements and attributes. | normalization-form | () | Applies Unicode normalization to strings. Allowed values are NFC, NFD, NFKC, NFKD and FULLY-NORMALIZED. | ordered | true() | Considers the top-level order of the input sequences. | processing-instructions | false() | Consider processing instructions. | timezones | false() | Consider timezones in time/date values. | unordered-elements | () | A list of QNames of elements considered whose child elements may appear in any order. | whitespace | preserve | Handling of whitespace:
preserve: Compare strings unchanged.strip: Ignore whitespace-only text nodes.normalize: Normalize whitespace; ignore whitespace-only text nodes.
|
As BaseX is not schema-aware, all nodes have the same type annotations, and typed values are equal to string values. The options typed-values, type-annotations and type-variety are accepted and ignored.
|
|---|
| Examples | deep-equal((), ()) Result: true()
deep-equal(1, 1.0) Result: true()
deep-equal(
<name sex='f' id='name1'>Sunita</name>,
<name id="name1" sex="f">Sunita</name>
) Result: true(). Attributes have no order, different quotes make no difference.
deep-equal((1, 2, 3), (3, 2, 1), { 'ordered': false() }) Result: true()
deep-equal('X', ' X ', { 'whitespace': 'normalize' }) Result: true()
deep-equal(sum#1, sum#2, {
'items-equal': fn($a, $b) {
if(($a, $b) instance of fn(*)*) {
function-name($a) = function-name($b)
}
}
}) Result: true(). When comparing functions, only the function name is considered, but not the arity. |
|---|
| Signature | fn:distinct-values( $values as xs:anyAtomicType*, $collation as xs:string? := fn:default-collation()) as xs:anyAtomicType* |
|---|
| Summary | Returns the atomic items of $values with duplicates removed. Strings are compared with the specified $collation, and NaN is equal to itself. The first occurrence of each value is retained: unlike in XQuery 3.1, the order of the result is prescribed. |
|---|
| Examples | distinct-values((1, 2, 2, 3, 1)) Result: 1, 2, 3
distinct-values((2, 2.0e0, 2.0)) Result: 2. Numeric values of different types are compared by value. |
|---|
| Signature | fn:duplicate-values( $values as xs:anyAtomicType*, $collation as xs:string? := fn:default-collation()) as xs:anyAtomicType* |
|---|
| Summary | Returns all values that appear for the second time in $values. If no $collation is specified, the function is similar to:
for $group in $values
group by $value := $group
where count($group) > 1
return $value
|
|---|
| Examples | duplicate-values((1, 2, 3, 1.0, 1e0)) Result: 1
duplicate-values(1 to 100) Result: ()
let $ids := duplicate-values(//@id)
where exists($ids)
return error((), 'Duplicate IDs found: ' || string-join($ids, ', ')) Raises an error for duplicates in a sequence. |
|---|
| Signature | fn:ends-with-subsequence( $input as item()*, $subsequence as item()*, $compare as (fn($a, $b) as xs:boolean)? := fn:deep-equal#2) as xs:boolean |
|---|
| Summary | Determines whether $input ends with $subsequence, using the $compare function to compare items. |
|---|
| Examples | ends-with-subsequence(1 to 10, 8 to 10) Result: true()
ends-with-subsequence(
('one', 'two', 'three'),
('t', 't'),
starts-with#2
) Result: true() |
|---|
| Signature | fn:index-of( $input as xs:anyAtomicType*, $target as xs:anyAtomicType, $collation as xs:string? := fn:default-collation()) as xs:integer* |
|---|
| Summary | Returns the positions of all items of $input that are equal to $target. Strings are compared with the specified $collation, and NaN is equal to itself. |
|---|
| Examples | index-of((10, 20, 30, 20), 20) Result: 2, 4 |
|---|
| Signature | fn:starts-with-subsequence( $input as item()*, $subsequence as item()*, $compare as (fn($a, $b) as xs:boolean)? := fn:deep-equal#2) as xs:boolean |
|---|
| Summary | Determines whether $input starts with $subsequence, using the $compare function to compare items. |
|---|
| Examples | starts-with-subsequence(1 to 10, 1 to 3) Result: true()
starts-with-subsequence(
1 to 10,
('a', 'bb', 'ccc'),
fn($a, $b) { $a = string-length($b) }
) Result: true() |
|---|
| Signature | fn:exactly-one( $input as item()*) as item() |
|---|
| Summary | Returns $input if it consists of exactly one item, and raises an error otherwise. |
|---|
| Examples | exactly-one(1) Result: 1 |
|---|
| Signature | fn:one-or-more( $input as item()*) as item()+ |
|---|
| Summary | Returns $input if it consists of at least one item, and raises an error otherwise. |
|---|
| Examples | one-or-more(1 to 3) Result: 1, 2, 3 |
|---|
| Signature | fn:zero-or-one( $input as item()*) as item()? |
|---|
| Summary | Returns $input if it consists of at most one item, and raises an error otherwise. |
|---|
| Examples | zero-or-one(()) Result: () |
|---|
| Signature | fn:count( $input as item()*) as xs:integer |
|---|
| Summary | Returns the number of items in $input. |
|---|
| Examples | count(1 to 10) Result: 10 |
|---|
| Signature | fn:all-equal( $values as xs:anyAtomicType*, $collation as xs:string? := fn:default-collation()) as xs:boolean |
|---|
| Summary | Returns true if all items in $values are equal, using the specified $collation for string comparisons. |
|---|
| Examples | all-equal((1, 1.0, 1e0)) Result: true()
all-equal((1, '1')) Result: false()
all-equal(()) Result: true() |
|---|
| Signature | fn:all-different( $values as xs:anyAtomicType*, $collation as xs:string? := fn:default-collation()) as xs:boolean |
|---|
| Summary | Returns true if all items in $values are distinct, using the specified $collation for string comparisons. |
|---|
| Examples | all-different(1 to 5) Result: true()
all-different(()) Result: true() |
|---|
| Signature | fn:avg( $values as xs:anyAtomicType*) as xs:anyAtomicType? |
|---|
| Summary | Returns the average of the atomic items in $values, or an empty sequence if $values is empty. |
|---|
| Examples | avg(1 to 4) Result: 2.5 |
|---|
| Signature | fn:max( $values as xs:anyAtomicType*, $collation as xs:string? := fn:default-collation()) as xs:anyAtomicType? |
|---|
| Summary | Returns the largest of the atomic items in $values, or an empty sequence if $values is empty. Strings are compared with the specified $collation. Unlike in XQuery 3.1, integers and decimals are no longer converted to doubles; the result keeps the type of the input items. |
|---|
| Examples | max(1 to 10) Result: 10
max(('Kafka', 'Camus', 'Tawada')) Result: 'Tawada' |
|---|
| Signature | fn:min( $values as xs:anyAtomicType*, $collation as xs:string? := fn:default-collation()) as xs:anyAtomicType? |
|---|
| Summary | Returns the smallest of the atomic items in $values, or an empty sequence if $values is empty. Strings are compared with the specified $collation. Unlike in XQuery 3.1, integers and decimals are no longer converted to doubles; the result keeps the type of the input items. |
|---|
| Examples | min((3, 1.5, 2)) Result: 1.5 |
|---|
| Signature | fn:sum( $values as xs:anyAtomicType*, $zero as xs:anyAtomicType? := 0) as xs:anyAtomicType? |
|---|
| Summary | Returns the sum of the atomic items in $values. If $values is empty, $zero is returned. |
|---|
| Examples | sum(1 to 100) Result: 5050
sum((), ()) Result: () |
|---|
| Signature | fn:apply( $function as fn(*), $arguments as array(*)) as item()* |
|---|
| Summary | The supplied $function is invoked with the specified $arguments. The arity of the function must be less than or equal to the size of the array. |
|---|
| Examples | apply(concat#5, array { 1 to 5 }) Result: '12345'
apply(fn($a) { sum($a) }, [ 1 to 5 ]) Result: 15
apply(substring#3, [ "abc", 2 ]) Raises an error as the array has only two members. |
|---|
| Signature | fn:do-until( $input as item()*, $action as fn($value as item()*, $pos as xs:integer) as item()*, $predicate as fn($value as item()*, $pos as xs:integer) as xs:boolean?) as item()* |
|---|
| Summary | This function provides a way to write functionally clean and interruptible iterations, commonly known as do while/until loops:
$action is called with $input and the result is adopted as new $input.$predicate is called with $input. If the result is false, step 1 is repeated.- Otherwise,
$input is returned.
|
|---|
| Examples | do-until(
(),
fn($value, $pos) { $value, $pos * $pos },
fn($value) { foot($value) > 50 }
) Result: 1, 4, 9, 16, 25, 36, 49, 64. The loop is interrupted once the last value of the generated sequence is greater than 50.
do-until(
(1, 0),
fn($value) { $value[1] + $value[2], $value },
fn($value) { avg($value) > 10 }
) Result: 55, 34, 21, 13, 8, 5, 3, 2, 1, 1, 0. The computation is continued as long as the average of the first Fibonacci numbers is smaller than 10. |
|---|
| Signature | fn:every( $input as item()*, $predicate as (fn($item, $pos) as xs:boolean)? := fn:boolean#1) as xs:boolean |
|---|
| Summary | Returns true if every item in $input matches $predicate. If no predicate is specified, the boolean value of the item will be checked. |
|---|
| Examples | every(1 to 5) Result: true()
every(1 to 5, fn { . > 3 }) Result: false()
every(()) Result: true() |
|---|
| Signature | fn:filter( $input as item()*, $predicate as fn($item as item(), $pos as xs:integer) as xs:boolean?) as item()* |
|---|
| Summary | Applies the boolean $predicate to all items of the sequence $input, returning those for which it returns true(). The function can easily be implemented with fn:for-each:
declare function filter($input, $pred) {
for-each(
$input,
fn($item) { if ($pred($item)) { $item } }
)
};
An equivalent XQuery function is:
declare function filter(
$input as item()*,
$predicate as fn(item()) as xs:boolean?
) as item()* {
$input[$predicate(.)]
};
|
|---|
| Examples | filter(1 to 10, fn { . mod 2 eq 0 }) Result: 2, 4, 6, 8, 10. Returns all even integers until 10.
let $first-upper := fn($str) {
let $first := substring($str, 1, 1)
return $first eq upper-case($first)
}
return filter(('FooBar', 'foo', 'BAR'), $first-upper) Result: 'FooBar', 'BAR'. Returns strings that start with an upper-case letter.
let $is-prime := fn($x) {
$x gt 1 and (every $y in 2 to ($x - 1) satisfies $x mod $y != 0)
}
return filter(1 to 20, $is-prime) Result: 2, 3, 5, 7, 11, 13, 17, 19. An inefficient prime number generator. |
|---|
| Signature | fn:fold-left( $input as item()*, $init as item()*, $action as fn($value as item()*, $item as item(), $pos as xs:int) as item()*) as item()* |
|---|
| Summary | The left fold traverses the $input from the left. The query fold-left(1 to 5, 0, $f), for example, would be evaluated as:
$f($f($f($f($f(0, 1), 2), 3), 4), 5)
An equivalent XQuery function is:
declare function fold-left(
$input as item()*,
$init as item()*,
$action as fn(item()*, item()) as item()*
) as item()* {
if (empty($input)) then $init
else fold-left(
tail($input),
$action($init, head($input)),
$action
)
};
Note: Contrary to the official specification, the current position of the iteration can be retrieved via the third parameter of the higher-order function argument.
|
|---|
| Examples | fold-left(1 to 5, 1, fn($result, $curr) { $result * $curr }) Result: 120. Computes the product of a sequence of integers.
fold-left(1 to 5, '$seed',
concat('$f(', ?, ', ', ?, ')')
) Illustrates the evaluation order and returns $f($f($f($f($f($seed, 1), 2), 3), 4), 5).
let $from-digits := fold-left(?, 0,
fn($n, $d) { 10 * $n + $d }
)
return (
$from-digits(1 to 5),
$from-digits((4, 2))
) Result: 12345, 42. Builds a decimal number from digits.
fold-left(
1 to 10000000000,
1,
fn($n, $curr) { if($n > 100000) then $n else $n * $curr }
) Result: 362880. Once the condition is met, further calculations are skipped. |
|---|
| Signature | fn:fold-right( $input as item()*, $init as item()*, $action as fn($item as item(), $value as item()*, $pos as xs:int) as item()*) as item()* |
|---|
| Summary | The right fold traverses the $input from the right. The query fold-right(1 to 5, 0, $f), for example, would be evaluated as:
$f(1, $f(2, $f(3, $f(4, $f(5, 0)))))
Note that the order of the arguments of $fun are inverted compared to that in fn:fold-left:
declare function fold-right(
$input as item()*,
$init as item()*,
$action as fn(item(), item()*) as item()*
) as item()* {
if (empty($input)) then $init
else $action(
head($input),
fold-right(tail($input), $init, $action)
)
};
Note: Contrary to the official specification, the current position of the iteration can be retrieved via the third parameter of the higher-order function argument.
|
|---|
| Examples | fold-right(1 to 5, 1,
fn($curr, $result) { $result * $curr }
) Result: 120. Computes the product of a sequence of integers.
fold-right(1 to 5, '$seed',
concat('$f(', ?, ', ', ?, ')')
) Illustrates the evaluation order and $f(1, $f(2, $f(3, $f(4, $f(5, $seed))))).
let $reverse := fold-right(?, (), fn($item, $rev) { $rev, $item })
return $reverse(1 to 5) Result: 5, 4, 3, 2, 1. Reverses a sequence of items. |
|---|
| Signature | fn:for-each( $input as item()*, $action as fn($item as item(), $pos as xs:integer) as item()*) as item()* |
|---|
| Summary | Applies the specified $action to every item of $input and returns all results as a single sequence.
An equivalent XQuery function is:
declare function for-each(
$input as item()*,
$action as fn(item()) as item()*
) as item()* {
for $item in $input
return $action($item)
}
|
|---|
| Examples | for-each(1 to 10, math:pow(?, 2)) Result: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100. Computes the square of all numbers from 1 to 10.
let $fs := (
upper-case#1,
substring(?, 4),
string-length#1
)
return for-each($fs, fn($f) { $f('foobar') }) Result: 'FOOBAR', 'bar', 6. Applies a list of functions to a string.
("one", "two", "three") => for-each(upper-case(?)) Result: 'ONE', 'TWO', 'THREE'. Processes each item of a sequence with the arrow operator. |
|---|
| Signature | fn:for-each-pair( $input1 as item()*, $input2 as item()*, $action as fn($a as item(), $b as item(), $pos as xs:integer) as item()*) as item()* |
|---|
| Summary | Applies the specified $action to the successive pairs of items of $input1 and $input2. Evaluation is stopped if one sequence yields no more items.
An equivalent function is:
declare function for-each-pair(
$input1 as item()*,
$input2 as item()*,
$action as fn(item(), item()) as item()*
) as item()* {
for $pos in 1 to min((count($input1), count($input2)))
return $action($input1[$pos], $input2[$pos])
};
|
|---|
| Examples | for-each-pair(
for-each(1 to 10, fn { . mod 2 }),
replicate(1, 5),
fn($a, $b) { $a + $b }
) Result: 2, 1, 2, 1, 2. Adds one to the numbers at odd positions.
let $number-words := fn($str) {
string-join(
for-each-pair(
1 to 1000000000,
tokenize($str, ' +'),
concat(?, ': ', ?)
),
', '
)
}
return $number-words('how are you?') Result: '1: how, 2: are, 3: you?'
let $is-sorted := fn($input) {
every $b in
for-each-pair(
$input,
tail($input),
fn($a, $b) { $a <= $b }
)
satisfies $b
}
return (
$is-sorted(1 to 10),
$is-sorted((1, 2, 42, 4, 5))
) Result: true(), false(). Checks if a sequence is sorted. |
|---|
| Signature | fn:highest( $input as item()*, $collation as xs:string? := fn:default-collation(), $key as (fn(item()) as xs:anyAtomicType*)? := fn:data#1) as item()* |
|---|
| Summary | Returns those items from $input for which $key produces the highest value, using the specified $collation for strings. |
|---|
| Examples | highest(8 to 12) Result: 12
highest(98 to 102, key := string#1) Result: 99
highest(1 to 7, (), fn { . idiv 3 }) Result: 6, 7 |
|---|
| Signature | fn:index-where( $input as item()*, $predicate as fn($item as item(), $pos as xs:integer) as xs:boolean?) as xs:integer* |
|---|
| Summary | Returns the positions of all items of $input that match the $predicate function. |
|---|
| Examples | index-where(
(10, 11, 12, 14, 17, 21, 26),
fn { . mod 2 = 0 }
) Result: 1, 3, 4, 7
index-where(
(1, 8, 2, 7, 3),
fn($item, $pos) { $item < 5 and $pos > 2 }
) Result: 3, 5 |
|---|
| Signature | fn:lowest( $input as item()*, $collation as xs:string? := fn:default-collation(), $key as (fn(item()) as xs:anyAtomicType*)? := fn:data#1) as item()* |
|---|
| Summary | Returns those items from $input for which $key produces the lowest value, using the specified $collation for strings. |
|---|
| Examples | lowest(8 to 12) Result: 8
lowest(98 to 102, key := string#1) Result: 100
lowest(1 to 7, (), fn { . idiv 3 }) Result: 1, 2 |
|---|
| Signature | fn:partial-apply( $function as fn(*), $arguments as map(xs:positiveInteger, item()*)) as fn(*) |
|---|
| Summary | Returns a function with selected arguments of $function pre-bound to values in $arguments. The keys in the map denote 1-based positions of the arguments to bind. |
|---|
| Examples | let $char-at := partial-apply(substring#3, { 3: 1 })
return $char-at("abc", 2) Result: 'b' |
|---|
| Signature | fn:partition( $input as item()*, $split-when as fn($group, $next, $pos) as xs:boolean?) as array(item()*)* |
|---|
| Summary | Partitions the $input into a sequence of non-empty arrays, starting a new partition when $split-when is true for a tested item. |
|---|
| Examples | partition((1 to 5), fn($seq) { count($seq) = 2 }) Result: [ 1, 2 ], [ 3, 4 ], [ 5 ]
partition(
('Anita', 'Anne', 'Barbara', 'Catherine', 'Christine'),
fn($partition, $next) {
substring(head($partition), 1, 1) ne substring($next, 1, 1)
}
) The result:[ 'Anita', 'Anne' ],
[ 'Barbara' ],
[ 'Catherine', 'Christine' ]
|
|---|
| Signature | fn:some( $input as item()*, $predicate as (fn($item, $pos) as xs:boolean)? := fn:boolean#1) as xs:boolean |
|---|
| Summary | Returns true if some items in $input match $predicate. If no predicate is specified, the boolean value of the item will be checked. |
|---|
| Examples | some(-3 to 3) Result: true()
some(1 to 5, fn { . > 3 }) Result: true()
some(()) Result: false() |
|---|
| Signature | fn:sort( $input as item()*, $collation as xs:string? := fn:default-collation(), $key as fn($item as item()) as xs:anyAtomicType* := fn:data#1) as item()* |
|---|
| Summary | Returns a new sequence with sorted $input items. A $collation and a $key can be supplied, which will be applied to each sort item. The items resulting from the sort key will be sorted using the semantics of the lt operator. |
|---|
| Examples | sort(reverse(1 to 3)) Result: 1, 2, 3
reverse(sort(1 to 3)) Result: 3, 2, 1
sort((-2, 1, 3), key := abs#1) Result: 1, -2, 3
sort($employees, (), fn { @name, @age }) Sorts employees by their name and age.
sort((1, 'a')) Raises an error because strings and integers cannot be compared. |
|---|
| Signature | fn:sort-by( $input as item()*, $keys as map(*)*) as item()* |
|---|
| Summary | Returns a new sequence with sorted $input items, matching the order of the sort $keys.
| option | default | description |
|---|
key | fn:data#1 | Sort function. | collation | | Collation URI. | order | 'ascending' | Order (ascending, descending) |
|
|---|
| Examples | sort-by((-2, 1, 3), { 'key': abs#1 }) Result: 1, -2, 3
sort-by(1 to 3, { 'order': 'descending' }) Result: 3, 2, 1 |
|---|
| Signature | fn:sort-with( $input as item()*, $comparators as (fn($a as item(), $b as item()) as xs:integer)+) as item()* |
|---|
| Summary | Returns a new sequence of $input with the order induced by the supplied $comparators. |
|---|
| Examples | sort-with((1, 4, 6, 5, 3), compare#2) Result: 1, 3, 4, 5, 6
sort-with(
(1, -2, 5, 10, -12, 8),
fn($a, $b) { abs($a) - abs($b) }
) Result: 1, -2, 5, 8, 10, -12
let $persons := <persons>
<person name='Josipa' age='8'/>
<person name='Jade' age='6'/>
<person name='Jie' age='8'/>
</persons>
return sort-with($persons/person, (
fn($a, $b) { compare($a/@age, $b/@age) },
fn($a, $b) { compare($a/@name, $b/@name) }
)) The result:<person name="Jade" age="6"/>,
<person name="Jie" age="8"/>,
<person name="Josipa" age="8"/>
|
|---|
| Signature | fn:subsequence-where( $input as item()*, $from as (fn($item as item(), $pos as xs:int) as xs:boolean)? := true#0, $to as (fn($item as item(), $pos as xs:int) as xs:boolean)? := false#0) as item()* |
|---|
| Summary | Returns a subsequence of $input starting with the first item that matches $from, and ending with the first subsequent item that matches $to.
The function is equivalent to:
let $start := index-where($input, $from)[1]
otherwise (count($input) + 1)
let $end := index-where($input, $to)[. ge $start][1]
otherwise (count($input) + 1)
return slice($input, $start, $end)
|
|---|
| Examples | subsequence-where(1 to 5, fn { . >= 3 }) Result: 3, 4, 5
subsequence-where(1 to 5, fn { . >= 2 }, fn { . >= 4 }) Result: 2, 3, 4
let $drop-while := fn($input, $predicate) {
subsequence-where($input, fn { not($predicate(.)) })
}
return $drop-while(1 to 5, fn { . <= 2 }) Result: 3, 4, 5. The function can be used to emulate the nonexisting drop-while function. |
|---|
| Signature | fn:take-while( $input as item()*, $predicate as fn($item as item(), $pos as xs:integer) as xs:boolean?) as item()* |
|---|
| Summary | Returns items of $input as long as $predicate is satisfied. The predicate is called with the current item and position.
The function is equivalent to:
declare function take-while($input, $predicate, $pos := 1) {
if(exists($input) and $predicate(head($input), $pos)) {
head($input),
take-while(tail($input), $predicate, $pos + 1)
}
};
|
|---|
| Examples | take-while((1, 5, 10, 20, 50, 100), fn { . <= 30 }) Returns all integers until a value is larger than 30.
take-while(
(1 to 100) ! random:integer(50),
fn($item, $pos) { . >= 10 }
) Computes at most 100 random integers, but stops if an integer is smaller than 10. |
|---|
| Signature | fn:transitive-closure( $node as gnode()?, $step as fn($current as gnode()) as gnode()*) as gnode()* |
|---|
| Summary | Computes the transitive closure of $node by applying $step to each unchecked node and returns all the nodes except for the input node. |
|---|
| Examples | let $nodes := <xml>
<node id='0'/>
<node id='1' idref='0'/>
<node id='2' idref='1'/>
<node id='3' idref='1'/>
</xml>/node
return transitive-closure(
head($nodes),
fn($n) { $nodes[@idref = $n/@id] }
) The result:<node id='1' idref='0'/>,
<node id='2' idref='1'/>,
<node id='3' idref='1'/>
|
|---|
| Signature | fn:while-do( $input as item()*, $predicate as fn($value as item()*, $pos as xs:integer) as xs:boolean?, $action as fn($value as item()*, $pos as xs:integer) as item()*) as item()* |
|---|
| Summary | This function provides a way to write functionally clean and interruptible iterations, commonly known as while loops:
$predicate is called with $input.- If the result is
true, $action is called with $input, the result is adopted as new $input, and step 2 is repeated. - Otherwise,
$input is returned.
|
|---|
| Examples | while-do(2, fn { . <= 100 }, fn { . * . }) Result: 256. The loop is interrupted as soon as the computed product is greater than 100.
while-do(
1,
fn($num, $pos) { $pos <= 10 },
fn($num, $pos) { $num * $pos }
) Result: 3628800. Returns the factorial of 10, i.e., the product of all integers from 1 to 10.
let $input := (0 to 4, 6 to 10)
return while-do(
0,
fn($n) { $n = $input },
fn($n) { $n + 1 }
) Result: 5. Returns the first positive number missing in a sequence.
let $input := 3936256
return while-do(
$input,
fn($result) { abs($result * $result - $input) >= 0.0000000001 },
fn($guess) { ($guess + $input div $guess) div 2 }
) => round(5) Result: 1984. Computes the square root of a number. |
|---|
| Signature | fn:true() as xs:boolean |
|---|
| Summary | Returns the boolean value true. |
|---|
| Examples | true() Result: true() |
|---|
| Signature | fn:false() as xs:boolean |
|---|
| Summary | Returns the boolean value false. |
|---|
| Examples | false() Result: false() |
|---|
| Signature | fn:boolean( $input as item()*) as xs:boolean |
|---|
| Summary | Returns the effective boolean value of $input. An error is raised if $input is a sequence of more than one item that starts with an atomic item. |
|---|
| Examples | boolean('Kafka') Result: true()
boolean(''), boolean(()) Result: false(), false() |
|---|
| Signature | fn:not( $input as item()*) as xs:boolean |
|---|
| Summary | Returns the negated effective boolean value of $input. |
|---|
| Examples | not(true()) Result: false() |
|---|
| Signature | fn:divide-decimals( $value as xs:decimal, $divisor as xs:decimal, $precision as xs:integer? := 0) as record(quotient as xs:decimal, remainder as xs:decimal) |
|---|
| Summary | The function returns the quotient and remainder of a decimal division for the specified $value, the $divisor and an optional $precision. |
|---|
| Examples | divide-decimals(10, 3) Result: { "quotient": 3, "remainder": 1 }
divide-decimals(10, 7, 3) Result: { "quotient": 1.428, "remainder": 0.004 } |
|---|
| Signature | fn:abs( $value as xs:numeric?) as xs:numeric? |
|---|
| Summary | Returns the absolute value of $value. The type of the result is the same as the type of the argument. |
|---|
| Examples | abs(-3.5) Result: 3.5 |
|---|
| Signature | fn:ceiling( $value as xs:numeric?) as xs:numeric? |
|---|
| Summary | Returns the smallest number that is not less than $value and has no fractional part. |
|---|
| Examples | ceiling(2.1) Result: 3 |
|---|
| Signature | fn:floor( $value as xs:numeric?) as xs:numeric? |
|---|
| Summary | Returns the largest number that is not greater than $value and has no fractional part. |
|---|
| Examples | floor(2.9) Result: 2 |
|---|
| Signature | fn:round( $value as xs:numeric?, $precision as xs:integer? := 0, $mode as xs:string? := 'half-to-ceiling') as xs:numeric? |
|---|
| Summary | Rounds a $value to a specified number of decimal places, using the specified $precision and $mode.
Allowed values for $mode are: floor, ceiling, toward-zero, away-from-zero, half-to-floor, half-to-ceiling, half-toward-zero, half-away-from-zero, and half-to-even. |
|---|
| Examples | round(1.5) Result: 2.0
round(15, -1) Result: 20
round(9.9999, 1, 'floor') Result: 9.9 |
|---|
| Signature | fn:round-half-to-even( $value as xs:numeric?, $precision as xs:integer? := 0) as xs:numeric? |
|---|
| Summary | Rounds $value to the number of decimal places specified by $precision. If the value is exactly halfway between two candidates, the candidate with an even last digit is chosen. A negative $precision rounds to a power of ten. |
|---|
| Examples | round-half-to-even(2.5), round-half-to-even(3.5) Result: 2, 4. Both results are even.
round-half-to-even(12345, -2) Result: 12300 |
|---|
| Signature | fn:is-NaN( $value as xs:anyAtomicType) as xs:boolean |
|---|
| Summary | Returns true if the argument is the xs:float or xs:double value NaN. |
|---|
| Examples | is-NaN(0e0 div 0) Result: true()
is-NaN('NaN') Result: false() |
|---|
| Signature | fn:number( $value as xs:anyAtomicType? := .) as xs:double |
|---|
| Summary | Converts $value to a double. NaN is returned if the conversion fails or if $value is an empty sequence. |
|---|
| Examples | number('3.5') Result: 3.5e0
number('Kafka') Result: NaN |
|---|
| Signature | fn:parse-integer( $value as xs:string?, $radix as xs:integer? := 10) as xs:integer? |
|---|
| Summary | Converts $value to an integer, using the supplied $radix in the range 2 to 36. The input may be positive or negative and can contain whitespace and underscore separators. |
|---|
| Examples | parse-integer('7B', 16) Result: 123
parse-integer('11111111', 2) Result: 255
parse-integer(' -1_000_000 ') Result: -1000000 |
|---|
| Signature | fn:format-integer( $value as xs:integer?, $picture as xs:string, $language as xs:string? := ()) as xs:string |
|---|
| Summary | Converts $value to a string, using the supplied $picture and (optionally) $language. |
|---|
| Examples | format-integer(123, '0') Result: '123'
format-integer(12, 'w') Result: 'twelve'
format-integer(21, 'Ww;o', 'de') Result: 'Einundzwanzigste'
format-integer(65535, '16^xxxx') Result: 'ffff'
format-integer(15, '2^xxxx') Result: '1111' |
|---|
| Signature | fn:format-number( $value as xs:numeric?, $picture as xs:string, $options as (xs:string | map(*))? := ()) as xs:string |
|---|
| Summary | Converts $value to a string, using the supplied $picture and $options. The options argument can be the name of a statically available decimal-format or a set of options. |
|---|
| Examples | format-number(123, '0') Result: '123'
format-number(1.23, '0,0##', 'de') Result: '1,23'
format-number(1234, "0.000,0", { 'format-name': 'de' }) Result: '1.234,0'
format-number(1010, '0^0', { 'exponent-separator': '^' }) Result: '1^3'
format-number(1984.42, '00.0e0') Result: '19.8e2' |
|---|
| Signature | fn:random-number-generator( $seed as xs:anyAtomicType? := ()) as fn:random-number-generator-record |
|---|
| Summary | Creates a random number generator, using an optional seed. The returned map contains three entries:
number is a random double between 0 and 1next is a function that returns another random number generatorpermute is a function that returns a random permutation of its argument
The returned random generator is deterministic: If the function is called twice with the same arguments and in the same execution scope, it will always return the same result.
|
|---|
| Examples | let $rng := random-number-generator()
let $number := $rng?number
let $next-rng := $rng?next()
let $next-number := $next-rng?number
let $permutation := $rng?permute(1 to 5)
return ($number, $next-number, $permutation)
|
|---|
| Signature | fn:codepoints-to-string( $values as xs:integer*) as xs:string |
|---|
| Summary | Converts the Unicode codepoints in $values to a string. Each codepoint must be a valid XML character. |
|---|
| Examples | codepoints-to-string((72, 101, 108, 108, 111)) Result: 'Hello' |
|---|
| Signature | fn:string-to-codepoints( $value as xs:string?) as xs:integer* |
|---|
| Summary | Returns the Unicode codepoints of $value. |
|---|
| Examples | string-to-codepoints('AB') Result: 65, 66 |
|---|
| Signature | fn:codepoint-equal( $value1 as xs:string?, $value2 as xs:string?) as xs:boolean? |
|---|
| Summary | Returns true if $value1 and $value2 contain the same codepoints. No collation is applied, and no Unicode normalization takes place. An empty sequence is returned if one of the arguments is empty. |
|---|
| Examples | codepoint-equal('Käthe', 'Ka' || char(0x308) || 'the') Result: false(). Precomposed ä and a + combining diaeresis are different codepoints, see fn:normalize-unicode. |
|---|
| Signature | fn:collation( $options as map(*)) as xs:string |
|---|
| Summary | Generates a collation URI with the specified $options. Depending on the availability of ICU, the returned collation will either use the standard or the ICU collation features (see Collations for more details). |
|---|
| Examples | collation({ 'language': 'de' }) Result: "http://basex.org/collation?language=de". Returned without ICU.
collation({ 'language': 'de' }) Result: "http://www.w3.org/2013/collation/UCA?language=de". Returned with ICU embedded. |
|---|
| Signature | fn:collation-available( $collation as xs:string) as xs:boolean |
|---|
| Summary | Checks if the specified $collation is supported. |
|---|
| Signature | fn:collation-key( $value as xs:string, $collation as xs:string? := fn:default-collation()) as xs:base64Binary |
|---|
| Summary | Returns a binary item for $value, using the supplied $collation, which can be used for unambiguous and context-free comparisons. |
|---|
| Examples | for value $v in map:build(
('a', 'A', 'b'),
collation-key(?, collation({ 'strength': 'primary' })),
identity#1
)
return [ $v ] The result:[ "b" ]
[ ("a", "A") ]
|
|---|
| Signature | fn:contains-token( $value as xs:string*, $token as xs:string, $collation as xs:string? := fn:default-collation()) as xs:boolean |
|---|
| Summary | The supplied strings will be tokenized at whitespace boundaries. The function returns true if one of the strings equals the supplied token, possibly under the rules of a supplied collation. |
|---|
| Examples | contains-token(('a', 'b c', 'd'), 'c') Result: true() |
|---|
| Signature | fn:char( $value as (xs:string | xs:positiveInteger)) as xs:string |
|---|
| Summary | Returns a single-character string for the specified $value, which can be:
|
|---|
| Examples | char(65), char(0x41), char(0b01000001) Result: 'A', 'A', 'A'
char('xcirc') Result: '◯'
string-join(('auml', 'ouml', 'uuml', 'szlig') ! char(.)) Result: 'äöüß'
string-to-codepoints(char('\t')) Result: 9 |
|---|
| Signature | fn:characters( $value as xs:string?) as xs:string* |
|---|
| Summary | Returns the single characters of $value as a string sequence. Equivalent to:
for $cp in string-to-codepoints($value)
return codepoints-to-string($cp)
|
|---|
| Examples | characters('AB') Result: 'A', 'B' |
|---|
Added: New function.
| Signature | fn:graphemes( $value as xs:string?) as xs:string* |
|---|
| Summary | Splits $value into a sequence of strings, each containing a single extended grapheme cluster as defined by UAX #29. Returns an empty sequence if $value is empty or the empty sequence. |
|---|
| Examples | graphemes("a" || char(0x308) || "b") Result: "a" || char(0x308), "b". I.e., a + ◌̈ + b, three characters, two graphemes.
graphemes(char(0x1F476) || char(0x200D) || char(0x1F6D1)) Result: char(0x1F476) || char(0x200D) || char(0x1F6D1). I.e., 👶 + ZWJ + 🛑: three characters, one grapheme.
graphemes(char('\r') || char('\n')) Result: char('\r') || char('\n'). I.e., CR + LF: two characters, one grapheme. |
|---|
| Signature | fn:concat( $values... as xs:anyAtomicType*) as xs:string |
|---|
| Summary | Concatenates the string representations of the supplied $values. Unlike in XQuery 3.1, the function accepts any number of arguments, and each argument may be a sequence. |
|---|
| Examples | concat('Gerhard', ' ', 'Richter') Result: 'Gerhard Richter'
concat(1 to 3) Result: '123'. A single argument with three items.
concat() Result: '' |
|---|
| Signature | fn:string-join( $values as xs:anyAtomicType*, $separator as xs:string? := '') as xs:string |
|---|
| Summary | Creates a string by concatenating the supplied $values, optionally interspersed by a $separator. |
|---|
| Examples | string-join(1 to 3) Result: '123'
string-join(('one', 'two', 'three'), ', ') Result: 'one, two, three' |
|---|
Added: New function.
| Signature | fn:pad-string( $value as xs:anyAtomicType?, $length as xs:integer, $options as map(*)? := {}) as xs:string |
|---|
| Summary | Creates a string by extending $value to the requested $length with padding characters. As in fn:string-join, the supplied value is atomized and cast to a string. A value that is already long enough is returned unchanged: the function never truncates.
The following $options are available:
padding: string to pad with (default: ' '). It is repeated as often as required and cut to fit; it must not be empty.side: side on which the padding is added: end (default), start or both. With both, an odd padding character is appended at the end.
|
|---|
| Examples | pad-string('abc', 6) Result: 'abc '
pad-string('abc', 6, { 'side': 'start' }) Result: ' abc'
pad-string(42, 6, { 'padding': '0', 'side': 'start' }) Result: '000042'
pad-string('Chapter 1', 20, { 'padding': '.' }) Result: 'Chapter 1...........'. Dot leaders in a table of contents.
pad-string('abcdef', 3) Result: 'abcdef'. Padding never truncates. |
|---|
| Signature | fn:substring( $value as xs:string?, $start as xs:numeric, $length as xs:numeric? := ()) as xs:string |
|---|
| Summary | Returns the characters of $value starting at the position $start, and at most $length characters. Positions outside the range of the string are ignored. If $length is omitted or empty, all remaining characters are returned. |
|---|
| Examples | substring('Camus', 2) Result: 'amus'
substring('Camus', 2, 3) Result: 'amu'
substring('Camus', 0, 3) Result: 'Ca'. Requested positions 0 to 2, of which only 1 and 2 exist. |
|---|
| Signature | fn:string-length( $value as xs:anyAtomicType? := .) as xs:integer |
|---|
| Summary | Returns the number of characters in $value. Unlike in XQuery 3.1, the argument may be any atomic item, which will be cast to a string. |
|---|
| Examples | string-length('Kollwitz') Result: 8
string-length('Ka' || char(0x308) || 'the') Result: 6. Codepoints are counted, not graphemes, see fn:graphemes. |
|---|
| Signature | fn:normalize-space( $value as xs:anyAtomicType? := .) as xs:string |
|---|
| Summary | Removes leading and trailing whitespace from $value and replaces all other sequences of whitespace by a single space. Unlike in XQuery 3.1, the argument may be any atomic item, which will be cast to a string. |
|---|
| Examples | normalize-space(' Mark Rothko ') Result: 'Mark Rothko' |
|---|
| Signature | fn:normalize-unicode( $value as xs:string?, $form as xs:string? := 'NFC') as xs:string |
|---|
| Summary | Converts $value to the Unicode normalization form specified by $form, which can be NFC, NFD, NFKC, NFKD or the empty string. |
|---|
| Examples | normalize-unicode('Ka' || char(0x308) || 'the') eq 'Käthe' Result: true(). The combining diaeresis is composed into a single character. |
|---|
| Signature | fn:upper-case( $value as xs:string?) as xs:string |
|---|
| Summary | Converts all characters of $value to upper case. |
|---|
| Examples | upper-case('Rothko') Result: 'ROTHKO' |
|---|
| Signature | fn:lower-case( $value as xs:string?) as xs:string |
|---|
| Summary | Converts all characters of $value to lower case. |
|---|
| Examples | lower-case('KAFKA') Result: 'kafka' |
|---|
| Signature | fn:translate( $value as xs:string?, $replace as xs:string, $with as xs:string) as xs:string |
|---|
| Summary | Replaces the characters of $value that occur in $replace by the character at the same position in $with. Characters without a counterpart in $with are removed. |
|---|
| Examples | translate('2026-07-28', '-', '/') Result: '2026/07/28' |
|---|
| Signature | fn:hash( $value as (xs:string|xs:hexBinary|xs:base64Binary)?, $algorithm as xs:string? := 'MD5', $options as map(*)? := {}) as xs:hexBinary? |
|---|
| Summary | Computes a hash for the given $value, using the specified $algorithm. The supported algorithms are MD5, SHA-1, SHA-256, BLAKE3, and the cyclic redundancy check CRC-32. The $options have no effect in BaseX. |
|---|
| Examples | string(hash('')) Result: 'D41D8CD98F00B204E9800998ECF8427E'
string(hash('', 'SHA-1')) Result: 'DA39A3EE5E6B4B0D3255BFEF95601890AFD80709'
hash('', 'CRC-32') => string() Result: '00000000'
hash('BaseX', 'CRC-32') => string() Result: '4C06FC7F' |
|---|
| Signature | fn:contains( $value as xs:string?, $substring as xs:string?, $collation as xs:string? := fn:default-collation()) as xs:boolean |
|---|
| Summary | Returns true if $value contains $substring, possibly under the rules of a supplied $collation. |
|---|
| Examples | contains('Yoko Tawada', 'wad') Result: true() |
|---|
| Signature | fn:starts-with( $value as xs:string?, $substring as xs:string?, $collation as xs:string? := fn:default-collation()) as xs:boolean |
|---|
| Summary | Returns true if $value starts with $substring, possibly under the rules of a supplied $collation. |
|---|
| Examples | starts-with('Anselm Neft', 'Anselm') Result: true() |
|---|
| Signature | fn:ends-with( $value as xs:string?, $substring as xs:string?, $collation as xs:string? := fn:default-collation()) as xs:boolean |
|---|
| Summary | Returns true if $value ends with $substring, possibly under the rules of a supplied $collation. |
|---|
| Examples | ends-with('Mark Rothko', 'ko') Result: true() |
|---|
| Signature | fn:substring-before( $value as xs:string?, $substring as xs:string?, $collation as xs:string? := fn:default-collation()) as xs:string |
|---|
| Summary | Returns the characters of $value that precede the first occurrence of $substring, or the empty string if $substring does not occur. |
|---|
| Examples | substring-before('Franz Kafka', ' ') Result: 'Franz' |
|---|
| Signature | fn:substring-after( $value as xs:string?, $substring as xs:string?, $collation as xs:string? := fn:default-collation()) as xs:string |
|---|
| Summary | Returns the characters of $value that follow the first occurrence of $substring, or the empty string if $substring does not occur. |
|---|
| Examples | substring-after('Franz Kafka', ' ') Result: 'Kafka' |
|---|
| Signature | fn:matches( $value as xs:string?, $pattern as xs:string, $flags as xs:string? := '') as xs:boolean |
|---|
| Summary | Returns true if $value matches the regular expression $pattern, using the optional $flags. |
|---|
| Examples | matches('Kafka', '^K') Result: true() |
|---|
| Signature | fn:replace( $value as xs:string?, $pattern as xs:string, $replacement as (xs:string|fn($s, $g) as item()?)? := (), $flags as xs:string? := '') as xs:string |
|---|
| Summary | Searches the regular expression $pattern in $value and performs a $replacement, using optional $flags. The replacement argument can either be a string, or a function that will be invoked with the currently matched string ($s) and the currently captured groups ($g). |
|---|
| Examples | replace('a1c', '\d', 'X') Result: 'aXc'
replace('1aBc2', '[a-z]', 'X', 'i') Result: '1XXX2'
replace('1aBc2', '[a-z]', upper-case#1) Result: '1ABC2'
replace("Chapter 9", "[0-9]+", fn($match) { $match + 1 }) Result: 'Chapter 10'
replace(
"12°34′57″",
"([0-9]+)°([0-9]+)′([0-9]+)″",
fn($full-match, $groups) {
message($full-match),
($groups[1] + $groups[2] ÷ 60 + $groups[3] ÷ 3600) || '°'
}
) Result: '12.5825°'. Creates debugging output for the current match. |
|---|
| Signature | fn:tokenize( $value as xs:string?, $pattern as xs:string? := (), $flags as xs:string? := '') as xs:string* |
|---|
| Summary | Splits $value into several substrings wherever the regular expression $pattern is found, or (if no pattern is supplied) at whitespace boundaries. |
|---|
| Examples | tokenize('a b c') Result: 'a', 'b', 'c'
tokenize('a, b, c', ',\s*') Result: 'a', 'b', 'c'
tokenize('a|b|c', '|', 'q') Result: 'a', 'b', 'c'. Literal pattern search. |
|---|
| Signature | fn:analyze-string( $value as xs:string?, $pattern as xs:string, $flags as xs:string? := '') as element(fn:analyze-string-result) |
|---|
| Summary | Applies the regular expression $pattern to $value, using the optional $flags, and returns an element in which matching and non-matching substrings are marked up. Unlike in XQuery 3.1, the pattern may match a zero-length string. |
|---|
| Examples | analyze-string('Kafka 1924', '\d+') Result: <analyze-string-result xmlns="http://www.w3.org/2005/xpath-functions"><non-match>Kafka </non-match><match>1924</match></analyze-string-result> |
|---|
Added: New function.
| Signature | fn:matching-segments( $value as xs:string?, $pattern as xs:string, $flags as xs:string? := '') as fn:matching-segment-record* |
|---|
| Summary | Applies the regular expression $pattern to $value, using optional $flags, and returns one record for each match. Each record contains the matched substring, its 1-based position within the input, and a map of all captured groups. A group is keyed by its group number, or, if it is a named capturing group ((?<name>…)), by its name. |
|---|
| Examples | matching-segments("The cat sat on the mat.", "\w+")?substring Result: 'The', 'cat', 'sat', 'on', 'the', 'mat'
matching-segments(
"08-12-03",
"^(\d+)\-(\d+)\-(\d+)$")?groups ! (?1?group, ?2?group, ?3?group
) Result: '08', '12', '03'
matching-segments("Chapter 5", "(Chapter|Appendix)(?=\s+([0-9]+))")?groups?2 Result: { "group": "5", "position": 9 }. Groups captured inside a lookahead are included in the result.
matching-segments(
"2026-06-25",
"(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})"
)?groups?year?group Result: '2026'. A named capturing group is keyed by its name instead of its group number. |
|---|
| Signature | fn:regex( $pattern as xs:string, $flags as xs:string? := '') as fn:compiled-regex-record |
|---|
| Summary | Compiles the regular expression $pattern with the optional $flags and returns a record whose fields provide the regular expression operations for the compiled pattern. Next to the pattern and flags strings, the record supplies the functions matches, tokenize, replace, analyze-string and matching-segments. Compiling a pattern once and applying it repeatedly is faster than passing the pattern to each single function call. |
|---|
| Examples | let $re := regex('\d+')
return $re?matches('Kafka 1924') Result: true()
let $re := regex(',\s*')
return $re?tokenize('Kafka, Camus, Tawada') Result: 'Kafka', 'Camus', 'Tawada' |
|---|
| Signature | fn:decode-from-uri( $value as xs:string?) as xs:string |
|---|
| Summary | Decodes URI-escaped characters in $value. |
|---|
| Examples | decode-from-uri('S%C3%A3o%20Paulo%3F') Result: 'São Paulo?'
decode-from-uri('%00') Result: `�`. Invalid characters are replaced with the Unicode replacement character FFFD. |
|---|
| Signature | fn:encode-for-uri( $value as xs:string?) as xs:string |
|---|
| Summary | Escapes characters in $value for use in a URI. |
|---|
| Examples | encode-for-uri('São Paulo?') Result: 'S%C3%A3o%20Paulo%3F'
encode-for-uri('ABC123-~._ !"#<=>?') Result: `ABC123-~._%20%21%22%23%3C%3D%3E%3F` |
|---|
| Signature | fn:escape-html-uri( $value as xs:string?) as xs:string |
|---|
| Summary | Escapes all characters of $value that cannot be written directly in a URI, using the rules that HTML user agents apply to attributes such as href. Unlike fn:iri-to-uri, reserved ASCII characters, including spaces, are left untouched. |
|---|
| Examples | escape-html-uri('http://basex.org/Käthe Kollwitz') Result: 'http://basex.org/K%C3%A4the Kollwitz' |
|---|
| Signature | fn:iri-to-uri( $value as xs:string?) as xs:string |
|---|
| Summary | Converts the IRI $value to a URI by escaping all characters that are not permitted in a URI. |
|---|
| Examples | iri-to-uri('http://basex.org/Käthe Kollwitz') Result: 'http://basex.org/K%C3%A4the%20Kollwitz'. Unlike fn:escape-html-uri, the space is escaped as well. |
|---|
| Signature | fn:resolve-uri( $href as xs:string?, $base as xs:string? := ()) as xs:anyURI? |
|---|
| Summary | Resolves the relative URI $href against $base, or against the static base URI of the query if $base is omitted or empty. |
|---|
| Examples | resolve-uri('b.xml', 'http://basex.org/a/') Result: 'http://basex.org/a/b.xml' |
|---|
| Signature | fn:parse-uri( $value as xs:string?, $options as map(*)? := {}) as fn:uri-structure-record? |
|---|
| Summary |
Parses the supplied URI string and returns a map with its constituent components.
For a full description of behavior and the $options, see fn:parse-uri.
|
|---|
| Examples | parse-uri("https://basex.org/download/") The result:{
"uri": "https://basex.org/download/",
"scheme": "https",
"hierarchical": true(),
"authority": "basex.org",
"host": "basex.org",
"path": "/download/",
"path-segments": ("", "download", ""),
"absolute": true()
}
|
|---|
Added: New function.
| Signature | fn:build-uri( $parts as fn:uri-structure-record, $options as map(*) := {}) as xs:string |
|---|
| Summary |
Constructs a URI from the $parts provided.
For a full description of behavior and the $options, see fn:build-uri.
|
|---|
| Examples | build-uri({
"scheme": "https",
"host": "docs.basex.org",
"path": "/main"
}) Result: 'https://docs.basex.org/main' |
|---|
| Signature | fn:years-from-duration( $value as xs:duration?) as xs:integer? |
|---|
| Summary | Returns the years component of $value. |
|---|
| Examples | years-from-duration(xs:yearMonthDuration('P2Y6M')) Result: 2 |
|---|
| Signature | fn:months-from-duration( $value as xs:duration?) as xs:integer? |
|---|
| Summary | Returns the months component of $value. |
|---|
| Examples | months-from-duration(xs:yearMonthDuration('P2Y6M')) Result: 6 |
|---|
| Signature | fn:days-from-duration( $value as xs:duration?) as xs:integer? |
|---|
| Summary | Returns the days component of $value. |
|---|
| Examples | days-from-duration(xs:dayTimeDuration('P3DT4H')) Result: 3 |
|---|
| Signature | fn:hours-from-duration( $value as xs:duration?) as xs:integer? |
|---|
| Summary | Returns the hours component of $value. |
|---|
| Examples | hours-from-duration(xs:dayTimeDuration('P3DT4H')) Result: 4 |
|---|
| Signature | fn:minutes-from-duration( $value as xs:duration?) as xs:integer? |
|---|
| Summary | Returns the minutes component of $value. |
|---|
| Examples | minutes-from-duration(xs:dayTimeDuration('PT90M')) Result: 30. 90 minutes are normalized to 1 hour and 30 minutes. |
|---|
| Signature | fn:seconds-from-duration( $value as xs:duration?) as xs:decimal? |
|---|
| Summary | Returns the seconds component of $value, including fractional seconds. |
|---|
| Examples | seconds-from-duration(xs:dayTimeDuration('PT1.5S')) Result: 1.5 |
|---|
| Signature | fn:seconds( $value as xs:decimal?) as xs:dayTimeDuration? |
|---|
| Summary | Returns a duration for $value, which specifies the number of seconds. |
|---|
| Examples | seconds(0) Result: xs:dayTimeDuration('PT0S')
seconds(86_400.1) Result: xs:dayTimeDuration('P1DT0.1S')
current-time() + seconds(100) Adds 100 seconds to the current time. |
|---|
| Signature | fn:dateTime( $date as xs:date?, $time as xs:time?) as xs:dateTime? |
|---|
| Summary | Combines $date and $time into a single xs:dateTime item. |
|---|
| Examples | dateTime(xs:date('2026-07-28'), xs:time('14:30:00')) Result: 2026-07-28T14:30:00 |
|---|
Added: New function.
| Signature | fn:build-dateTime( $value as fn:dateTime-record?) as (xs:dateTime | xs:date | xs:time | xs:gYear | xs:gYearMonth | xs:gMonth | xs:gMonthDay | xs:gDay)? |
|---|
| Summary | Constructs a Gregorian value from the components of the $value record. |
|---|
| Examples | build-dateTime({
"year": 2026,
"month": 4,
"day": 8,
"hours": 18,
"minutes": 46,
"seconds": 12,
"timezone": xs:dayTimeDuration("PT2H")
}) Result: xs:dateTime("2026-04-08T18:46:12+02:00") |
|---|
| Signature | fn:unix-dateTime( $value as xs:nonNegativeInteger? := 0) as xs:dateTimeStamp |
|---|
| Summary | Converts a Unix timestamp to an xs:dateTimeStamp. |
|---|
| Examples | unix-dateTime(0) Result: xs:dateTime('1970-01-01T00:00:00Z') |
|---|
| Signature | fn:year-from-dateTime( $value as (xs:dateTime | xs:date | xs:time | xs:gYear | xs:gYearMonth | xs:gMonth | xs:gMonthDay | xs:gDay)?) as xs:integer? |
|---|
| Summary | Returns the year component of $value. Unlike in XQuery 3.1, other Gregorian types are accepted as well. |
|---|
| Examples | year-from-dateTime(xs:dateTime('2026-07-28T14:30:15.5')) Result: 2026
year-from-dateTime(xs:gYearMonth('2026-07')) Result: 2026 |
|---|
| Signature | fn:month-from-dateTime( $value as (xs:dateTime | xs:date | xs:time | xs:gYear | xs:gYearMonth | xs:gMonth | xs:gMonthDay | xs:gDay)?) as xs:integer? |
|---|
| Summary | Returns the month component of $value. Unlike in XQuery 3.1, other Gregorian types are accepted as well. |
|---|
| Examples | month-from-dateTime(xs:dateTime('2026-07-28T14:30:15.5')) Result: 7 |
|---|
| Signature | fn:day-from-dateTime( $value as (xs:dateTime | xs:date | xs:time | xs:gYear | xs:gYearMonth | xs:gMonth | xs:gMonthDay | xs:gDay)?) as xs:integer? |
|---|
| Summary | Returns the day component of $value. Unlike in XQuery 3.1, other Gregorian types are accepted as well. |
|---|
| Examples | day-from-dateTime(xs:dateTime('2026-07-28T14:30:15.5')) Result: 28 |
|---|
| Signature | fn:hours-from-dateTime( $value as (xs:dateTime | xs:date | xs:time | xs:gYear | xs:gYearMonth | xs:gMonth | xs:gMonthDay | xs:gDay)?) as xs:integer? |
|---|
| Summary | Returns the hours component of $value. Unlike in XQuery 3.1, other Gregorian types are accepted as well. |
|---|
| Examples | hours-from-dateTime(xs:dateTime('2026-07-28T14:30:15.5')) Result: 14 |
|---|
| Signature | fn:minutes-from-dateTime( $value as (xs:dateTime | xs:date | xs:time | xs:gYear | xs:gYearMonth | xs:gMonth | xs:gMonthDay | xs:gDay)?) as xs:integer? |
|---|
| Summary | Returns the minutes component of $value. Unlike in XQuery 3.1, other Gregorian types are accepted as well. |
|---|
| Examples | minutes-from-dateTime(xs:dateTime('2026-07-28T14:30:15.5')) Result: 30 |
|---|
| Signature | fn:seconds-from-dateTime( $value as (xs:dateTime | xs:date | xs:time | xs:gYear | xs:gYearMonth | xs:gMonth | xs:gMonthDay | xs:gDay)?) as xs:decimal? |
|---|
| Summary | Returns the seconds component of $value, including fractional seconds. Unlike in XQuery 3.1, other Gregorian types are accepted as well. |
|---|
| Examples | seconds-from-dateTime(xs:dateTime('2026-07-28T14:30:15.5')) Result: 15.5 |
|---|
| Signature | fn:timezone-from-dateTime( $value as (xs:dateTime | xs:date | xs:time | xs:gYear | xs:gYearMonth | xs:gMonth | xs:gMonthDay | xs:gDay)?) as xs:dayTimeDuration? |
|---|
| Summary | Returns the timezone component of $value as a duration, or an empty sequence if $value has no timezone. Unlike in XQuery 3.1, other Gregorian types are accepted as well. |
|---|
| Examples | timezone-from-dateTime(xs:dateTime('2026-07-28T14:30:00+02:00')) Result: PT2H |
|---|
| Signature | fn:year-from-date( $value as xs:date?) as xs:integer? |
|---|
| Summary | Returns the year component of $value. |
|---|
| Examples | year-from-date(xs:date('2026-07-28')) Result: 2026 |
|---|
| Signature | fn:month-from-date( $value as xs:date?) as xs:integer? |
|---|
| Summary | Returns the month component of $value. |
|---|
| Examples | month-from-date(xs:date('2026-07-28')) Result: 7 |
|---|
| Signature | fn:day-from-date( $value as xs:date?) as xs:integer? |
|---|
| Summary | Returns the day component of $value. |
|---|
| Examples | day-from-date(xs:date('2026-07-28')) Result: 28 |
|---|
| Signature | fn:timezone-from-date( $value as xs:date?) as xs:dayTimeDuration? |
|---|
| Summary | Returns the timezone component of $value as a duration, or an empty sequence if $value has no timezone. |
|---|
| Examples | timezone-from-date(xs:date('2026-07-28+02:00')) Result: PT2H |
|---|
| Signature | fn:hours-from-time( $value as xs:time?) as xs:integer? |
|---|
| Summary | Returns the hours component of $value. |
|---|
| Examples | hours-from-time(xs:time('14:30:15')) Result: 14 |
|---|
| Signature | fn:minutes-from-time( $value as xs:time?) as xs:integer? |
|---|
| Summary | Returns the minutes component of $value. |
|---|
| Examples | minutes-from-time(xs:time('14:30:15')) Result: 30 |
|---|
| Signature | fn:seconds-from-time( $value as xs:time?) as xs:decimal? |
|---|
| Summary | Returns the seconds component of $value, including fractional seconds. |
|---|
| Examples | seconds-from-time(xs:time('14:30:15')) Result: 15 |
|---|
| Signature | fn:timezone-from-time( $value as xs:time?) as xs:dayTimeDuration? |
|---|
| Summary | Returns the timezone component of $value as a duration, or an empty sequence if $value has no timezone. |
|---|
| Examples | timezone-from-time(xs:time('14:30:00+02:00')) Result: PT2H |
|---|
| Signature | fn:parts-of-dateTime( $value as (xs:dateTime | xs:date | xs:time | xs:gYear | xs:gYearMonth | xs:gMonth | xs:gMonthDay | xs:gDay)?) as fn:dateTime-record? |
|---|
| Summary | Returns the components of a Gregorian value. |
|---|
| Examples | parts-of-dateTime(xs:dateTime('2026-04-08T18:46:12+02:00')) Result: { "year": 2026, "month": 4, "day": 8, "hours": 18, "minutes": 46, "seconds": 12, "timezone": "PT2H"} |
|---|
| Signature | fn:adjust-dateTime-to-timezone( $value as xs:dateTime?, $timezone as xs:dayTimeDuration? := fn:implicit-timezone()) as xs:dateTime? |
|---|
| Summary | Adjusts $value to the specified $timezone. If $timezone is supplied as an empty sequence, the timezone component is removed. |
|---|
| Examples | adjust-dateTime-to-timezone(
xs:dateTime('2026-07-28T14:30:00+02:00'),
xs:dayTimeDuration('PT0S')
) Result: 2026-07-28T12:30:00Z |
|---|
| Signature | fn:adjust-date-to-timezone( $value as xs:date?, $timezone as xs:dayTimeDuration? := fn:implicit-timezone()) as xs:date? |
|---|
| Summary | Adjusts $value to the specified $timezone. If $timezone is supplied as an empty sequence, the timezone component is removed. |
|---|
| Examples | adjust-date-to-timezone(xs:date('2026-07-28'), xs:dayTimeDuration('PT2H')) Result: 2026-07-28+02:00
adjust-date-to-timezone(xs:date('2026-07-28+02:00'), ()) Result: 2026-07-28 |
|---|
| Signature | fn:adjust-time-to-timezone( $value as xs:time?, $timezone as xs:dayTimeDuration? := fn:implicit-timezone()) as xs:time? |
|---|
| Summary | Adjusts $value to the specified $timezone. If $timezone is supplied as an empty sequence, the timezone component is removed. |
|---|
| Examples | adjust-time-to-timezone(
xs:time('14:30:00+02:00'),
xs:dayTimeDuration('-PT5H')
) Result: 07:30:00-05:00 |
|---|
| Signature | fn:civil-timezone( $value as xs:dateTime, $place as xs:string? := ()) as xs:dayTimeDuration |
|---|
| Summary | Returns the timezone offset for a given date/time $value and $place. If no place is specified, the system’s default place is used. |
|---|
| Examples | civil-timezone(xs:dateTime('2001-01-01T11:11:11Z')) Result: xs:dayTimeDuration('PT1H'). Returned when being executed in Germany.
civil-timezone(xs:dateTime('2001-07-01T11:11:11Z')) Result: xs:dayTimeDuration('PT2H'). Returned when being executed in Germany.
let $dt := xs:dateTime('2024-07-01T01:01:01Z')
return adjust-dateTime-to-timezone($dt, civil-timezone($dt)) Result: xs:dateTime('2024-07-01T03:01:01+02:00'). Returned when being executed in Germany.
civil-timezone(xs:dateTime('2024-12-24T12:24:48'), 'Africa/Abidjan') Result: xs:dayTimeDuration('PT0S') |
|---|
| Signature | fn:format-dateTime( $value as xs:dateTime?, $picture as xs:string, $language as xs:string? := (), $calendar as xs:string? := (), $place as xs:string? := ()) as xs:string? |
|---|
| Summary | Converts $value to a string, using the supplied $picture and (optionally) $language, $calendar and $place. Unlike in XQuery 3.1, the last three arguments can be omitted individually. |
|---|
| Examples | format-dateTime(xs:dateTime('2026-07-28T14:30:15.5'), '[H01]:[m01]') Result: '14:30' |
|---|
| Signature | fn:format-date( $value as xs:date?, $picture as xs:string, $language as xs:string? := (), $calendar as xs:string? := (), $place as xs:string? := ()) as xs:string? |
|---|
| Summary | Converts $value to a string, using the supplied $picture and (optionally) $language, $calendar and $place. Unlike in XQuery 3.1, the last three arguments can be omitted individually. |
|---|
| Examples | format-date(xs:date('2026-07-28'), '[D1] [MNn] [Y]') Result: '28 July 2026'
format-date(xs:date('2026-07-28'), '[D1]. [MNn] [Y]', 'de') Result: '28. Juli 2026' |
|---|
| Signature | fn:format-time( $value as xs:time?, $picture as xs:string, $language as xs:string? := (), $calendar as xs:string? := (), $place as xs:string? := ()) as xs:string? |
|---|
| Summary | Converts $value to a string, using the supplied $picture and (optionally) $language, $calendar and $place. Unlike in XQuery 3.1, the last three arguments can be omitted individually. |
|---|
| Examples | format-time(xs:time('14:30:00'), '[h].[m01] [PN]') Result: '2.30 PM' |
|---|
| Signature | fn:parse-ietf-date( $value as xs:string?) as xs:dateTime? |
|---|
| Summary | Parses a string in the IETF format (which is widely used on the Internet) and returns an xs:dateTime item: |
|---|
| Examples | parse-ietf-date('28-Feb-1984 07:07:07') Result: xs:dateTime('1984-02-28T07:07:07Z')
parse-ietf-date('Wed, 01 Jun 2001 23:45:54 +02:00') Result: xs:dateTime('2001-06-01T23:45:54+02:00') |
|---|
| Signature | fn:QName( $uri as xs:string?, $qname as xs:string) as xs:QName |
|---|
| Summary | Creates a QName from $uri and the lexical QName $qname, which may include a prefix. |
|---|
| Examples | QName('http://basex.org/', 'p:a') Result: p:a |
|---|
| Signature | fn:parse-QName( $value as xs:string?) as xs:QName? |
|---|
| Summary | Converts $value to a QName. The supplied string can be a local name, have a namespace prefix, or use the braced URI syntax. |
|---|
| Examples | parse-QName('xml:node') => namespace-uri-from-QName() Result: 'http://www.w3.org/XML/1998/namespace'
let $qname := parse-QName('Q{http://gotcha.org/works}fine')
return string-join((
namespace-uri-from-QName($qname),
local-name-from-QName($qname)
), ': ') Result: 'http://gotcha.org/works: fine' |
|---|
| Signature | fn:resolve-QName( $value as xs:string?, $element as element()) as xs:QName? |
|---|
| Summary | Creates a QName from the lexical QName $value, resolving its prefix against the namespaces that are in scope for $element. |
|---|
| Examples | resolve-QName('p:a', <e xmlns:p='http://basex.org/'/>) Result: p:a |
|---|
| Signature | fn:prefix-from-QName( $value as xs:QName?) as xs:NCName? |
|---|
| Summary | Returns the prefix of $value, or an empty sequence if the QName has no prefix. |
|---|
| Examples | prefix-from-QName(QName('http://basex.org/', 'p:a')) Result: 'p' |
|---|
| Signature | fn:local-name-from-QName( $value as xs:QName?) as xs:NCName? |
|---|
| Summary | Returns the local name of $value. |
|---|
| Examples | local-name-from-QName(QName('http://basex.org/', 'p:a')) Result: 'a' |
|---|
| Signature | fn:namespace-uri-from-QName( $value as xs:QName?) as xs:anyURI? |
|---|
| Summary | Returns the namespace URI of $value, or the empty string if the QName is in no namespace. |
|---|
| Examples | namespace-uri-from-QName(QName('http://basex.org/', 'p:a')) Result: 'http://basex.org/' |
|---|
| Signature | fn:expanded-QName( $value as xs:QName?) as xs:string? |
|---|
| Summary | Returns a string representation of the QName $value in the format Q{uri}local. |
|---|
| Examples | expanded-QName(xs:QName('country')) Result: 'Q{}country'
expanded-QName(QName('http://eat.org/lunch', 'cake')) Result: 'Q{http://eat.org/lunch}cake' |
|---|
| Signature | fn:base-uri( $node as node()? := .) as xs:anyURI? |
|---|
| Summary | Returns the base URI of $node, or an empty sequence if no base URI is available. |
|---|
| Examples | base-uri(<a xml:base='http://basex.org/'/>) Result: 'http://basex.org/' |
|---|
| Signature | fn:document-uri( $node as node()? := .) as xs:anyURI? |
|---|
| Summary | Returns the URI of the document node $node, or an empty sequence if the node is no document node or has no URI. |
|---|
| Examples | document-uri(document { <a/> }) Result: (). A constructed document has no URI. |
|---|
| Signature | fn:nilled( $node as node()? := .) as xs:boolean? |
|---|
| Summary | Returns true if $node is an element that was validated against a schema and marked as nilled. An empty sequence is returned if $node is no element. |
|---|
| Examples | nilled(<a/>) Result: false() |
|---|
| Signature | fn:node-name( $node as node()? := .) as xs:QName? |
|---|
| Summary | Returns the name of $node as a QName, or an empty sequence if the node has no name. |
|---|
| Examples | node-name(<xml/>) Result: xml |
|---|
| Signature | fn:string( $value as item()? := .) as xs:string |
|---|
| Summary | Returns the string value of $value. If $value is an empty sequence, the empty string is returned. |
|---|
| Examples | string(<a>Kafka</a>) Result: 'Kafka' |
|---|
| Signature | fn:data( $input as item()* := .) as xs:anyAtomicType* |
|---|
| Summary | Returns the atomized value of $input: nodes are replaced by their typed values, and atomic items are returned unchanged. |
|---|
| Examples | data(<a>1</a>) Result: 1. The result is an xs:untypedAtomic item. |
|---|
| Signature | fn:has-children( $node as gnode()? := .) as xs:boolean |
|---|
| Summary | Returns true if $node has one or more child nodes. |
|---|
| Examples | has-children(<a><b/></a>) Result: true() |
|---|
| Signature | fn:in-scope-namespaces( $element as element()) as map((xs:NCName | enum('')), xs:anyURI) |
|---|
| Summary | Returns the in-scope namespaces of $element as a map. |
|---|
| Examples | in-scope-namespaces(<xsi:a/>) The result:{
"xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xml": "http://www.w3.org/XML/1998/namespace"
}
|
|---|
| Signature | fn:in-scope-prefixes( $element as element()) as xs:string* |
|---|
| Summary | Returns the namespace prefixes that are in scope for $element. |
|---|
| Examples | in-scope-prefixes(<a xmlns:p='http://basex.org/'/>) Result: 'p', 'xml' |
|---|
| Signature | fn:lang( $language as xs:string?, $node as node()? := .) as xs:boolean |
|---|
| Summary | Returns true if $node has an xml:lang attribute whose value equals $language, or starts with $language followed by a hyphen. |
|---|
| Examples | lang('en', <a xml:lang='en-US'/>) Result: true() |
|---|
| Signature | fn:local-name( $node as node()? := .) as xs:string |
|---|
| Summary | Returns the local name of $node, or the empty string if the node has no name. |
|---|
| Examples | local-name(<p:a xmlns:p='http://basex.org/'/>) Result: 'a' |
|---|
| Signature | fn:name( $node as node()? := .) as xs:string |
|---|
| Summary | Returns the name of $node, including its prefix, or the empty string if the node has no name. |
|---|
| Examples | name(<p:a xmlns:p='http://basex.org/'/>) Result: 'p:a' |
|---|
| Signature | fn:namespace-uri( $node as node()? := .) as xs:anyURI |
|---|
| Summary | Returns the namespace URI of $node, or the empty string if the node is in no namespace. |
|---|
| Examples | namespace-uri(<p:a xmlns:p='http://basex.org/'/>) Result: 'http://basex.org/' |
|---|
| Signature | fn:namespace-uri-for-prefix( $value as xs:string?, $element as element()) as xs:anyURI? |
|---|
| Summary | Returns the namespace URI that is bound to the prefix $value in the scope of $element, or an empty sequence if the prefix is not bound. |
|---|
| Examples | namespace-uri-for-prefix('p', <a xmlns:p='http://basex.org/'/>) Result: 'http://basex.org/' |
|---|
| Signature | fn:path( $node as gnode()? := ., $options as map(*)? := {}) as xs:string? |
|---|
| Summary | Returns a string that can be used as path expression to select the supplied $node, using the specified $options:
| option | default | description |
|---|
origin | () | If present, the returned path will be relative to this origin node. | lexical | false() | If enabled, fn:name() will be used to serialize node names. | namespaces | {} | A map with prefixes and namespace URIs. If a prefix is used for a namespace, it is used instead of the Q{URI} syntax when serializing nodes names. | indexes | true() | By default, the index positions of nodes are included in the string. |
|
|---|
| Examples | let $xml := document { <xml><a/></xml> }
return path($xml/xml/a, { 'indexes': false() }) Result: '/Q{}xml/Q{}a'
let $xml := document {
<xml xmlns='URI'><a/></xml>
}
let $namespaces := in-scope-namespaces($xml/*)
return path($xml/*:xml/*:a, { 'namespaces': $namespaces }) Result: '/xml[1]/a[1]' |
|---|
| Signature | fn:root( $node as gnode()? := .) as gnode()? |
|---|
| Summary | Returns the root of the tree that contains $node. |
|---|
| Examples | root(<a><b><c/></b></a>/b) Result: <a><b><c/></b></a> |
|---|
| Signature | fn:siblings( $node as gnode()? := .) as gnode()* |
|---|
| Summary | Returns the siblings of a $node, including the node itself. |
|---|
| Examples | siblings(<xml><a/><b/><c/></xml>/b) Result: <a/>, <b/>, <c/> |
|---|
| Signature | fn:distinct-ordered-nodes( $nodes as gnode()*) as gnode()* |
|---|
| Summary | Returns nodes in distinct document order: duplicate nodes (nodes with the same node identity) are removed, and the remaining nodes are returned in document order. This function makes explicit what the path expression does before returning the result of a node traversal. It is equivalent to expressions like:
$nodes/self::node()
$nodes/.
$nodes union .
$nodes except ()
|
|---|
| Examples | let $doc := <doc><b/><a/></doc>
return distinct-ordered-nodes(($doc/a, $doc/a, $doc/b)) Result: <b/>, <a/> |
|---|
| Signature | fn:innermost( $nodes as gnode()*) as gnode()* |
|---|
| Summary | Returns those nodes of $nodes that have no descendant in $nodes, in document order and without duplicates. |
|---|
| Examples | let $xml := <a><b><c/></b></a>
return innermost(($xml, $xml//c)) Result: <c/> |
|---|
| Signature | fn:outermost( $nodes as gnode()*) as gnode()* |
|---|
| Summary | Returns those nodes of $nodes that have no ancestor in $nodes, in document order and without duplicates. |
|---|
| Examples | let $xml := <a><b><c/></b></a>
return outermost(($xml, $xml//c)) Result: <a><b><c/></b></a> |
|---|
| Signature | fn:id( $values as xs:string*, $node as node()? := .) as element()* |
|---|
| Summary | Returns the elements of the tree containing $node that have an ID value matching one of the supplied $values. |
|---|
| Examples | id('x', document { <a><b xml:id='x'/></a> }) Result: <b xml:id="x"/> |
|---|
| Signature | fn:element-with-id( $values as xs:string*, $node as node()? := .) as element()* |
|---|
| Summary | Returns the elements of the tree containing $node that have an ID value matching one of the supplied $values. For most documents, the result is the same as for fn:id; the functions differ for schema-validated documents in which an ID is not supplied by an attribute. |
|---|
| Examples | element-with-id('x', document { <a><b xml:id='x'/></a> }) Result: <b xml:id="x"/> |
|---|
| Signature | fn:idref( $values as xs:string*, $node as node()? := .) as node()* |
|---|
| Summary | Returns the elements and attributes of the tree containing $node that have an IDREF value matching one of the supplied $values. Attributes are only typed as IDREF if the document was parsed with a DTD or validated against a schema. |
|---|
| Examples | idref('x', document { <a><b xml:id='x'/></a> }) Result: (). Without a DTD or schema, no attribute is typed as IDREF. |
|---|
| Signature | fn:generate-id( $node as gnode()? := .) as xs:string |
|---|
| Summary | Returns a string that uniquely identifies $node. The returned value is implementation-dependent; it is guaranteed to be the same for every call on the same node, and different for distinct nodes. The empty string is returned if $node is an empty sequence. |
|---|
| Examples | let $node := <a/>
return generate-id($node) eq generate-id($node) Result: true() |
|---|
| Signature | fn:function-lookup( $name as xs:QName, $arity as xs:integer) as fn(*)? |
|---|
| Summary | Returns the function with the supplied $name and $arity, or an empty sequence if no such function exists. |
|---|
| Examples | function-lookup(xs:QName('fn:abs'), 1)(-3) Result: 3 |
|---|
| Signature | fn:function-name( $function as fn(*)) as xs:QName? |
|---|
| Summary | Returns the name of a $function item. |
|---|
| Examples | function-name(true#0) Result: xs:QName('fn:true')
function-name(fn { . + 1 }) Result: () |
|---|
| Signature | fn:function-arity( $function as fn(*)) as xs:integer |
|---|
| Summary | Returns the arity (number of parameters) of a $function item. |
|---|
| Examples | function-arity(true#0) Result: 0
function-arity(fn { . + 1 }) Result: 1 |
|---|
| Signature | fn:function-identity( $function as fn(*)) as xs:string |
|---|
| Summary | Returns a string representing the identity of a $function. The generated string may change when the function is run multiple times. |
|---|
| Examples | function-identity({}) Result: 'map0'
function-identity(abs#1) Result: 'fn:abs#1' |
|---|
| Signature | fn:function-annotations( $function as fn(*)) as map(xs:QName, xs:anyAtomicType*)* |
|---|
| Summary | Returns the annotations of a $function item as a sequence of single-entry maps. Each map contains one annotation name as its key and the annotation arguments as its value. |
|---|
| Examples | declare
%public
%rest:GET
%rest:path('/')
%perm:allow('all')
function local:index($n) {
<html>Welcome!</html>
};
function-annotations(local:index#1) The result:{ #xq:public: () },
{ #rest:GET: () },
{ #rest:path: '/' },
{ #perm:allow: 'all' }
let $add := fn($a, $b) { $a * $b }
let $double := %local:deprecated fn($a) { $a + $a }
for $ann in ($add, $double) =!> function-annotations()
where map:keys($ann) = #local:deprecated
return 'Deprecated function found.' Result: 'Deprecated function found.' |
|---|
Added: New function.
| Signature | fn:element-to-map-plan( $input as (document-node() | element())*) as map(xs:string, (fn:element-conversion-plan-record | fn:attribute-conversion-plan-record)) |
|---|
| Summary | Analyzes the supplied $input nodes and returns a conversion plan suitable for use as the plan option of fn:element-to-map.
The returned map contains entries for element and attribute names. Each value is either an fn:element-conversion-plan-record:
record(
layout as xs:string,
child? as xs:string?,
type? as enum('integer', 'decimal', 'double', 'boolean', 'string')
)
or an fn:attribute-conversion-plan-record (for entries prefixed with @):
record(
type as enum('integer', 'decimal', 'double', 'boolean', 'string', 'skip')
)
The type is inferred from the string values: integer, decimal or double if all values are numeric, boolean if all values are true/false, and string otherwise. Values with a leading zero (such as 007) are kept as string to preserve their lexical form.
|
|---|
| Examples | element-to-map-plan(<a><b>3</b><b>4</b></a>) The result:{
"a": {
"layout": "list",
"child": "b"
},
"b": {
"layout": "simple",
"type": "integer"
}
}
element-to-map-plan((<a x="2">red</a>, <a x="3">blue</a>)) The result:{
"a": {
"layout": "simple-plus"
},
"@x": {
"type": "integer"
}
}
let $plan := element-to-map-plan(
<name><first>Jane</first><last>Smith</last></name>
)
return element-to-map(
<name><first>John</first><last>Doe</last></name>,
{ 'plan': $plan }
) Generate a plan from sample data and apply it to a new document. The result:{
"name": {
"first": "John",
"last": "Doe"
}
}
|
|---|
Added: New function.
| Signature | fn:element-to-map( $element as (document-node() | element())?, $options as map(*)? := {}) as map(xs:string, item()?)? |
|---|
| Summary | Converts $element into a map suitable for JSON serialization. The returned map has a single entry whose key is the element name and whose value represents the element’s attributes and children. The $options argument accepts the following keys:
| option | default | description |
|---|
plan | {} | A conversion plan, as generated by fn:element-to-map-plan, controlling how individual elements and attributes are converted. | attribute-marker | '@' | String prepended to keys representing attributes in the output. | content-key | '#content' | String used in place of #content as the key for content derived from an element’s children. If the chosen key clashes with another key in the generated map, # characters are prepended until it is unique. | name-format | 'default' | Controls how element and attribute names are serialized: lexical, local, eqname, or default. |
|
|---|
| Examples | element-to-map(<foo>bar</foo>) Result: { "foo": "bar" }
element-to-map(
<name>
<first>Jane</first>
<last>Smith</last>
</name>
) Result: { "name": { "first": "Jane", "last": "Smith" } }
element-to-map(
<list>
<item value='1'/>
<item value='2'/>
</list>,
{ 'attribute-marker': '' }
) Result: { "list": [ { "value": "1" }, { "value": "2" } ] }. The empty attribute marker avoids an @ prefix on attribute keys. |
|---|
JNodes wrap maps and arrays in a tree structure with identity and document order, enabling XPath path expressions to navigate JSON-like data. See JNodes for an introduction.
Added: New function.
| Signature | fn:jtree( $input as (map(*)|array(*))) as jnode((), (map(*)|array(*))) |
|---|
| Summary | Creates a root JNode that wraps the supplied map or array $input, enabling path expressions to navigate the resulting JTree.
Calling jtree($X) is equivalent to the path expression $X/.: maps and arrays that appear as the left-hand operand of / are wrapped implicitly, so an explicit call is rarely needed.
|
|---|
| Examples | jtree([ "a", "b", "c" ])/*[1] Result: "a"
jtree([ "a", "b" ])/* =!> jkey() Result: 1, 2 |
|---|
Added: New function.
| Signature | fn:jkey( $input as jnode()? := .) as xs:anyAtomicType? |
|---|
| Summary | Returns the jkey property of $input: the map key or 1-based array index that identifies this JNode within its parent. Returns an empty sequence if $input is empty or is a root JNode. |
|---|
| Examples | let $array := [ 1, 4.5, "eight", 10 ]
return $array/jnode(*, xs:integer) =!> jkey() Result: 1, 4. Positions of the integer members.
let $map := { 'Mo': 'Monday', 'Tu': 'Tuesday', 'We': 'Wednesday' }
return $map/(Mo|We|Fr|Su) =!> jkey() Result: "Mo", "We". Keys that actually exist in the map; Fr and Su are silently ignored.
let $array := [ [ 4, 18 ], [ 30, 4, 22 ] ]
return $array/descendant::*[. > 25]/ancestor-or-self::* =!> jkey() Result: 2, 1. The subarray [ 30, 4, 22 ] is at index 2; the value 30 is at index 1 within it. |
|---|
Added: New function.
| Signature | fn:jvalue( $input as jnode()? := .) as item()* |
|---|
| Summary | Returns the jvalue property of $input: the value wrapped by the JNode. Returns an empty sequence if $input is empty.
In most contexts an explicit call is unnecessary, because the coercion rules automatically extract the value when a JNode is used where an atomic value, map, or array is required. Notable exceptions are effective boolean value tests (if ($jnode) tests for the existence of a child, not its truth value) and calls to functions that accept arbitrary sequences such as count or deep-equal.
|
|---|
| Examples | let $array := [ 1, 3, 4.5, 7, "eight", 10 ]
return $array/jnode(*, xs:integer) =!> jvalue() Result: 1, 3, 7, 10
let $map := { 'Mo': 'Monday', 'Tu': 'Tuesday', 'We': 'Wednesday' }
return $map/(Mo|We|Fr|Su) =!> jvalue() Result: "Monday", "Wednesday" |
|---|
Added: New function.
| Signature | fn:jposition( $input as jnode()? := .) as xs:integer? |
|---|
| Summary | Returns the jposition property of $input: the 1-based position of the map or array that produced this JNode within the sequence that is the parent entry or member value. Returns an empty sequence if $input is empty or is a root JNode.
This property is always 1 for JTrees derived from JSON, since JSON values are never multi-item sequences. It is only relevant when a map entry or array member holds a sequence containing multiple maps or arrays.
|
|---|
| Examples | let $input := {
"a": [ 10, 20 ],
"b": ([ 30, 40 ], [], 0, [ 50 ])
}
return $input/b/* ! [ jposition(), jkey(), jvalue() ] The result:[ 1, 1, 30 ]
[ 1, 2, 40 ]
[ 4, 1, 50 ]
|
|---|
Added: trusted option.
Removed: entity-expansion-limit and allow-external-entities options.
| Signature | fn:doc( $source as xs:string?, $options as map(*)? := {}) as document-node()? |
|---|
| Summary |
Retrieves and parses an XML document from a given URI and returns a document-node() item.
Within $options, the following keys can be specified:
| option | default | description |
|---|
dtd-validation | false() | Enables DTD validation if set to true(). | stable | true() | Ensures deterministic results when set to true(). | strip-space | false() | Controls whether whitespace-only text nodes are stripped. | xinclude | false() | Expands xi:include elements if set to true(). Requires the trusted option to be enabled. | xsd-validation | skip | Specifies XSD validation mode: strict, lax, or skip. | use-xsi-schema-location | false() | Determines whether xsi:schemaLocation and xsi:noNamespaceSchemaLocation declarations are followed. Requires the trusted option to be enabled. |
Additionally, these BaseX XML Parsing options are supported, using lower-case option names:
| option | default | description |
|---|
dtd | true() | When set to true(), external entities are processed, otherwise they are ignored. | intparse | false() | Uses the internal XML parser instead of the standard Java XML parser. | stripns | false() | Strips all namespaces from an XML document while parsing. | trusted | false() | Allows the parser to fetch external resources (external DTDs and entities, XInclude documents, and referenced schemas). The default is controlled by the FNXMLTRUSTED option. |
|
|---|
| Examples | doc('example.xml') The result:<root>
<a> </a>
</root>
doc('example.xml', { 'strip-space': true() }) Result: <root><a/></root>
doc('book.xml', { 'xinclude': true(), 'trusted': true() }) Parses book.xml and expands its xi:include elements. Because XInclude fetches external documents, the trusted option must be enabled; without it, the call is rejected with err:FODC0016 (External resources not available, call is untrusted). |
|---|
Added: trusted option.
| Signature | fn:doc-available( $source as xs:string?, $options as map(*)? := {}) as xs:boolean |
|---|
| Summary |
Checks if an XML document can be retrieved and parsed from a given URI. Returns true if fn:doc($source, $options) would return a document node, and false otherwise.
The recognized options are the same as for fn:doc.
|
|---|
| Examples | doc-available('https://example.org/example.xml') Result: false() |
|---|
| Signature | fn:collection( $source as xs:string? := ()) as item()* |
|---|
| Summary | Returns the documents of the collection that is addressed by $source. If no argument is supplied, the documents of the currently opened database are returned. |
|---|
| Examples | collection('factbook') Returns all documents of the database factbook. |
|---|
| Signature | fn:uri-collection( $source as xs:string? := ()) as xs:anyURI* |
|---|
| Summary | Returns the URIs of the documents of the collection that is addressed by $source. |
|---|
| Examples | uri-collection('factbook') Returns the URIs of all documents of the database factbook. |
|---|
| Signature | fn:unparsed-text( $source as xs:string?, $options as item()? := ()) as xs:string? |
|---|
| Summary | Retrieves $source and returns its contents as a string. The $options argument can be supplied as an encoding string or as a map with an encoding key. |
|---|
| Examples | unparsed-text('notes.txt') Returns the contents of the file notes.txt. |
|---|
| Signature | fn:unparsed-text-lines( $source as xs:string?, $options as item()? := ()) as xs:string* |
|---|
| Summary | Retrieves $source and returns its contents as a sequence of strings, one for each line. As in fn:unparsed-text, the $options argument can be supplied as an encoding string or as a map. |
|---|
| Examples | count(unparsed-text-lines('notes.txt')) Counts the lines of the file notes.txt. |
|---|
| Signature | fn:unparsed-text-available( $source as xs:string?, $options as item()? := ()) as xs:boolean |
|---|
| Summary | Returns true if $source can be retrieved and decoded by fn:unparsed-text. |
|---|
| Examples | unparsed-text-available('notes.txt') Indicates whether the file notes.txt can be read. |
|---|
| Signature | fn:unparsed-binary( $source as xs:string?) as xs:base64Binary? |
|---|
| Summary | Retrieves $source and returns it as a binary. |
|---|
| Examples | unparsed-binary('https://files.basex.org/releases/BaseX.jar') Retrieves the latest release of BaseX. |
|---|
Added: New function.
| Signature | fn:system-properties() as map(xs:QName, xs:anyAtomicType) |
|---|
| Summary | Returns a map with information about the processor. As the map keys are QNames, a property is looked up with ?#name. BaseX supplies the following properties:
xpath-version: version of the supported XPath specificationxsd-version: version of the supported XML Schema specificationproduct-name: name of the productproduct-version: version of the productschema-aware: indicates whether schema-awareness is supportedaccepts-typed-data: indicates whether typed data is acceptedsupports-xinclude: indicates whether XInclude is supportedsupports-dtd: indicates whether DTDs are fully supportedsupports-invisible-xml: indicates whether Invisible XML is availablesupports-dynamic-xquery: indicates whether dynamic XQuery evaluation is supportedsupports-dynamic-xslt: indicates whether dynamic XSLT evaluation is supported
|
|---|
| Examples | system-properties()?#product-name Result: 'BaseX'
system-properties()?#xpath-version Result: 4
sort(map:keys(system-properties()) ! string()) Lists the names of all available properties. |
|---|
| Signature | fn:environment-variable( $name as xs:string) as xs:string? |
|---|
| Summary | Returns the value of the environment variable $name, or an empty sequence if no such variable exists. |
|---|
| Examples | environment-variable('PATH') Returns the search path of the operating system. |
|---|
| Signature | fn:available-environment-variables() as xs:string* |
|---|
| Summary | Returns the names of all environment variables. |
|---|
| Examples | sort(available-environment-variables()) Lists the names of all environment variables. |
|---|
Added: trusted option.
Removed: entity-expansion-limit and allow-external-entities options.
| Signature | fn:parse-xml( $value as (xs:string | xs:hexBinary | xs:base64Binary)?, $options as map(*)? := ()) as document-node(*)? |
|---|
| Summary |
Parses a string as XML and returns a document-node() item.
If the $value is supplied as a binary (e.g., xs:base64Binary or xs:hexBinary), its encoding may be inferred from a byte order mark or an XML declaration. The input is then processed like a resource retrieved via fn:doc.
The recognized $options are the same as for fn:doc, with the following differences: the stable option does not apply; a base-uri can be supplied (defaulting to the static base URI of the function call); and xsd-validation does not support the values lax and type.
|
|---|
| Examples | parse-xml('<Greeting>Hello, world!</Greeting>') Result: <Greeting>Hello, world!</Greeting> |
|---|
| Signature | fn:parse-xml-fragment( $value as (xs:string | xs:hexBinary | xs:base64Binary)?, $options as map(*)? := ()) as document-node()? |
|---|
| Summary |
This function takes an XML fragment as a string or binary input and returns it as a document node.
If the $value is supplied as binary, its encoding is inferred as with fn:unparsed-text, and it is parsed as an external general parsed entity.
Within $options, the standard options are supported:
| option | default | description |
|---|
base-uri | | base-uri of document. Defaults to the static base URI of the function call. | strip-space | false() | Determines whether whitespace-only text nodes are removed from the resulting document. |
Additionally, this BaseX XML Parsing option is supported, using a lower-case option name:
| option | default | description |
|---|
stripns | false() | Strips all namespaces from an XML document while parsing. |
|
|---|
| Examples | parse-xml-fragment('<a/> <b/> <c/>')/node() Result: (<a/>, text {' '}, <b/>, text {' '}, <c/>) |
|---|
| Signature | fn:serialize( $input as item()*, $options as (element(output:serialization-parameters) | map(*))? := ()) as xs:string |
|---|
| Summary | Returns a string representation of $input. The $options argument contains serialization parameters, which can be supplied…
- as a map…
{ "method": "xml", "cdata-section-elements": "div" }
- or (for backward compliance) as an element:
<output:serialization-parameters>
<output:method value='xml'/>
<output:cdata-section-elements value='div'/>
</output:serialization-parameters>
|
|---|
| Examples | serialize(1 to 3) Result: '1 2 3'
serialize(<xml id='1'></xml>) Result: '<xml id="1"/>'
serialize(<html/>, { 'method': 'html', 'html-version': 5.0 }) Result: '<!DOCTYPE HTML><html></html>'
serialize({ 1: "one" }, { 'method': 'json' }) Result: '{"1":"one"}' |
|---|
Added: New function.
| Signature | fn:xsd-validator( $options as map(*)? := {}) as fn((document-node() | element() | attribute())?) as fn:validation-result-record? |
|---|
| Summary |
Assembles an XSD schema and returns a function that validates a document or element node against this schema. The returned function returns an empty sequence if the supplied node is empty. Otherwise, it returns a record with the field is-valid and, on demand, the validated node (typed-node) and details on the invalidities that were found (error-details).
The following $options are available:
| option | default | description |
|---|
schema | () | Schema documents, supplied as element(xs:schema)* nodes. | schema-location | () | URIs of schema documents. Relative URIs are resolved against the static base URI of the function call. | use-xsi-schema-location | false() | Retrieve schema documents that are referenced by xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes of the validated node. | trusted | | Allow access to schema documents that are indirectly referenced (e.g., via xs:include). The default is controlled by the FNXMLTRUSTED option. | xsd-version | | Requested XSD version. An error is raised if no processor with this version is available (see Validation Functions). | return-typed-node | true() | Include the validated node in the result. | return-error-details | false() | Include details on invalidities in the result. If the option is disabled, validation stops after the first error. |
As BaseX is not schema-aware, the returned node has no type annotations, and the options validation-mode (with the values lax and by-type), type and target-namespace are rejected with an error.
|
|---|
| Examples | let $schema := <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:element name='distance' type='xs:decimal'/>
</xs:schema>
let $validator := xsd-validator({ 'schema': $schema })
return (
$validator(<distance>8.5</distance>)?is-valid,
$validator(<distance>8.5km</distance>)?is-valid
) Result: (true(), false()) |
|---|
Strings and binary data can be parsed as HTML to XDM items.
| Signature | fn:parse-html( $value as (xs:string | xs:hexBinary | xs:base64Binary)?, $options as map(*)? := {}) as document-node(*:html)? |
|---|
| Summary | Parses the supplied $value as HTML and returns an item representation, using the supplied $options. The result is returned as a document node with a *:html root element. In contrast to other HTML parsing in BaseX, this function by default uses the Validator.nu HTML Parser, but it can be instructed to use TagSoup by supplying option method=tagsoup. See HTML Functions for more information about the available HTML parsers and their options.
With our custom html:parse function, additional conversion formats are available.
|
|---|
| Examples | parse-html(
'<!DOCTYPE html><html><head><meta charset="UTF-8"></head>' ||
'<body>Hello, World!</body></html>'
) The result:<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
</head>
<body>Hello, World!</body>
</html>
|
|---|
| Signature | fn:html-doc( $source as xs:string?, $options as map(*)? := {}) as document-node(*:html)? |
|---|
| Summary | Reads an external resource containing HTML data, retrieved from the $source location, and returns the result of parsing the resource as HTML, using the supplied $options.
The returned result is a document node whose root element is <html>, conforming to the HTML structure parsed from the input. The result is equivalent to reading the file as binary with unparsed-binary and parsing it via parse-html.
For more details and allowable options, see fn:html-doc.
With our custom html:doc function, additional parsing features are available.
|
|---|
| Examples | html-doc('https://basex.org/download')//@href[contains(., '.zip')]!string() Returns the download link for the latest BaseX version. |
|---|
Strings and resources can be parsed to XDM items and serialized back to their original form.
| Signature | fn:parse-json( $value as xs:string?, $options as map(*)? := {}) as item()? |
|---|
| Summary | Parses the supplied $value as JSON and returns an item representation, using the supplied $options. The result may be a map, an array, a string, a double, a boolean, or an empty sequence.
With our custom json:parse function, additional conversion formats are available.
|
|---|
| Examples | parse-json('{ "name": "john" }') Result: { "name": "john" }
parse-json('[ 1, 2, 4, 8, 16 ]') Result: [ 1, 2, 4, 8, 16 ] |
|---|
| Signature | fn:json-doc( $source as xs:string?, $options as map(*)? := {}) as item()? |
|---|
| Summary | Parses the JSON string retrieved from the $source location and returns an item representation, using the supplied $options.
With our custom json:doc function, additional conversion formats are available.
|
|---|
| Examples | json-doc("http://ip.jsontest.com/")?id Returns your IP address. |
|---|
| Signature | fn:json-to-xml( $value as xs:string?, $options as map(*)? := {}) as document-node(fn:*)? |
|---|
| Summary | Parses the supplied $value as a JSON string and returns an XML representation, using the supplied $options.
With our custom json:parse function, additional conversion formats are available.
|
|---|
| Examples | json-to-xml('{ "message": "world" }') The result:document {
<map xmlns="http://www.w3.org/2005/xpath-functions">
<string key="message">world</string>
</map>
}
|
|---|
| Signature | fn:xml-to-json( $node as node()?, $options as map(*)? := {}) as xs:string? |
|---|
| Summary | Converts a $node, whose format conforms to the results created by fn:json-to-xml, to a JSON string, using the supplied $options.
The resulting string can also be created with our custom json:serialize function.
|
|---|
| Examples | <map xmlns="http://www.w3.org/2005/xpath-functions">
<string key="message">world</string>
</map>
=> xml-to-json() Result: '{"message":"world"}' |
|---|
Strings and resources can be parsed to XDM items and serialized back to their original form.
| Signature | fn:csv-to-arrays( $value as xs:string?, $options as map(*)? := {}) as array(xs:string)* |
|---|
| Summary | Parses the supplied $value as CSV data and returns an item representation, using the supplied $options. The result is returned as a sequence of arrays of strings. For details, and for the allowable options, see fn:csv-to-arrays.
With our custom csv:parse function, additional conversion formats are available.
|
|---|
| Examples | csv-to-arrays(
string-join(
('Name,City', 'Rossi,Rome', 'Da Silva,Rio de Janeiro'),
char('\n')
)
) Result: [ "Name", "City" ], [ "Rossi", "Rome" ], [ "Da Silva", "Rio de Janeiro" ]
csv-to-arrays(
string-join(('Product;Price', 'Laptop;1200', 'Mouse;25'), char('\n')),
{ 'separator': ';' }
) Result: [ "Product", "Price" ], [ "Laptop" , "1200" ], [ "Mouse", "25" ] |
|---|
| Signature | fn:parse-csv( $value as xs:string?, $options as map(*)? := {}) as fn:parsed-csv-structure-record? |
|---|
| Summary | Parses the supplied $value as CSV data and returns an item representation, using the supplied $options. The result is returned as a map with these keys:
columns is a sequence of strings containing column names, if anycolumn-index is a map from column names to (one-based) column positionsrows is a sequence of arrays of strings representing the parsed rows of the CSV dataget is a function that returns a field in the result that is identified by row and column. Its signature is function(xs:positiveInteger, (xs:positiveInteger | xs:string)) as xs:string? where the first argument is the (one-based) row number, and the second argument is the (one-based) column number or the column name.
For more details, and for the allowable options, see fn:parse-csv.
With our custom csv:parse function, additional conversion formats are available.
|
|---|
| Examples | parse-csv(
string-join(
('Name,City', 'Rossi,Rome', 'Da Silva,Rio de Janeiro'),
char('\n')
),
{ 'header': true() }
) The result:{
"columns": ("Name", "City"),
"column-index": { "Name": 1, "City": 2},
"rows": ([ "Rossi", "Rome" ], [ "Da Silva", "Rio de Janeiro" ]),
"get": (anonymous-function)#2
}
parse-csv(
string-join(('Laptop;1200', 'Mouse;25', 'Keyboard;45'), char('\n')),
{ 'separator': ';', 'header': ('Product', 'Price') }
) The result:{
"columns": ("Product", "Price"),
"column-index": { "Product": 1, "Price": 2},
"rows": ([ "Laptop", "1200" ], [ "Mouse", "25" ], [ "Keyboard", "45" ]),
"get": (anonymous-function)#2
}
|
|---|
| Signature | fn:csv-doc( $source as xs:string?, $options as map(*)? := {}) as fn:parsed-csv-structure-record? |
|---|
| Summary |
Reads an external resource containing CSV data, and returns the results as a record structure with information about column names and row data, using the supplied $options.
The result is equivalent to reading the CSV file as binary using unparsed-binary and parsing the content with parse-csv. If the $source is the empty sequence, the function returns the empty sequence.
For more details and allowable options, see fn:csv-doc.
With our custom csv:doc function, additional conversion formats are available.
|
|---|
| Examples | csv-doc('input.csv', { 'header': true() }) The result:{
"columns": ("Name", "Age"),
"column-index": { "Name": 1, "Age": 2 },
"rows": ([ "Alice", "30" ], [ "Bob", "25" ]),
"get": (anonymous-function)#2
}
|
|---|
| Signature | fn:csv-to-xml( $value as xs:string?, $options as map(*)? := {}) as document-node(fn:csv)? |
|---|
| Summary | Parses the supplied $value as CSV data and returns an item representation, using the supplied $options. The result is returned as a document node with a csv root element in the http://www.w3.org/2005/xpath-functions namespace. It has these child elements, which are all in the same namespace:
columns holds the column names in a sequence of column elements (only present if there are column names)rows holds a sequence of row elements representing the rows of the CSV data. Each row has field elements with the field values. Their column attribute indicates the column name, if any
For more details, and for the allowable options, see fn:csv-to-xml.
With our custom csv:parse function, additional conversion formats are available.
|
|---|
| Examples | csv-to-xml(
string-join(('Laptop;1200', 'Mouse;25', 'Keyboard;45'), char('\n')),
{ 'separator': ';', 'header': ('Product', 'Price') }
) The result:<csv xmlns="http://www.w3.org/2005/xpath-functions">
<columns>
<column>Product</column>
<column>Price</column>
</columns>
<rows>
<row>
<field column="Product">Laptop</field>
<field column="Price">1200</field>
</row>
<row>
<field column="Product">Mouse</field>
<field column="Price">25</field>
</row>
<row>
<field column="Product">Keyboard</field>
<field column="Price">45</field>
</row>
</rows>
</csv>
|
|---|
A separate page is available on
Invisible XML and how to use it in XQuery.
| Signature | fn:invisible-xml( $grammar as (xs:string | element(ixml))?, $options as map(*)? := {}) as fn($value as xs:string) as document-node() |
|---|
| Summary | Generates a parser for the supplied Invisible XML $grammar and returns it as a function. The returned function converts an input string to an XML document. See Invisible XML for a full description. |
|---|
| Examples | let $string := 'greeting: "Hello", " ", name. name: ["A"-"Z"], ["a"-"z"]+.'
return invisible-xml($string)('Hello World') Result: <greeting>Hello <name>World</name></greeting> |
|---|
| Signature | fn:load-xquery-module( $module-uri as xs:string, $options as map(*)? := {}) as fn:load-xquery-module-record |
|---|
| Summary |
Loads an XQuery library module by its namespace URI and returns a map of its public functions and global variables.
Within $options, the following keys can be specified:
| option | default | description |
|---|
location-hints | () | URI(s) of the module. | content | () | Literal string content of the module. If supplied, location-hints are ignored. | context-item | () | Initial context item for evaluating global variables. | variables | {} | Map of external variable bindings. | vendor-options | {} | Ignored by BaseX. | xquery-version | | Specifies the minimum XQuery version; must be supported by BaseX. Default: version declared in the module, otherwise unspecified. |
|
|---|
| Examples | let $module := '
module namespace m = "http://ex.org";
declare %public function m:two() { 2 };'
let $functions := load-xquery-module(
'http://ex.org',
{ 'content': $module }
)?functions
let $two := $functions(QName('http://ex.org', 'two'))?0
return $two() Result: 2
let $uri := 'http://basex.org/modules/code'
let $functions := load-xquery-module(
$uri,
{ 'location-hints': 'code.xqm' }
)?functions
let $run := $functions(QName($uri, 'run'))(0)
return $run() Parses code.xqm and evaluates a zero-arity function named run. |
|---|
Added: New function.
| Signature | fn:transform( $options as map(*)) as map(*) |
|---|
| Summary |
Invokes an XSLT transformation and returns a map with the result documents. The key of the principal result document is the base output URI, or the string output; secondary result documents, generated by xsl:result-document, are returned under their own output URI. See XSLT Functions for the processors that can be used.
The following $options are available:
| option | default | description |
|---|
stylesheet-location | | URI of the stylesheet. Relative URIs are resolved against the static base URI of the function call. | stylesheet-node | | Stylesheet, supplied as document or element node. | stylesheet-text | | Stylesheet, supplied as string. Exactly one of the three stylesheet options must be specified. | stylesheet-base-uri | | Static base URI of the stylesheet. | stylesheet-params | {} | Map with stylesheet parameters. The keys are QNames. | source-location | | URI of the source document. | source-node | | Source document, supplied as node. Exactly one of the two source options must be specified. | base-output-uri | | URI of the principal result document. | delivery-format | document | Result format: document (document node), serialized (string), raw (the result of the transformation, converted to XQuery items) or file (the result is written to the base output URI, and the returned value is an empty sequence). | serialization-params | {} | Serialization parameters for the principal result document. Parameters that are unknown to the XSLT processor are ignored; parameters with map or array values, such as use-character-maps, are rejected. As document results are built directly, the option only applies to the delivery formats serialized and file. | post-process | | Function that is applied to the key and the value of the result before it is returned. | cache | true() | Cache the compiled stylesheet. Only applies to stylesheets that are supplied by location. | trusted | | Allow the stylesheet to access external resources (e.g., via xsl:include or document). The default is controlled by the FNXMLTRUSTED option. | xslt-version | | Requested XSLT version. An error is raised if no processor with this version is available. |
If Saxon is available, it is addressed via its s9api interface, and all options of the specification are supported. Otherwise, transformations are performed via Java’s JAXP interface: the options that cannot be assigned via this interface (initial-template, initial-mode, initial-function, global-context-item, initial-match-selection, static-params, template-params, tunnel-params, the package-* options) are rejected with an error, as is the delivery format raw, and secondary result documents are lost.
The options enable-trace and vendor-options are accepted and ignored, as are enable-assertions and enable-messages if the JAXP interface is used. Requested properties other than xsl:version are always rejected.
|
|---|
| Examples | transform({
'stylesheet-text':
"<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version='1.0'><xsl:template match='/'><out><xsl:value-of
select='//b'/></out></xsl:template></xsl:stylesheet>",
'source-node': <a><b>89</b></a>
})?output Result: <out>89</out> |
|---|
| Signature | fn:op( $operator as xs:string) as fn($op1 as item()*, $op2 as item()*) as item()* |
|---|
| Summary | Returns a new function that applies the specified $operator to two arguments. The supported operators are:
+ * - | || < <= = >= > != << >> is mod div idiv and or lt le eq ge gt ne to union intersect except otherwise
|
|---|
| Examples | for-each-pair(1 to 3, 4 to 6, op('+')) Result: 5, 7, 9
map:keys(map:filter(
{ 2: 1234, 3: 3, 4: 5678, 5: 5 },
op('=')
)) Result: 3, 5. Keeps the entries whose value equals the key, and returns those keys. |
|---|
Added: New function.
| Signature | fn:schema-type( $name as xs:QName) as fn:schema-type-record? |
|---|
| Summary | Returns a fn:schema-type-record with information about the schema type named $name, with the fields described for fn:atomic-type-annotation. An empty sequence is returned if no such type is known; BaseX provides the built-in XSD types. |
|---|
| Examples | schema-type(xs:QName('xs:integer'))?variety Result: 'atomic'
schema-type(xs:QName('xs:integer'))?base-type()?name => string() Result: 'decimal'
schema-type(xs:QName('xs:positiveInteger'))?constructor('42')
instance of xs:positiveInteger Result: true()
empty(schema-type(xs:QName('unknown-type'))) Result: true() |
|---|
| Signature | fn:type-of( $value as item()*) as xs:string |
|---|
| Summary | Returns a string representation of the type of $value. The function is similar to inspect:type. |
|---|
| Examples | type-of('Hello') Result: 'xs:string'
type-of(1 to 10) Result: 'xs:integer+'
type-of((1, 'a')) Result: '(xs:integer|xs:string)+'
type-of(()) Result: 'empty-sequence()' |
|---|
Added: New function.
| Signature | fn:atomic-type-annotation( $value as xs:anyAtomicType) as fn:schema-type-record |
|---|
| Summary | Returns a record with information about the type annotation of $value. The record has the following fields:
name: QName of the typeis-simple: indicates whether it is a simple typebase-type: function returning the annotation of the base typeprimitive-type: function returning the annotation of the primitive typevariety: variety of the type (atomic, list, union or mixed)members: function returning the annotations of the member typessimple-content-type: function returning the annotation of the simple content typematches: function testing whether an atomic value is an instance of the typeconstructor: function constructing a value of the type
|
|---|
| Examples | atomic-type-annotation(1e0)?variety Result: 'atomic'
atomic-type-annotation(xs:byte(1))?base-type()?name => string() Result: 'short'
atomic-type-annotation(1)?matches(2) Result: true()
atomic-type-annotation(xs:byte(1))?constructor('127') instance of xs:byte Result: true() |
|---|
Added: New function.
| Signature | fn:node-type-annotation( $node as (element() | attribute())) as fn:schema-type-record |
|---|
| Summary | Returns a fn:schema-type-record with information about the type annotation of an element or attribute node, with the fields described for fn:atomic-type-annotation. As BaseX is not schema-aware, elements are annotated as xs:untyped and attributes as xs:untypedAtomic. |
|---|
| Examples | node-type-annotation(<a/>)?name => string() Result: 'untyped'
node-type-annotation(attribute id { 1 })?name => string() Result: 'untypedAtomic'
node-type-annotation(<a/>)?variety Result: 'mixed' |
|---|
| Signature | fn:current-date() as xs:date |
|---|
| Summary | Returns the current date, including a timezone. All calls within a single query return the same value. |
|---|
| Examples | current-date() eq current-date() Result: true(). The value is stable throughout the query. |
|---|
| Signature | fn:current-dateTime() as xs:dateTimeStamp |
|---|
| Summary | Returns the current date and time, including a timezone. All calls within a single query return the same value. |
|---|
| Examples | current-dateTime() eq current-dateTime() Result: true(). The value is stable throughout the query. |
|---|
| Signature | fn:current-time() as xs:time |
|---|
| Summary | Returns the current time, including a timezone. All calls within a single query return the same value. |
|---|
| Examples | current-time() eq current-time() Result: true(). The value is stable throughout the query. |
|---|
| Signature | fn:default-collation() as xs:string |
|---|
| Summary | Returns the default collation of the query. |
|---|
| Examples | default-collation() Result: 'http://www.w3.org/2005/xpath-functions/collation/codepoint' |
|---|
| Signature | fn:default-language() as xs:language |
|---|
| Summary | Returns the default language used for formatting numbers and dates. BaseX always returns en. |
|---|
| Signature | fn:implicit-timezone() as xs:dayTimeDuration |
|---|
| Summary | Returns the timezone of the system on which the query is run. It is used whenever a date, time or dateTime value without an explicit timezone needs to be compared or adjusted. |
|---|
| Examples | implicit-timezone() Returns e.g. PT2H for Central European Summer Time. |
|---|
| Signature | fn:last() as xs:integer |
|---|
| Summary | Returns the number of items in the sequence that is currently being processed. |
|---|
| Examples | ('Kafka', 'Camus', 'Tawada')[last()] Result: 'Tawada' |
|---|
| Signature | fn:position() as xs:integer |
|---|
| Summary | Returns the position of the context item within the sequence that is currently being processed. |
|---|
| Examples | (1 to 5)[position() gt 3] Result: 4, 5 |
|---|
| Signature | fn:static-base-uri() as xs:anyURI? |
|---|
| Summary | Returns the static base URI of the query, or an empty sequence if no base URI is available. |
|---|
| Examples | static-base-uri() Returns the URI of the executed query file. |
|---|
| Signature | fn:error( $code as xs:QName? := (), $description as xs:string? := (), $value as item()* := ()) as xs:error |
|---|
| Summary | Raises an error with the supplied $code, $description and $value. If no $code is supplied, FOER0000 is used. |
|---|
| Examples | error(xs:QName('err:FORG0001'), 'Wrong value') Raises FORG0001 with the supplied description. |
|---|
| Signature | fn:trace( $input as item()*, $label as xs:string? := ()) as item()* |
|---|
| Summary | Generates a serialized representation of $input, optionally prefixed with $label, and outputs it (see Debugging). In contrast to fn:message, the evaluated result is returned unchanged. |
|---|
| Signature | fn:message( $input as item()*, $label as xs:string? := ()) as empty-sequence() |
|---|
| Summary | Generates a serialized representation of $input, optionally prefixed with $label, and outputs it (see Debugging). The function itself returns an empty sequence. In contrast to fn:trace, the evaluated result will be swallowed. |
|---|
| Examples | 'Hello' => trace() => void() Results can also be output and swallowed with fn:trace and fn:void. |
|---|
Version 13.0- Added:
fn:atomic-type-annotation, fn:build-dateTime, fn:build-uri, fn:element-to-map-plan, fn:element-to-map, fn:graphemes, fn:jkey, fn:jposition, fn:jtree, fn:jvalue, fn:matching-segments, fn:node-type-annotation, fn:pad-string, fn:parts-of-dateTime, fn:schema-type, fn:system-properties, fn:transform, fn:unix-dateTime, fn:xsd-validator. - Added:
trusted option for fn:doc, fn:doc-available and fn:parse-xml. - Updated:
fn:insert-separator - Updated:
fn:deep-equal: The debug option outputs the items that were found to be different. - Removed:
entity-expansion-limit and allow-external-entities options; fn:intersperse and fn:sequence-join in favor of fn:insert-separator. - Removed:
fn:deep-equal: Options false-on-error and normalize-space.
Version 12.0- Added:
fn:civil-timezone, fn:collation, fn:collation-available, fn:csv-doc, fn:csv-to-arrays, fn:csv-to-xml, fn:divide-decimals, fn:function-identity, fn:html-doc, fn:load-xquery-module, fn:parse-csv, fn:parse-html, fn:parse-uri, fn:partial-apply, fn:siblings, fn:type-of, fn:unparsed-binary. - Updated:
fn:apply, fn:function-annotations, fn:hash, fn:doc, fn:doc-available, fn:path, fn:parse-json, fn:parse-xml, fn:parse-xml-fragment, fn:replace, fn:round, fn:sequence-join.
Version 11.0- Added:
fn:all-different, fn:all-equal, fn:atomic-equal, fn:char, fn:collation-key, fn:contains-subsequence, fn:decode-from-uri, fn:distinct-ordered-nodes, fn:do-until, fn:duplicate-values, fn:ends-with-subsequence, fn:every, fn:expanded-QName, fn:foot, fn:function-annotations, fn:hash, fn:highest, fn:identity, fn:in-scope-namespaces, fn:index-where, fn:intersperse, fn:items-at, fn:lowest, fn:message, fn:op, fn:parse-QName, fn:parse-integer, fn:partition, fn:replicate, fn:seconds, fn:slice, fn:some, fn:sort-with, fn:starts-with-subsequence, fn:subsequence-where, fn:take-while, fn:transitive-closure, fn:trunk, fn:void, fn:while-do - Updated:
fn:compare, fn:deep-equal, fn:filter, fn:fold-left, fn:fold-right, fn:for-each, fn:for-each-pair, fn:format-integer, fn:format-number, fn:remove, fn:replace, fn:sort, fn:string-join, fn:tokenize - Updated: Positional argument added to the function parameters.
⚡Generated with XQuery