Utility Functions
This module contains some utility and helper functions.
All functions and errors in this module and errors are assigned to the http://basex.org/modules/util namespace, which is statically bound to the util prefix.
| Signature | util:if(
  $condition  as item()*,
  $then       as item()*,
  $else       as item()*  := ()
) as item()*  | 
|---|
| Summary | Alternative writing for the if/then/else expression:
- If the effective boolean value of 
$condition is true, the $then branch will be evaluated. - Otherwise, 
$else will be evaluated. If the third argument is omitted, an empty sequence will be returned. 
  | 
|---|
| Examples | util:if(true(), 123, 456)  Result: 123
 util:if('', 'wrong!') Returns an empty sequence. | 
|---|
| Signature | util:count-within(
  $input  as item()*,
  $min    as xs:integer,
  $max    as xs:integer  := ()
) as xs:boolean  | 
|---|
| Summary | Checks if the specified $input has at least $min and, optionally, at most $max items. Equivalent to:
let $count := count($sequence)
return $count >= $min and $count <= $max 
   | 
|---|
| Examples | util:count-within(('a', 'b', 'c'), 2)  Result: true()
 util:count-within((1 to 1000000000)[. < 10], 3, 6)  Result: false() | 
|---|
| Signature | util:range(
  $sequence  as item()*,
  $first     as xs:double,
  $last      as xs:double
) as item()*  | 
|---|
| Summary | Returns items from $sequence, starting at position $first and ending at $last. Roughly equivalent to:
subsequence($sequence, $first, $last - $first + 1) 
   | 
|---|
| Examples | util:range(//item, 11, 20) Returns all path results from (if available) position 11 to 20. | 
|---|
Added: New function.
| Signature | util:values-except(
  $values     as xs:anyAtomicType*,
  $except     as xs:anyAtomicType*,
  $collation  as xs:string?         := fn:default-collation()
) as xs:anyAtomicType*  | 
|---|
| Summary | Returns all values of $values excluding the ones from $except. | 
|---|
| Examples | util:values-except(
  1 to 5,
  (2, 4)
)  Result: 1, 3, 5 | 
|---|
Added: New function.
| Signature | util:map-key-at(
  $map    as map(*),
  $index  as xs:integer
) as xs:item()*  | 
|---|
| Summary | Returns the key of a map at the specified position (starting with 1). | 
|---|
| Examples | util:map-value-at(
  { 1: 'one', 10: 'ten', 100: 'hundred' },
  3
)  Result: 100 | 
|---|
Added: New function.
| Signature | util:map-value-at(
  $map    as map(*),
  $index  as xs:integer
) as xs:item()*  | 
|---|
| Summary | Returns the value of a map at the specified position (starting with 1). | 
|---|
| Examples | util:map-value-at(
  { 1: 'one', 10: 'ten', 100: 'hundred' },
  3
)  Result: 'hundred' | 
|---|
| Signature | util:root(
  $nodes  as node()*
) as document-node()*  | 
|---|
| Summary | Returns the document nodes of the specified $nodes. The path expression /abc is internally represented as util:root(.)/abc. Equivalent to:
util:ddo($nodes ! /) 
   | 
|---|
| Signature | util:strip-namespaces(
  $node      as node(),
  $prefixes  as xs:string*  := ()
) as node()  | 
|---|
| Summary | Removes namespaces with the specified $prefixes from the supplied $node. An empty string can be supplied to remove the default namespace. If no prefixes are specified, all namespaces will be removed. | 
|---|
| Examples | util:strip-namespaces(
  <xml xmlns='uri' xmlns:prefix='uri2' prefix:name='value'>
    <prefix:child/>
  </xml>
)  Result: <xml name='value'><child/></xml>
 <xml xmlns='uri1'><child xmlns='uri2'/></xml>
=> util:strip-namespaces('') Remove all default namespaces. | 
|---|
| Code | Description | 
|---|
negative | The specified number is negative. | 
Version 12.0Version 11.0- Removed: 
util:array-members, util:array-values, util:chars, util:duplicates, util:init, util:intersperse, util:item, util:last, util:map-entries, util:map-values, util:replicate in favor of new Standard Functions. 
Version 9.7Version 9.5- Added: 
util:intersperse, util:within, util:duplicates, util:array-members, util:array-values, util:map-entries, util:map-values - Updated: 
util:replicate: Third argument added. 
Version 9.4Version 9.3Version 9.2- Added: 
util:chars, util:init - Updated: 
util:item, util:last, util:range renamed (before: util:item-at, util:item-range, util:last-from) 
Version 9.1Version 9.0Version 8.5
 
⚡Generated with XQuery