Difference between revisions of "Utility Module"

From BaseX Documentation
Jump to navigation Jump to search
Line 14: Line 14:
 
|-
 
|-
 
| width='120' | '''Signatures'''
 
| width='120' | '''Signatures'''
|{{Func|util:if|$codition as item()*, $then as item()*|item()*}}<br/>{{Func|util:if|$codition as item()*, $then as item()*, $else as item()*|item()*}}<br/>
+
|{{Func|util:if|$condition as item()*, $then as item()*|item()*}}<br/>{{Func|util:if|$condition as item()*, $then as item()*, $else as item()*|item()*}}<br/>
 
|-
 
|-
 
| '''Summary'''
 
| '''Summary'''
|Alternative writing for the if/then/else expression. If the condition yields false, and if no {{Code|else}} branch is supplied, an empty sequence is returned.
+
|Alternative writing for the if/then/else expression:
 +
* If the ''effective boolean value'' of {{Code|$condition}} yields true, the {{Code|$then}} branch will be evaluated.
 +
* Otherwise, {{Code|$else}} will be evaluated. If no third argument is supplied, an empty sequence will be returned.
 
|-
 
|-
 
| '''Examples'''
 
| '''Examples'''

Revision as of 16:52, 23 July 2018

This XQuery Module contains various small utility and helper functions. Please note that some of the functions are used for internal query rewritings. They may be renamed or moved to other modules in future versions of BaseX.

Conventions

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.

Functions

util:if

Template:Mark

Signatures util:if($condition as item()*, $then as item()*) as item()*
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 yields true, the $then branch will be evaluated.
  • Otherwise, $else will be evaluated. If no third argument is supplied, an empty sequence will be returned.
Examples
  • util:if(true(), 123, 456) returns 123.
  • util:if(0, 'wrong!') returns an empty sequence.

util:item-at

Signatures util:item-at($sequence as item()*, $position as xs:double) as item()?
Summary Returns the item from $sequence at the specified $position. Equivalent to $sequence[$position].
Examples
  • util:item-at(reverse(1 to 5), 1) returns 5.
  • util:item-at(('a','b'), 0) returns an empty sequence.

util:item-range

Signatures util:item-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. Equivalent to subsequence($sequence, $first, $last - $first + 1).
Examples
  • util:item-range(//item, 11, 20) returns all path results from (if available) position 11 to 20.

util:last-from

Signatures util:last-from($sequence as item()*) as item()?
Summary Returns last item of a $sequence. Equivalent to $sequence[last()].
Examples
  • util:last-from(reverse(1 to 100)) returns 1.

util:replicate

Signatures util:replicate($sequence as item()*, $count as xs:integer) as item()*
Summary Returns $count instances of the specified $sequence. A similar result can be generated with (1 to $count) ! $sequence, but in the latter case, the right-hand expression will be evaluated multiple times.
Errors negative: The specified number is negative.
Examples
  • util:replicate('A', 3) returns A A A.

Errors

Code Description
negative The specified number is negative.

Changelog

Version 9.1
Version 9.0

The Module was introduced with Version 8.5.