Mixing Updating and Non-updating Expressions

Updating Expressions are XQuery expressions that encompass the 5 updating primitives.

There are rules about mixing Updating and Non-updating Expressions:

  • First of all, let us remember that Updating Expressions do not return any value. They simply add an update request to a list. Eventually the updates in the list are applied at the end of a script execution (or at the end of the modify clause in the case of the transform expression).

  • Updating Expressions are therefore not allowed in places where a meaningful value is expected. For example the condition of a if, the right hand-side of a let :=, the in part of a for and so on.

  • Mixing Updating and Non-updating Expressions is not allowed in a sequence (the comma operator). Though technically feasible, it would not make much sense to mix expressions that return a value and expressions that don't remember that the sequence operator returns the concatenation of the sequences returned by its components.

    The fn:error() function and the empty sequence () are special as they can appear both in Updating and in non-updating expressions.

  • In the same way, the branches of a if or a typeswitch must be consistent: both Updating or both Non-updating. If both branches are Updating then the if itself is considered Updating, and conversely.

  • If the body of a function is an Updating Expression, then the function must be declared with the updating keyword. Example:

    declare updating function insert-id($elem, $id-value) {
       insert node attribute id { $id-value } into $elem
    }

    A call to such a function is itself considered an Updating Expression. Logically enough, an updating function returns no value and therefore is not allowed to declare a return type.

Copyright © 2010 - 2023 Emakin. All rights reserved.