Changes

Jump to navigation Jump to search
2,845 bytes added ,  12:46, 6 May 2024
no edit summary
This [[Module Library|XQuery Module]] contains various small some utility and helper functions. Please note that some  With {{Announce|Version 11}}, many functions have been removed in favor of new features of the XQuery 4: {||- valign="top"| '''BaseX 10'''| '''XQuery 4'''|- valign="top"| {{Code|util:array-members}}| [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-array-members <code>array:members</code>]|- valign="top"| {{Code|util:array-values}}| [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-array-values <code>array:values</code>]|- valign="top"| {{Code|util:chars}}| [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-chars <code>fn:characters</code>]|- valign="top"| {{Code|util:duplicates}}| [https://qt4cg.org/specifications/xpath-functions are used for internal query rewritings-40/Overview. They may be renamed html#func-duplicate-values <code>fn:duplicate-values</code>]|- valign="top"| {{Code|util:init}}| [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-trunk <code>fn:trunk</code>]|- valign="top"| {{Code|util:intersperse}}| [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-intersperse <code>fn:intersperse</code>]|- valign="top"| {{Code|util:item}}| [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-items-at <code>fn:items-at</code>]|- valign="top"| {{Code|util:last}}| [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-foot <code>fn:foot</code>]|- valign="top"| {{Code|util:map-entries}}| [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-map-entries <code>map:entries</code>]|- valign="top"| {{Code|util:map-values}}| [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-map-values <code>map:values</code>]|- valign="top"| {{Code|util:or moved to other modules in future versions of BaseX}}| <code>$expr1 otherwise $expr2|- valign="top"| {{Code|util:replicate}}| [https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-replicate <code>fn:replicate</code>]|}
=Conventions=
All functions and errors in this module and errors are assigned to the <code><nowiki>http://basex.org/modules/util</nowiki></code> namespace, which is statically bound to the {{Code|util}} prefix.<br/>
=FunctionsConditions and Ranges=
==util:if==
 
{{Mark|Introduced with Version 9.1:}}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|util:if|$condition as item()*, $then as item()*|item()*}}<br/pre>{{Func|util:if|( $condition as item()*, $then as item()*, $else as item()*| := ()) as item()*}}<br/pre>|-valign="top"
| '''Summary'''
|Alternative writing for the if/then/else expression:
* If the ''effective boolean value'' of {{Code|$condition}} is true, the {{Code|$then}} branch will be evaluated.
* Otherwise, {{Code|$else}} will be evaluated. If no the third argument is suppliedomitted, an empty sequence will be returned.|-valign="top"
| '''Examples'''
|
|}
==util:orcount-within== {{Mark|Introduced with Version 9.1:}}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>util:or|count-within( $items sequence as item()*, $default min as itemxs:integer, $max as xs:integer := ()*|item()*}}as xs:boolean</pre>|-valign="top"
| '''Summary'''
|Returns Checks if the specified {{Code|$itemssequence}} has at least {{Code|$min}} if it is a non-empty sequence. Otherwiseand, optionally, returns at most {{Code|$defaultmax}}items. The function is equivalent Equivalent to the expression :<codepre lang='xquery'>if(existslet $count := count($itemssequence)) then return $count >= $min and $items else count <= $defaultmax</codepre>.|-valign="top"
| '''Examples'''
|
* <code>util:orcount-within((123'a', 'b', 456'c'), 2)</code> returns {{Code|123true}}.* <code>util:orcount-within((1to 1000000000)[. = 0< 10], -13, 6)</code> returns {{Code|-1true}}.
|}
==util:item-atrange==
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>util:item-at|range( $sequence as item()*, $position first as xs:double|, $last as xs:double) as item()?}}*<br/pre>|-valign="top"
| '''Summary'''
|Returns the item items from {{Code|$sequence}} , starting at position {{Code|$first}} and ending at the specified {{Code|$positionlast}}. Equivalent to :<codepre lang='xquery'>subsequence($sequence[, $position]first, $last - $first + 1)</codepre>.|-valign="top"
| '''Examples'''
|
* <code>util:item-at(reverserange(1 to 5), 1)</code> returns <code>5</code>.* <code>util:item-at(('a','b')11, 020)</code> returns an empty sequenceall path results from (if available) position 11 to 20.
|}
=Node Functions= ==util:item-rangeddo==
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>util:item-range|ddo( $sequence nodes as itemnode()*, $first as xs:double, $last ) as xs:double|itemnode()*}}<br/pre>|-valign="top"
| '''Summary'''
|Returns items from {{Code|$sequence}}nodes in ''distinct document order'': duplicate nodes will be removed, starting at position {{Code|$first}} and ending at {{Code|$last}}the remaining nodes will be returned in [https://www.w3. Equivalent to <code>subsequence($sequence, $first, $last org/TR/xquery- $first + 1)<31/code>#dt-document-order document order].As results of path expressions are brought into distinct document order before they are returned, the function is equivalent to:|-| '''Examples'<pre lang='xquery'>|* <code>util$nodes/self::item-rangenode(//item, 11, 20)</codepre> returns all path results from (if available) position 11 to 20.
|}
==util:lastroot== {{Mark|Updated with Version 9.2}}: Renamed (before: {{Code|util:last-from}}).
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>util:last-from|root( $sequence nodes as itemnode()*|item) as document-node()?}}*<br/pre>|-valign="top"
| '''Summary'''
|Returns last item the document nodes of a the specified {{Code|$sequencenodes}}. Equivalent to The path expression <code>$sequence[last()]/abc</code>.|-| '''Examples'''|* is internally represented as <code>util:lastroot(reverse(1 to 100).)/abc</code> returns . Equivalent to:<codepre lang='xquery'>1util:ddo($x ! /)</codepre>.
|}
==util:initstrip-namespaces== {{Mark|Added with Version 9.2:}}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>util:init|strip-namespaces( $sequence node as itemnode(), $prefixes as xs:string*|item := ()) as node()*}}<br/pre>|-valign="top"
| '''Summary'''
|Returns all items of a {{Code|Removes namespaces with the specified <code>$sequence}} except for prefixes</code> from the last one. Equivalent to supplied <code>$sequence[position() < last()]node</code>. An empty string can be supplied to remove the default namespace. If no prefixes are specified, all namespaces will be removed.|-valign="top"
| '''Examples'''
|
* Remove all namespaces from an element and its descendants:<codepre lang='xquery'>util:initstrip-namespaces(1 to 4)</codexml xmlns='uri' xmlns:prefix='uri2' prefix:name='value'> returns <codeprefix:child/>1 2 3</codexml>.|})
==util(: yields :replicate==) {| width<xml name='100%value'|-| width='120' | '''Signatures'''|{{Func|util:replicate|$sequence as item()*, $count as xs:integer|item()*}}><brchild/>|-| '''Summary'''|Returns {{Code|$count}} instances of the specified {{Code|$sequence}}. A similar result can be generated with <code/xml>(1 to $count) ! $sequence</codepre>, but in the latter case, the right-hand expression will be evaluated multiple times.|-* Remove all default namespaces:| '''Errors'<pre lang='xquery'>|{{Error|negative|#Errors}} The specified number is negative.|-| <xml xmlns='uri1'><child xmlns='Examples''uri2'/></xml>|* <code=>util:replicatestrip-namespaces('A', 3)</code> returns <code>A A A</codepre>.
|}
! width="110"|Code
|Description
|-valign="top"
|{{Code|negative}}
|The specified number is negative.
=Changelog=
 
;Version 11.0
* Removed: {{Code|util:array-members}}, {{Code|util:array-values}}, {{Code|util:chars}}, {{Code|util:duplicates}}, {{Code|util:init}}, {{Code|util:intersperse}}, {{Code|util:item}}, {{Code|util:last}}, {{Code|util:map-entries}}, {{Code|util:map-values}}, {{Code|util:replicate}}
 
;Version 9.7
* Added: {{Function||util:strip-namespaces}}
* Updated: {{Function||util:count-within}}: Renamed from {{Code|util:within}}.
 
;Version 9.5
* Added: {{Code|util:intersperse}}, {{Code|util:within}}, {{Code|util:duplicates}}, {{Code|util:array-members}}, {{Code|util:array-values}}, {{Code|util:map-entries}}, {{Code|util:map-values}}
* Updated: {{Code|util:replicate}}: Third argument added.
 
;Version 9.4
* Added: {{Function||util:root}}
 
;Version 9.3
* Added: {{Function||util:ddo}}
;Version 9.2
* Added: [[#{{Code|util:chars}}, {{Code|util:init}}* Updated: {{Code|util:item}}, {{Code|util:last}}, {{Function||util:last]] range}} renamed (before: {{Code|util:item-at}}, {{Code|util:item-range}}, {{Code|util:last-from}})
;Version 9.1
* Added: [[#util:if{{Function||util:if]]}}, [[#util:or{{Code|util:or]]}}
;Version 9.0
* Added: [[#util:replicate{{Code|util:replicate]]}}
The Module was introduced with Version 8.5.
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu