XQuery Update Facility 3.0 provides extensions to the semantics of several existing kinds of XQuery expressions, as specified in this section.
The syntax of the FLWOR expression is not changed.
The category of the FLWOR expression is the same as the category of the expression in its ReturnClause.
If any ForClause, LetClause, WindowClause, WhereClause, GroupByClause, or OrderByClause has operand expressions that are an updating expression, an error is raised [err:XUST0001].
The ReturnClause may contain any category of expression.
The semantics of all clauses other than the ReturnClause are as specified in Section 3.10 FLWOR Expressions XQ30. These clauses generate a stream of tuples of bound variables.
The result of the FLWOR expression is the concatenation of the
XDM instances and
pending update lists returned by
evaluating the ReturnClause on each tuple generated by the previous step.
Pending update lists are concatenated by the
upd:mergeUpdates
operation.
Note:
In the event of incompatible updates, the upd:mergeUpdates
operation may raise an error,
as described in [8.2.2 upd:mergeUpdates].
Update an inventory of parts according to a set of changes provided in the bound variable
$changes
. Both /inventory
and $changes
contain a set of part
elements, each with a partno
and a quantity
.
for $p in /inventory/part let $deltap := $changes/part[partno eq $p/partno] return replace value of node $p/quantity with $p/quantity + $deltap/quantity
[75] | TypeswitchExpr |
::= | "typeswitch" "(" Expr ")" CaseClause+ "default" ("$" VarName)? "return" ExprSingle |
[76] | CaseClause |
::= | "case" ("$" VarName "as")? SequenceTypeUnion "return" ExprSingle |
[77] | SequenceTypeUnion |
::= | SequenceType ("|" SequenceType)* |
The syntax of the typeswitch expression is not changed.
The return expressions in the CaseClauses and default
clause are called
branches, and the expression in parentheses after the keyword typeswitch
is called
the test.
If all branches of the typeswitch expression are simple expressions, then the typeswitch expression is a simple expression.
If any branch of the typeswitch expression is an updating expression, then the typeswitch expression is an updating expression.
If test is an updating expression, an error is raised [err:XUST0001].
The branches of a typeswitch expression can be expressions of any category.
Selection of the effective case and binding of variables are performed as specified
in
Section
3.16.2 Typeswitch
XQ30. The expression in the return
clause of the effective case (or default) is then evaluated, resulting in
an XDM instance and
pending update list, which serves as the result of
the typeswitch expression.
[72] | SwitchExpr |
::= | "switch" "(" Expr ")" SwitchCaseClause+ "default" "return" ExprSingle |
[73] | SwitchCaseClause |
::= | ("case" SwitchCaseOperand)+ "return" ExprSingle |
[74] | SwitchCaseOperand |
::= | ExprSingle |
The syntax of the switch expression is not changed.
The return expressions in the CaseClauses and default
clause are called
branches, and the expression in parentheses after the keyword switch
is called
the test.
If all branches of the switch expression are simple expressions, then the typeswitch expression is a simple expression.
If any branch of the switch expression is an updating expression, then the switch expression is an updating expression.
If test or a SwitchCaseOperand is an updating expression, an error is raised [err:XUST0001].
The branches of a switch expression can be expressions of any category.
Selection of the effective case is
performed as specified in Section
3.13 Switch Expression
XQ30. The expression in the return
clause of the effective case (or default) is then evaluated, resulting in
an XDM instance and
pending update list, which serves as the result of
the switch expression.
[78] | IfExpr |
::= | "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle |
The syntax of conditional expression is not changed.
The operands of the then
and else
clauses are called
branches, and the expression in parentheses after the keyword if
is called
the test.
If all branches of the conditional expression are simple expressions, then the conditional expression is a simple expression.
If any branch of the conditional expression is an updating expression, then the conditional expression is an updating expression.
If test is an updating expression, an error is raised [err:XUST0001].
The branches of a conditional expression can be expressions of any category.
Selection of the effective branch performed as specified in Section 3.12 Conditional Expressions XQ30. The result of the conditional expression is the XDM instance and pending update list returned by the selected branch.
If the element bound to variable $e
has a last-updated
attribute, update its value to the current date; otherwise insert such an attribute.
if ($e/@last-updated) then replace value of node $e/last-updated with fn:currentDate() else insert node attribute last-updated {fn:currentDate()} into $e
[79] | TryCatchExpr |
::= | TryClause CatchClause+ |
[80] | TryClause |
::= | "try" "{" TryTargetExpr "}" |
[81] | TryTargetExpr |
::= | Expr |
[82] | CatchClause |
::= | "catch" CatchErrorList "{" Expr "}" |
[83] | CatchErrorList |
::= | NameTest ("|" NameTest)* |
If the TryTargetExpr and all of the catch expressions are simple expressions, then the try/catch expression is a simple expression.
If the TryTargetExpr or one of the catch expressions is an updating expression, then the conditional expression is an updating expression.
If the TryTargetExpr and all of the catch expressions can be expressions of any category.
The TryTargetExpr is evaluated, resulting in a pending update list or raising an error. If a pending update list is returned, it is checked for compatibility using upd:compatibilityCheck, which may also raise an error. If an error has not been raised, the result of the try/catch expression is the XDM instance and pending update list returned by it. However if it raises an error the result of the try/catch expression is the XDM instance and pending update list returned by executing the CatchClause matching the error, as defined in Section 3.15 Try/Catch Expressions XQ30.
Note:
Since the pending update list is considered part of the result of an expression, an error raised while executing the TryTargetExpr results in no update operations being returned from the execution of that expression.
[40] | Expr |
::= | ExprSingle ("," ExprSingle)* |
The comma expressions is composed of one or more expressions concatenated by the comma operator, as described in Section 3.4.1 Constructing Sequences XQ30.
If the operand expressions of the comma expression are simple expressions, then the comma expression is a simple expression.
If any of the operand expressions of the comma expression is an updating expression, then the comma expression is an updating expression.
The operand expressions of a comma expression can be expressions of any category.
The operand expressions of the comma expression are evaluated, and the
XDM instances and
pending update lists returned are concatenated
in operand order.
Pending update lists are concatenated by the
upd:mergeUpdates
operation.
This example makes the value of an element empty and gives the element an xsi:nil="true"
attribute. Both of these operations may be necessary in order to preserve the validity
of the element.
let $q := /inventory/item[serialno = "123456"]/quantity return ( replace value of node $q with ( ), insert node attribute xsi:nil {"true"} into $q )
[131] | ParenthesizedExpr |
::= | "(" Expr? ")" |
The category of a parenthesized expression is the same as the category of the expression enclosed in parentheses, which may have any category.
The result of a parenthesized expression is the same as the result of the expression enclosed in parentheses.
[105] | ExtensionExpr |
::= | Pragma+ "{" Expr? "}" |
The category of an extension (pragma) expression is the same as the category of the enclosed expression, which may have any category.
The result of an extension (pragma) expression is the same as the result of the enclosed expression.
[167] | InlineFunctionExpr |
::= | Annotation* "function" "(" ParamList? ")" ("as" SequenceType)? FunctionBody |
[36] | FunctionBody |
::= | EnclosedExpr |
The %simple
and %updating
annotations can be specified at the start of the inline
function expression, to force the creation of a simple or
updating function repectively.
If neither %simple
nor %updating
is specified:
The FunctionBody can be an expression of any category.
If the FunctionBody is an updating expression, the inline function expression is a simple expression, returning an updating function.
If the FunctionBody is a simple expression, the inline function expression is a simple expression, returning a simple function.
If %simple
is specified:
The FunctionBody must not be an updating expression [err:XUST0001]
The inline function expression is a simple expression, returning a simple function.
If %updating
is specified:
The FunctionBody can be an expression of any category.
The inline function expression is a simple expression, returning an updating function.
It is a static error to use more than one %updating
or %simple
annotation in a given annotation set [err:XUST0033].
[135] | FunctionCall |
::= | EQName ArgumentList |
[123] | ArgumentList |
::= | "(" (Argument ("," Argument)*)? ")" |
[136] | Argument |
::= | ExprSingle | ArgumentPlaceholder |
[137] | ArgumentPlaceholder |
::= | "?" |
Function calls can either be a partial function applicationXQ30 or not.
If the function call is a partial function applicationXQ30 of an updating function, then it is a simple expression returning an updating function.
If the function call is a partial function applicationXQ30 of a simple function, then it is a simple expression returning an simple function.
A function call of a simple function is a simple expression.
A function call of an updating function is an updating expression.
The argument expressionsXQ30 of a function call or partial function applicationXQ30 can be expressions of any category.
The function call is evaluated as specified in Section 3.1.5 Static Function Calls XQ30. All pending update lists returned by the evaluation of argument expressionsXQ30 are concatenated with the pending update list returned by evaluating the function to form the pending update list returned from the function call expression.
[122] | PostfixExpr |
::= | PrimaryExpr (Predicate | ArgumentList)* |
[123] | ArgumentList |
::= | "(" (Argument ("," Argument)*)? ")" |
[136] | Argument |
::= | ExprSingle | ArgumentPlaceholder |
[137] | ArgumentPlaceholder |
::= | "?" |
Dynamic function invocation can either be a partial function applicationXQ30 or not.
A dynamic function invocation is a simple expression.
The PrimaryExpr and the argument expressionsXQ30 of a dynamic function invocation can be expressions of any category.
The dynamic function invocation is evaluated as specified in Section 3.2.2 Dynamic Function Call XQ30.
If the function returned by the PrimaryExpr is an updating function, and the dynamic function invocation is not a partial function applicationXQ30, a dynamic error is raised [err:XUDY0038]. To perform dynamic function invocation of an updating function, [5.5 Dynamic Updating Function Invocation] should be used.
All pending update lists returned by the evaluation of the PrimaryExpr or argument expressionsXQ30 are concatenated to form the pending update list returned from the dynamic function invocation expression.
[140] | DirElemConstructor |
::= | "<" QName DirAttributeList ("/>" | (">" DirElemContent* "</" QName S? ">")) |
[141] | DirAttributeList |
::= | (S (QName S? "=" S? DirAttributeValue)?)* |
[151] | CDataSection |
::= | "<![CDATA[" CDataSectionContents "]]>" |
[149] | DirPIConstructor |
::= | "<?" PITarget (S DirPIContents)? "?>" |
[147] | DirCommentConstructor |
::= | "<!--" DirCommentContents "-->" |
[155] | CompElemConstructor |
::= | "element" (EQName | ("{" Expr "}")) "{" ContentExpr? "}" |
[157] | CompAttrConstructor |
::= | "attribute" (EQName | ("{" Expr "}")) "{" Expr? "}" |
[154] | CompDocConstructor |
::= | "document" "{" Expr "}" |
[162] | CompTextConstructor |
::= | "text" "{" Expr "}" |
[164] | CompPIConstructor |
::= | "processing-instruction" (NCName | ("{" Expr "}")) "{" Expr? "}" |
[163] | CompCommentConstructor |
::= | "comment" "{" Expr "}" |
If all operand expressions of the node constructor are simple expressions then the node constructor is a simple expression.
If any operand expression of the node constructor is an updating expression then the node constructor is an updating expression.
The operand expressions of a node constructor may be expressions of any category.
The pending update lists
returned by each of the operand expressions
are merged by calling upd:mergeUpdates
, and returned as the
pending update list
part of the result of the node constructor.
All other XQuery expressions not listed in the sections preceeding this are extended as follows:
The expression is a simple expression.
If an operand expression of the expresion is an updating expression, a static error is raised [err:XUST0001].