Difference between revisions of "Update Module"

From BaseX Documentation
Jump to navigation Jump to search
Line 6: Line 6:
  
 
Except for [[#update:output-cache|update:output-cache]], all functions are ''updating'' and thus comply to the XQuery Update constraints.
 
Except for [[#update:output-cache|update:output-cache]], all functions are ''updating'' and thus comply to the XQuery Update constraints.
 +
 +
=Updates=
 +
 +
==update:for-each==
 +
 +
{|
 +
|-
 +
| width='120' | '''Signatures'''
 +
|{{Func|update:for-each|$seq as item()*, $function as function(item()) as item()*)|empty-sequence()}}
 +
|-
 +
| '''Summary'''
 +
|The updating variant of [[Higher-Order Functions#fn:for-each|fn:for-each]] applies the specified updating <code>$function</code> to every item of <code>$seq</code>.
 +
|-
 +
| '''Examples'''
 +
|
 +
* Creates two databases:
 +
<pre class="brush:xquery">
 +
let $names := ('db1', 'db2')
 +
return update:for-each($names, db:create#1)
 +
</pre>
 +
|}
 +
 +
==update:for-each-pair==
 +
 +
{|
 +
|-
 +
| width='120' | '''Signatures'''
 +
|{{Func|update:for-each-pair|$seq1 as item()*, $function as function(item()) as item()*)|empty-sequence()}}
 +
|-
 +
| '''Summary'''
 +
|The updating variant of [[Higher-Order Functions#fn:for-each-pair|fn:for-each-pair]] applies the specified updating <code>$function</code> to the successive pairs of items of <code>$seq1</code> and <code>$seq2</code>. Evaluation is stopped if one sequence yields no more items.
 +
|-
 +
| '''Examples'''
 +
|
 +
* Creates two databases:
 +
<pre class="brush:xquery">
 +
copy $xml := <xml><a/><b/></xml>
 +
modify update:for-each-pair(
 +
  ('a', 'b'),
 +
  ('d', 'e'),
 +
  function($source, $target) {
 +
    for $e in $xml/*[name() = $source]
 +
    return rename node $e as $target
 +
  }
 +
)
 +
return $xml
 +
</pre>
 +
|}
  
 
=Output=
 
=Output=

Revision as of 13:42, 12 December 2017

This XQuery Module provides additional functions for performing updates and returning results in updating expressions.

Conventions

All functions in this module are assigned to the http://basex.org/modules/update namespace, which is statically bound to the update prefix.

Except for update:output-cache, all functions are updating and thus comply to the XQuery Update constraints.

Updates

update:for-each

Signatures update:for-each($seq as item()*, $function as function(item()) as item()*)) as empty-sequence()
Summary The updating variant of fn:for-each applies the specified updating $function to every item of $seq.
Examples
  • Creates two databases:
let $names := ('db1', 'db2')
return update:for-each($names, db:create#1)

update:for-each-pair

Signatures update:for-each-pair($seq1 as item()*, $function as function(item()) as item()*)) as empty-sequence()
Summary The updating variant of fn:for-each-pair applies the specified updating $function to the successive pairs of items of $seq1 and $seq2. Evaluation is stopped if one sequence yields no more items.
Examples
  • Creates two databases:
copy $xml := <xml><a/><b/></xml>
modify update:for-each-pair(
  ('a', 'b'),
  ('d', 'e'),
  function($source, $target) {
    for $e in $xml/*[name() = $source]
    return rename node $e as $target
  }
)
return $xml

Output

update:output

Template:Mark: formerly db:output.

Signatures update:output($result as item()*) as empty-sequence()
Summary This function is a helper function for returning results in an updating expression. The argument of the function will be evaluated, and the resulting items will be cached and returned after the updates on the pending update list have been processed. As nodes may be updated, they will be copied before being cached.
Examples
  • update:output("Prices have been deleted."), delete node //price deletes all price elements in a database and returns an info message.

update:output-cache

Template:Mark: formerly db:output-cache.

Signatures update:output-cache() as item()*
Summary Returns the items that have been cached by update:output. It can be used to check which items will eventually be returned as result of an updating function.
This function is non-deterministic: It will return different results before and after items have been cached. It is e. g. useful when writing unit tests.

Changelog

This module was introduced with Version 9.0.