Difference between revisions of "Utility Module"
Jump to navigation
Jump to search
Line 76: | Line 76: | ||
|} | |} | ||
− | ==util:last-from | + | ==util:last== |
+ | |||
+ | {{Mark|Updated with Version 9.2}}: Renamed (before: {{Code|util:last-from}}). | ||
{| width='100%' | {| width='100%' | ||
Line 88: | Line 90: | ||
| '''Examples''' | | '''Examples''' | ||
| | | | ||
− | * <code>util:last | + | * <code>util:last(reverse(1 to 100))</code> returns <code>1</code>. |
+ | |} | ||
+ | |||
+ | ==util:init== | ||
+ | |||
+ | {{Mark|Added with Version 9.2:}} | ||
+ | |||
+ | {| width='100%' | ||
+ | |- | ||
+ | | width='120' | '''Signatures''' | ||
+ | |{{Func|util:init|$sequence as item()*|item()*}}<br/> | ||
+ | |- | ||
+ | | '''Summary''' | ||
+ | |Returns all items of a {{Code|$sequence}} except for the last one. Equivalent to <code>$sequence[position() < last()]</code>. | ||
+ | |- | ||
+ | | '''Examples''' | ||
+ | | | ||
+ | * <code>util:init(1 to 4)</code> returns <code>1 2 3</code>. | ||
|} | |} | ||
Line 120: | Line 139: | ||
=Changelog= | =Changelog= | ||
+ | |||
+ | ;Version 9.2 | ||
+ | * Added: [[#util:last|util:last]] renamed (before: {{Code|util:last-from}}) | ||
;Version 9.1 | ;Version 9.1 |
Revision as of 21:01, 20 November 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.
Contents
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
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:
|
Examples |
|
util:or
Signatures | util:or($items as item()*, $default as item()*) as item()*
|
Summary | Returns $items if it is a non-empty sequence. Otherwise, returns $default . The function is equivalent to the expression if(exists($items)) then $items else $default .
|
Examples |
|
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-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:last
Template:Mark: Renamed (before: 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:init
Signatures | util:init($sequence as item()*) as item()* |
Summary | Returns all items of a $sequence except for the last one. Equivalent to $sequence[position() < last()] .
|
Examples |
|
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 |
|
Errors
Code | Description |
---|---|
negative
|
The specified number is negative. |
Changelog
- Version 9.2
- Added: util:last renamed (before:
util:last-from
)
- Version 9.1
- Version 9.0
- Added: util:replicate
The Module was introduced with Version 8.5.