UpdateIfExpr

An UpdateIfExpr is a conditional expression for use in an update expression. If the expression following the if keyword evaluates to true, the update expression following the then keyword is applied, otherwise the update expression following the else keyword is applied.

Top of page

Related Syntax Constructs

The following construct(s) refer to this construct:


Syntax

graphics/UpdateIfExpr.png

Description

If the then branch and/or the else branch does not require any update operations, an empty pair of parentheses should be used.

Note that the else clause is mandatory.

Example

Insert an attribute, if it does not exist yet, otherwise replace the existing attribute, if its value is less then 100. This query contains two UpdateIfExpr constructs, where the second one occurs in the else branch of the first:

update
  for $book in input()/bib/book
  do 
    if (empty($book/@year)) then
		    insert attribute year {year-from-date(current-date())}
      into $book
    else if ($book/@year < 100) then
		    replace $book/@year
      with attribute year {1900 + $book/@year}
    else
      ()