This document is also available in these non-normative formats: XML and Recent revisions (HTML).
Copyright © 2017 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and document use rules apply.
This document defines an update facility that extends the XML Query language, XQuery. The XQuery Update Facility 3.0 provides expressions that can be used to make persistent changes to instances of the XQuery and XPath Data Model 3.0.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.
This document is governed by the 1 September 2015 W3C Process Document.
This is a Working Group Note as described in the Process Document. It was developed by the W3C XML Query Working Group, which is part of the XML Activity.
This is a Working Group Note of XQuery Update Facility 3.0. There are no substantive changes from the previous Working Draft. The reason for publishing this Note is to provide the XQuery Update grammar fully integrated with the XQuery 3.0 grammar.
This document incorporates changes made against the previous publication of the Working Draft. Changes to this document since the previous publication of the Working Draft are detailed in [H Revision Log].
Please report errors in this document using W3C's public Bugzilla system (instructions can be found at https://www.w3.org/XML/2005/04/qt-bugzilla). If access to that system is not feasible, you may send your comments to the W3C XSLT/XPath/XQuery public comments mailing list, public-qt-comments@w3.org. It will be very helpful if you include the string “[UPD30]” in the subject line of your report, whether made in Bugzilla or in email. Please use multiple Bugzilla entries (or, if necessary, multiple email messages) if you have more than one comment to make. Archives of the comments and responses are available at https://lists.w3.org/Archives/Public/public-qt-comments/.
Publication as a Working Group Note does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document defines the syntax and semantics of an extension to [XQuery 3.0: An XML Query Language] called the XQuery Update Facility 3.0. This language extension is designed to meet the requirements for updating instances of the [XQuery and XPath Data Model (XDM) 3.0], as defined in [XQuery Update Facility 3.0 Requirements and Use Cases].
The XQuery Update Facility 3.0 provides facilities to perform any or all of the following operations on an XDM instance:
Insertion of a node.
Deletion of a node.
Modification of a node by changing some of its properties while preserving its node identity.
Creation of a modified copy of a node with a new node identity.
Additionally, this document defines an XML syntax for the XQuery Update Facility 3.0. The most recent versions of the two XQueryX XML Schemas and the XQueryX XSLT stylesheet for the XQuery Update Facility 3.0 are available at http://www.w3.org/2015/02/xquery-update-30/xquery-update-30-xqueryx.xsd, http://www.w3.org/2015/02/xquery-update-30/xquery-update-30-xqueryx-redef.xsd, and http://www.w3.org/2015/02/xquery-update-30/xquery-update-30-xqueryx.xsl, respectively.
[Definition: Within this document, the term XQuery 3.0 refers to the language specified by [XQuery 3.0: An XML Query Language].] [Definition: The term data model refers to the data model specified by [XQuery and XPath Data Model (XDM) 3.0].] [Definition: The term XDM instance denotes an unconstrained sequence of zero or more nodes and/or atomic values as defined by the data model.] [Definition: The term node identity denotes the unique identity that is a property of every node in an XDM instance (see Section 2.3 Node Identity DM30.)]
As described in Section 3.3.3 QNames and NOTATIONS DM30, names in XQuery are qualified names (QNames) that consist of an optional namespace prefix, a local name, and an optional namespace URI. [Definition: The implied namespace binding of a QName is the association of its namespace prefix (or absence thereof) with its namespace URI (or absence thereof).] [Definition: Two namespace bindings are said to conflict if their namespace prefixes (or absence thereof) are the same but their namespace URI's (or absence thereof) are different.] Update operations that result in conflicting namespace bindings generally raise errors, as described in this document. However, if the namespace prefix of an attribute is absent, it is in no namespace, and its implied namespace binding is not added to the namespace bindings of its parent element. Therefore, an update operation can create such an attribute in an element even though its implied namespace binding conflicts with a namespace binding in the "namespaces" property of the element.
In this document, examples and material labeled as "Note" are provided for explanatory purposes and are not normative.
Expressions in XQuery Update Facility 3.0 can return a pending update list in addition to an XDM instance, which can result in modifications being made to the state of existing nodes. This specification defines the semantics of updates to an XDM instance. Propagation of these updates to an underlying persistent store (if any) is beyond the scope of this specification.
[Definition: A pending update list is an unordered collection of update primitives, which represent node state changes that have not yet been applied. ] The term "result" used in Section 2.3.4 Errors and Optimization XQ30 includes both the XDM instance and the pending update list returned by an expression.
XQuery Update Facility 3.0 relaxes many of the constraints placed on the position of updating expressions in [XQuery Update Facility 1.0] with the goal of allowing expressions to return both a non-empty pending update list and a non-empty XDM instance. Existing expressions are extended with new rules to determine the category and resulting pending update list when they are executed.
XQuery Update Facility 3.0 introduces a new category of expression, called an updating expression. Unlike expressions defined in [XQuery 3.0: An XML Query Language], updating expressions can potentially result in the modification of the state of an existing node. [Definition: An updating expression is an expression that can return a non-empty pending update list. This includes basic updating expressions, static function calls to an updating function, or any expression that directly contains an updating expression (other than the modify expression of a copy modify or transform with expression). ] [Definition: A simple expression is any XQuery expression that is not an updating expression. ]
The classification of each expression into one of the above categories is performed by static analysis, according to rules specified in this document for each type of expression.
[Definition: Five new kinds of expressions named basic updating expression are introduced, including insert, delete, replace, rename, and dynamic updating function invocation expressions. Basic updating expression are always classified as updating expressions. ] In addition two new kinds of expressions named transform with, and copy modify expressions can apply pending update lists to copies of nodes. These expressions are usually classified as simple expressions rather than updating expressions.
[Definition: An updating function is a functionDM30 which can return a non-empty pending update list when called. ] [Definition: If a function is not an updating function, then it is a simple function. ]
| [26] | AnnotatedDecl |
::= | "declare" (CompatibilityAnnotation | Annotation)* (VarDecl | FunctionDecl) |
| [27] | CompatibilityAnnotation |
::= | "updating" |
| [28] | Annotation |
::= | "%" EQName ("(" Literal ("," Literal)* ")")? |
| [167] | InlineFunctionExpr |
::= | Annotation* "function" "(" ParamList? ")" ("as" SequenceType)? FunctionBody |
XQuery Update Facility 3.0 defines the %updating annotation which can be used to declare an updating function. The bare keyword updating is
also allowed on a function declared in the prolog for backwards compatibility with
XQuery Update 1.0, and behaves
exactly as if the %updating annotation was specified instead.
For completeness, the %simple annotation is also defined. This can be used to explicitly label
a simple function. A FunctionDecl
without an %updating or %simple annotation is also considerd a
simple function.
If an %updating or %simple annotation is used on a VarDecl
a static error is raised [err:XUST0032].
It is a static error to use more than one %updating or %simple annotation in a given annotation set [err:XUST0033].
| [193] | FunctionTest |
::= | Annotation* (AnyFunctionTest |
| [194] | AnyFunctionTest |
::= | "function" "(" "*" ")" |
| [195] | TypedFunctionTest |
::= | "function" "(" (SequenceType ("," SequenceType)*)? ")" "as" SequenceType |
[Definition: An updating function assertion is a function assertionXQ30 that can be used to control how a FunctionTest matches updating functions. ] Updating function assertions can be added to either allow, prohibit, or require an updating function that matches the FunctionTest. The updating function assertions defined are as follows:
| Function Assertion | Matching Behaviour | Default? |
|---|---|---|
%simple, or %updating("prohibited") |
Matches only simple functions | true |
%updating, or %updating("allowed") |
Matches both simple functions and updating functions | false |
%updating("required") |
Matches only updating functions | false |
A FunctionTest without an updating function assertion only matches simple functions as it does in unextended XQuery 3.0.
It is a static error to use more than one updating function assertion in the function assertionXQ30 set of a FunctionTest [err:XUST0034].
XQuery Update Facility 3.0 also defines a set of update operations. [Definition: Update operations are used in defining the semantics of XQuery updates, but are not directly available to users. Update operations are defined in [8 Update Operations]. ] Update operations fall into the following categories:
[Definition: Update primitives are the components of pending update lists. Each update primitive represents a node state change that has not yet been applied. ] [Definition: The first argument of an update primitive, called its target node, is the principal node to be affected by the update primitive. ] Update primitives are held on pending update lists until they are made effective by a upd:applyUpdates operation.
[Definition: Update routines are sequences of actions that are used in the definition of XQuery semantics but do not appear on pending update lists. ] upd:applyUpdates is an example of an update routine.
If the outermost expression in a query returns a non-empty pending update list, upd:applyUpdates is implicitly invoked, supplying as arguments (a) the pending update list, and (b) the value of the revalidation mode in the static context of the main module. This invocation of upd:applyUpdates may raise an error (see [8.2.3 upd:applyUpdates] for possible error codes.)
[Definition: A snapshot is a scope within which expressions are evaluated with respect to a fixed XDM instance and updates are held pending. ] A snapshot is terminated by invocation of the upd:applyUpdates operation. XQuery Update Facility 3.0 defines an entire query as one snapshot.
In general, updating expressions cause a loss of type information from nodes that are affected by the update. Type information for these nodes may be recovered by a revalidation process at the end of the snapshot. Revalidation is defined by the upd:revalidate update routine. More information about type loss during update operations can be found in [8.1 Update Primitives], as well as [8.2.5 upd:removeType].
The following definitions are added to the XQuery static context (documented in Section 2.1.1 Static Context XQ30):
[Definition:
Revalidation mode, which may be strict, lax, or skip,
is a component of the static context that controls the behavior of the
upd:revalidate operation.
]
Support for each of the three revalidation modes is implementation-defined; however, an implementation must support at least one of the three revalidation modes. If a [4.1 Revalidation Declaration] specifies a revalidation mode that is not supported by the current implementation, a static error is raised [err:XUST0026].
The table of static context components Section C.1 Static Context Components XQ30 is augmented with the following new row:
Component: Revalidation mode
Default initial value: lax.
Can be overwritten or augmented by an implementation: Overwritable (implementation defined.)
Can be overwritten or augmented by prolog: Overwritable using a prolog declaration.
Can be overwritten or augmented by expressions: No.
Consistency rules: Must be strict, lax, or skip.
| [8] | Setter |
::= | BoundarySpaceDecl | DefaultCollationDecl | BaseURIDecl | ConstructionDecl | OrderingModeDecl | EmptyOrderDecl | RevalidationDecl | CopyNamespacesDecl | DecimalFormatDecl |
| [198] | RevalidationDecl |
::= | "declare" "revalidation" ("strict" | "lax" | "skip") |
The Prolog is extended by adding a new kind of Setter called a revalidation declaration. [Definition: A revalidation declaration sets the revalidation mode in the static context of the module, overriding any implementation-defined default.] If a Prolog contains more than one revalidation declaration, a static error is raised [err:XUST0003]. Revalidation mode controls the process by which type information is recovered for an updated document, as described in [8.2.4 upd:revalidate]
| [26] | AnnotatedDecl |
::= | "declare" (CompatibilityAnnotation | Annotation)* (VarDecl | FunctionDecl) |
| [33] | FunctionDecl |
::= | "function" EQName "(" ParamList? ")" ("as" SequenceType)? (FunctionBody | "external") |
| [36] | FunctionBody |
::= | EnclosedExpr |
Functions can be declared as updating functions using the
%updating annotation, or the equivalent backwards-compatible bare keyword updating.
The built-in function fn:put is also specified as an
updating function.
If a function is not declared with the %updating annotation, or if it is
declared with the %simple annotation it is a
simple function.
If a simple function is not declared as
external, its FunctionBody must be a
simple expression [err:XUST0001].
If a simple function is declared as
external, evaluation of the external function must not return a non-empty
pending update list; otherwise a dynamic error
is raised [err:XUDY0018].
An updating function may have a FunctionBody of any category.
XQuery Update Facility 3.0 allows an updating function to return both a non-empty pending update list and a non-empty XDM instance.
If the result of an updating function
does not match its declared return type (after applying function conversion rules
as specified in Section
3.1.5 Function CallsXQ), a type error is raised [err:XPTY0004]XQ30.
The default return type of an updating function
is item()*.
The means by which an external function returns an XDM instance or a pending update list is implementation-defined.
This function takes an element, a QName, and an atomic value. If the given element has an attribute with the given QName, the function updates the attribute with the given value; otherwise it inserts a new attribute with the given name and value.
declare %updating function
upsert($e as element(),
$an as xs:QName,
$av as xs:anyAtomicType)
{
let $ea := $e/attribute()[fn:node-name(.) = $an]
return
if (fn:empty($ea))
then insert node attribute {$an} {$av} into $e
else replace value of node $ea with $av
}| [26] | AnnotatedDecl |
::= | "declare" (CompatibilityAnnotation | Annotation)* (VarDecl | FunctionDecl) |
| [29] | VarDecl |
::= | "variable" "$" VarName TypeDeclaration? ((":=" VarValue) | ("external" (":=" VarDefaultValue)?)) |
| [30] | VarValue |
::= | ExprSingle |
| [31] | VarDefaultValue |
::= | ExprSingle |
The VarValue or VarDefaultValue of a variable declaration must be a simple expression [err:XUST0001].
| [32] | ContextItemDecl |
::= | "declare" "context" "item" ("as" ItemType)? ((":=" VarValue) | ("external" (":=" VarDefaultValue)?)) |
| [30] | VarValue |
::= | ExprSingle |
| [31] | VarDefaultValue |
::= | ExprSingle |
The VarValue or VarDefaultValue of a context item declaration must be a simple expression [err:XUST0001].
| [41] | ExprSingle |
::= | FLWORExpr |
| [108] | SimpleMapExpr |
::= | PathExpr ("!" PathExpr)* |
XQuery Update Facility 3.0 adds eight new kinds of expressions. The syntax and semantics of these expressions are described in the following sections.
| [200] | InsertExpr |
::= | "insert" ("node" | "nodes") SourceExpr InsertExprTargetChoice TargetExpr |
| [199] | InsertExprTargetChoice |
::= | (("as" ("first" | "last"))? "into") |
| [204] | SourceExpr |
::= | ExprSingle |
| [205] | TargetExpr |
::= | ExprSingle |
An insert expression inserts copies of zero or more nodes into a
designated position with respect to a target node. The keywords node and nodes may be used interchangeably, regardless of how many nodes are actually inserted.
The position of the inserted nodes is determined as follows:
If before (or after) is specified:
The inserted nodes become the preceding (or following) siblings of the target node.
If multiple nodes are inserted by a single insert expression, the nodes remain adjacent and their order preserves the node ordering of the source expression.
If multiple groups of nodes are inserted by multiple insert expressions in the same snapshot, adjacency and ordering of nodes within each group is preserved but ordering among the groups is implementation-dependent.
If as first into (or as last into) is specified:
The inserted nodes become the first (or last) children of the target node.
If multiple nodes are inserted by a single insert expression, the nodes remain adjacent and their order preserves the node ordering of the source expression.
If multiple groups of nodes are inserted by multiple insert expressions in the same snapshot, adjacency and ordering of nodes within each group is preserved but ordering among the groups is implementation-dependent.
If into is specified without as first or as last:
The inserted nodes become children of the target node.
If multiple nodes are inserted by a single insert expression, their order preserves the node ordering of the source expression.
The positions of the inserted nodes are chosen so as not to interfere with the intended
position of nodes that are inserted with the specification before, after,
as first into, or as last into. For example, If node B is inserted "after node A",
no other node will be inserted between nodes A and B unless it is also
inserted "after node A".
Subject to the above constraints, the positions of the inserted nodes among the children of the target node are implementation-dependent.
An insert expression is an updating expression.
The SourceExpr and TargetExpr can be expressions of any category.
SourceExpr is evaluated as though it were an enclosed
expression in an element constructor (see Rule 1e in Section
3.9.1.3 Content
XQ30). The result of this step is either an error or a
sequence of nodes to be inserted, called the insertion sequence. If the insertion sequence contains a document node, the document node is replaced
in the insertion sequence by its children. If the insertion sequence contains an attribute
node following a node that is not an attribute node, a type error is raised [err:XUTY0004]. Let $alist be the sequence of attribute nodes in the insertion sequence. Let $clist be the remainder of the insertion sequence, in its original order.
Note:
Either $alist or $clist or both may be empty.
TargetExpr is evaluated and checked as follows:
If the result is an empty sequence, [err:XUDY0027] is raised.
If any form of into is specified,
the result must be a single element or document node; any other non-empty result raises
a type error [err:XUTY0005].
If before or after
is specified, the result must be a single element, text, comment, or processing instruction
node; any other non-empty result raises a type error [err:XUTY0006].
If before or after
is specified, the node returned by the target expression must have a non-empty parent property [err:XUDY0029].
Let
$target be the node returned by the target expression.
If $alist is not empty and any form of into is specified, the following checks are performed:
$target must be an element node [err:XUTY0022].
No attribute node in $alist may have a QName whose implied namespace binding conflicts with a namespace binding in the "namespaces" property of $target [err:XUDY0023].
Multiple attribute nodes in $alist may not have QNames whose implied namespace bindings conflict with each other [err:XUDY0024].
If $alist is not empty and before or after is specified, the following checks are performed:
parent($target) must be an element node [err:XUDY0030].
No attribute node in $alist may have a QName whose implied namespace binding conflicts with a namespace binding in the "namespaces" property of parent($target) [err:XUDY0023].
Multiple attribute nodes in $alist may not have QNames whose implied namespace bindings conflict with each other [err:XUDY0024].
The result of the insert expression is an empty XDM instance and a pending update list constructed by merging the pending update lists returned by the SourceExpr and TargetExpr with the following update primitives using upd:mergeUpdates:
If as first into is specified, the pending update list includes the following update primitives:
If $alist is not empty, upd:insertAttributes($target, $alist)
If $clist is not empty, upd:insertIntoAsFirst($target, $clist)
If as last into is specified, the pending update list includes the following update primitives:
If $alist is not empty, upd:insertAttributes($target, $alist)
If $clist is not empty, upd:insertIntoAsLast($target, $clist)
If into is specified with neither as first nor as last, the pending update list includes the following update primitives:
If $alist is not empty, upd:insertAttributes($target, $alist)
If $clist is not empty, upd:insertInto($target, $clist)
If before is specified, let $parent be the parent node of $target. The pending update list includes the following update primitives:
If $alist is not empty, upd:insertAttributes($parent, $alist)
If $clist is not empty, upd:insertBefore($target, $clist)
If after is specified, let $parent be the parent node of $target. The pending update list includes the following update primitives:
If $alist is not empty, upd:insertAttributes($parent, $alist)
If $clist is not empty, upd:insertAfter($target, $clist)
Insert a year element after the publisher of the first book.
insert node <year>2005</year>
after fn:doc("bib.xml")/books/book[1]/publisherNavigating by means of several bound variables, insert a new police report into the list of police reports for a particular accident.
insert node $new-police-report
as last into fn:doc("insurance.xml")/policies
/policy[id = $pid]
/driver[license = $license]
/accident[date = $accdate]
/police-reports| [201] | DeleteExpr |
::= | "delete" ("node" | "nodes") TargetExpr |
| [205] | TargetExpr |
::= | ExprSingle |
A delete expression deletes zero or more nodes from an XDM instance.
The keywords node and nodes may be used interchangeably, regardless of how many nodes are actually deleted.
A delete expression is an updating expression.
The TargetExpr can be an expression of any category.
TargetExpr is evaluated. The result must be a
sequence of zero or more nodes; otherwise a type error is raised [err:XUTY0007].
Let $tlist be the list of nodes returned by
the target expression.
If any node in $tlist has no parent,
it is removed from $tlist (and is thus ignored in the following step).
A new pending update list is created. For each node
$tnode in $tlist, the following
update primitive is appended to the pending update list:
upd:delete($tnode). The resulting pending update list
is merged with the pending update list returned
by the TargetExpr using upd:mergeUpdates, and
together with an empty XDM instance forms the result of the delete expression.
Delete the last author of the first book in a given bibliography.
delete node fn:doc("bib.xml")/books/book[1]/author[last()]Delete all email messages that are more than 365 days old.
delete nodes /email/message
[fn:currentDate() - date > xs:dayTimeDuration("P365D")]Notes:
Since node deletions do not become effective until the end of a snapshot, they have no effect on variable bindings or on the set of available documents or collections within the current query.
The semantics of a delete expression are defined in terms of their effect on an XDM instance: the deleted nodes are detached from their parents after completion of the current query. The effects of a delete expression on persistent storage are beyond the scope of this specification.
| [202] | ReplaceExpr |
::= | "replace" ("value" "of")? "node" TargetExpr "with" ExprSingle |
| [205] | TargetExpr |
::= | ExprSingle |
A replace expression has two forms, depending on whether value of is specified.
If value of is not specified, a replace expression
replaces one node with a new sequence of zero or more nodes. The replacement nodes
occupy the position in the node hierarchy that was formerly occupied by the node that
was replaced. For this reason, an attribute node can be replaced only by zero or more
attribute nodes, and an element, text, comment, or processing instruction node can
be replaced only by zero or more element, text, comment, or processing instruction
nodes.
A replace expression without value of specified is an updating expression.
The TargetExpr and expression following the keyword with can be
expressions of any category.
The expression following the keyword with is evaluated as though it were an enclosed
expression in an element constructor (see Rule 1e in Section
3.9.1.3 Content
XQ30). Let $rlist be the node sequence that results from this evaluation. If $rlist contains a document node, the document node is replaced in $rlist by its children.
TargetExpr is evaluated and checked as follows:
If the result is an empty sequence, [err:XUDY0027] is raised.
If the result is non-empty and does not consist of a single element, attribute, text, comment, or processing instruction node, [err:XUTY0008] is raised.
If the result consists of a node whose parent property is empty, [err:XUDY0009] is raised.
Let
$target be the node returned by the target expression, and let $parent be its parent node.
If $target is an element, text, comment, or processing
instruction node, then $rlist must consist exclusively of zero or more element, text, comment, or processing instruction
nodes [err:XUTY0010].
If $target is an attribute node, then:
$rlist must consist exclusively of zero or more attribute nodes [err:XUTY0011].
No attribute node in $rlist may have a QName whose implied namespace binding conflicts with a namespace binding in the "namespaces" property of $parent [err:XUDY0023].
Multiple attribute nodes in $rlist may not have QNames whose implied namespace bindings conflict with each other [err:XUDY0024].
The result of the replace expression is an empty XDM instance
and a pending update list
constructed
by merging the pending update lists returned
by the TargetExpr and the expression following the keyword with
with the following update primitives
using upd:mergeUpdates:
upd:replaceNode($target, $rlist)
Replace the publisher of the first book with the publisher of the second book.
replace node fn:doc("bib.xml")/books/book[1]/publisher
with fn:doc("bib.xml")/books/book[2]/publisherIf value of is specified,
a replace expression is used to modify the value of a node while preserving
its node identity.
A replace expression with value of specified is an updating expression.
The TargetExpr and expression following the keyword with can be
expressions of any category.
The expression following the keyword with is evaluated as though it were the content
expression of a text node constructor (see Section 3.7.3.4 of
[XQuery 3.0: An XML Query Language].) The result of this step, in the absence of errors, is
either a single text node or an empty sequence. Let $text be the result of this step.
TargetExpr is evaluated and checked as follows:
If the result is an empty sequence, [err:XUDY0027] is raised.
If the result is non-empty and does not consist of a single element, attribute, text, comment, or processing instruction node, [err:XUTY0008] is raised.
Let
$target be the node returned by the target expression.
If $target is an element node, the result of the replace
expression is an empty XDM instance and a
pending update list
constructed
by merging the pending update lists returned
by the TargetExpr and the expression following the keyword with
with the following update primitives
using upd:mergeUpdates:
upd:replaceElementContent($target, $text)
If $target is an attribute, text, comment, or processing
instruction node, let $string be the string value of the text node
constructed in Step 1. If Step 1 did not construct
a text node, let $string be a zero-length string.
Then:
If $target is a comment node, and $string contains two adjacent hyphens or ends with a hyphen, a dynamic error is raised [err:XQDY0072].
If $target is a processing instruction node, and $string contains the substring "?>", a dynamic error is raised [err:XQDY0026].
In the absence of errors, the result of a replace expression is an empty
XDM instance and a
pending update list
constructed
by merging the pending update lists returned
by the TargetExpr and the expression following the keyword with
with the following update primitives
using upd:mergeUpdates:
upd:replaceValue($target, $string).
Increase the price of the first book by ten percent.
replace value of node fn:doc("bib.xml")/books/book[1]/price
with fn:doc("bib.xml")/books/book[1]/price * 1.1| [203] | RenameExpr |
::= | "rename" "node" TargetExpr "as" NewNameExpr |
| [205] | TargetExpr |
::= | ExprSingle |
| [206] | NewNameExpr |
::= | ExprSingle |
A rename expression replaces the name property of a data model node with a
new QName.
A rename expression is an updating expression.
The NewNameExpr and TargetExpr can be expressions of any category.
TargetExpr is evaluated and checked as follows:
If the result is an empty sequence, [err:XUDY0027] is raised.
If the result is non-empty and does not consist of a single element, attribute, or processing instruction node, [err:XUTY0012] is raised.
Let
$target be the node returned by the target expression.
NewNameExpr is processed as follows:
If $target is an element node, let $QName be the result of evaluating
NewNameExpr as though it were the name expression of a computed element
constructor (see Section
3.9.3.1 Computed Element Constructors
XQ30). If the namespace binding of $QName
conflicts with any namespace binding in the namespaces property of $target, a
dynamic error is raised [err:XUDY0023].
If $target is an attribute node, let $QName be the result of evaluating
NewNameExpr as though it were the name expression of a computed attribute
constructor (see Section
3.9.3.2 Computed Attribute
Constructors
XQ30). If $QName has a non-absent namespace URI, and if the namespace binding of $QName
conflicts with any namespace binding in the namespaces property of the parent
(if any) of $target, a dynamic error is raised [err:XUDY0023].
If $target is a processing instruction node, let $NCName be the result of
evaluating NewNameExpr as though it were the name expression of a computed
processing instruction constructor (see Section
3.9.3.5 Computed Processing Instruction Constructors
XQ30), and let $QName be
defined as fn:QName((), $NCName).
The result of the rename expression is an empty XDM instance and a pending update list
constructed
by merging the pending update lists returned
by the NewNameExpr and TargetExpr
with the following update primitives
using upd:mergeUpdates:
upd:rename($target, $QName).
Rename the first author element of the first book to principal-author.
rename node fn:doc("bib.xml")/books/book[1]/author[1]
as "principal-author"Rename the first author element of the first book to the QName that is the value of the variable $newname.
rename node fn:doc("bib.xml")/books/book[1]/author[1]
as $newnameNote:
The effects of a rename expression are limited to its target node. Attributes and
descendants of the target node are not affected. If a global change of names or namespaces
is intended, some form of explicit iteration must be used. The following example illustrates
such a global change. The example operates on the node bound to variable $root and all its attributes and descendants, changing all QNames with the prefix abc to have a new prefix xyz and a new namespace URI http://xyz/ns.
for $node in $root//abc:*
let $localName := fn:local-name($node),
$newQName := fn:concat("xyz:", $localName)
return (
rename node $node as fn:QName("http://xyz/ns", $newQName),
for $attr in $node/@abc:*
let $attrLocalName := fn:local-name($attr),
$attrNewQName := fn:concat("xyz:", $attrLocalName)
return
rename node $attr as fn:QName("http://xyz/ns", $attrNewQName)
)| [207] | UpdatingFunctionCall |
::= | "invoke" "updating" PrimaryExpr "(" (ExprSingle ("," ExprSingle)*)? ")" |
A dynamic updating function call dynamically invokes an updating function. A dynamic updating function call is constrained by the grammar so that it cannot be a partial function applicationXQ30.
A dynamic updating function call is an updating expression.
The PrimaryExpr and any argument expressionsXQ30 can be expressions of any category.
A dynamic updating function call is evaluated like a dynamic function invocation, as specified in Section 3.2.2 Dynamic Function Call XQ30. However unlike [7.11 Dynamic Function Invocation] it can invoke either an updating function or a simple function, and could therefore potentially return a non-empty pending update list.
The result of the dynamic updating function call is the XDM instance returned by the function invoked, as well as a pending update list constructed by merging the pending update lists returned by the PrimaryExpr and any argument expressionsXQ30, with the pending update list returned by the function invoked using upd:mergeUpdates.
Dynamically call the fn:put() function.
let $f := fn:put#2 return invoke updating $f(<newnode/>,"newnode.xml")
| [208] | CopyModifyExpr |
::= | "copy" "$" VarName ":=" ExprSingle ("," "$" VarName ":=" ExprSingle)* "modify" ExprSingle "return" ExprSingle |
A copy modify expression can be used to create modified copies of existing nodes in an XDM instance. Each node created by a copy modify expression has a new node identity. The result of a copy modify expression is an XDM instance that may include both nodes that were created by the copy modify expression and other, previously existing nodes.
A copy modify expression consists of three clauses, denoted by the keywords copy, modify, and return.
If all of the copy modify expression's copy and return clauses have operand
expressions that are simple expressions,
then the copy modify expression is a simple expression.
If any of the copy modify expression's copy or return clauses have operand
expressions that are updating expressions,
then the copy modify expression is a updating expression.
The operand expressions of any of the clauses of a copy modify expression can be expressions of any category.
The copy clause contains one or more variable bindings, each of which consists of a variable
name and an expression called the source expression. Each variable binding is processed as follows:
The result of evaluating the source expression must be a single node [err:XUTY0013]. Let $node be this single node.
A new copy is made of $node and all nodes that have $node as an ancestor,
collectively referred to as copied nodes. Each copied node receives a new node
identity. The parent, children, and attributes properties of the copied nodes
are set so as to preserve their inter-node relationships.
The parent property of the copy of $node is set
to empty.
Other properties of the copied nodes are determined as follows:
For a copied document node, the document-uri property is set to empty.
For a copied element node, the type-name property is set to xs:untyped,
and the nilled, is-id, and is-idrefs properties are set to false.
For a copied attribute node, the type-name property is set to
xs:untypedAtomic and the is-idrefs property is set to false. The is-id property
is set to true if the qualified name of the attribute node is xml:id; otherwise
it is set to false.
The string-value of each copied element and attribute node remains
unchanged, and its typed value becomes equal to its string value as an instance
of xs:untypedAtomic.
Note:
Implementations that store only the typed value of a node are required at this point to convert the typed value to a string form.
If copy-namespaces mode in the static context specifies preserve, all in-scope-namespaces of the original element are
retained in the new copy. If copy-namespaces mode specifies no-preserve, the new copy retains only those in-scope namespaces of the original element that
are used in the names of the element and its
attributes.
All other properties of the copied nodes are preserved.
The variable name is bound to the top-level copied node generated in the previous step. The scope of this variable binding includes all subexpressions of the containing copy modify expression that appear after the variable binding clause, including the source expressions of later variable bindings, but it does not include the source expression to which the current variable name is bound.
The expression in the modify clause is evaluated, resulting in a
pending update list (denoted $pul)
and an XDM instance. The
XDM instance is discarded, and does not form part
of the result of the copy modify expression.
If the target node of any
update primitive in $pul is a node that
was not newly created in Step 1, a dynamic error is raised [err:XUDY0014].
If $pul contains a upd:put
update primitive, a dynamic error is raised
[err:XUDY0037].
Let $revalidation-mode be the value of
the revalidation mode in the static context of
the library or main module containing
the copy modify expression, and $inherit-namespaces be the
value of inherit-namespaces in the static context of the copy modify
expression.
The following update operation is invoked: upd:applyUpdates($pul, $revalidation-mode, $inherit-namespaces). The effect of this operation is to make the updates specified in the modify clause effective on the copied nodes.
Note:
In the event of incompatible updates, the upd:applyUpdates operation may raise an error, as described in [8.2.3 upd:applyUpdates].
The return clause is evaluated, resulting in a
pending update list
and an XDM instance.
The result of the copy modify expression is the
XDM instance returned, as well as a
pending update list constructed by
merging the pending update lists returned
by any of the copy modify expression's copy or return clause operand
expressions using upd:mergeUpdates.
During evaluation of the return clause, changes applied to copied nodes by the preceding
step are visible.
Return a sequence consisting of all employee elements that have Java as a skill, excluding their salary child-elements:
for $e in //employee[skill = "Java"] return copy $je := $e modify delete node $je/salary return $je
The following example copies a node, modifies the copy, and returns both the original node and the modified copy:
let $oldx := /a/b/x
return
copy $newx := $oldx
modify (rename node $newx as "newx",
replace value of node $newx with $newx * 2)
return ($oldx, $newx)
Note:
No persistent changes to the underlying data result from this example.
| [97] | TransformWithExpr |
::= | UnaryExpr ( "transform" "with" "{" Expr? "}" )? |
The TransformWithExpr is a convenient short hand for the common
use case of wanting to apply updates to a copy of a single node. If N and U are arbitrary
expressions, and $v is a variable name that is otherwise unused in U, then the
following TransformWithExpr:
N transform with { U }is equivalent to the following longer form CopyModifyExpr:
copy $v := N modify $v!(U) return $v
The rules defining compatibility of updating expressions within a snapshot are defined in [8.2.3 upd:applyUpdates].
Note:
The effect of these rules is as follows:
If any node is affected by more than one rename expression within a snapshot, a dynamic error is raised [err:XUDY0015].
If any node is affected by more than one replace expression (without value of being specified) within a snapshot, a dynamic error is raised [err:XUDY0016].
If any node is affected by more than one replace value of expression within a snapshot, a dynamic error is raised [err:XUDY0017].
If multiple calls to fn:put operate on the same URI in the same snapshot, a dynamic error is raised [err:XUDY0031].
Within a given snapshot, if an element node E is the target of a replace value of expression, and the children of E are also modified by other expressions, the final children of E are determined by the replace value of expression. For example:
Suppose that $A is bound to an element node that has a child element named B. Suppose that the following expressions are evaluated in the same snapshot:
replace node $A/B with <C>Hello</C>, replace value of node $A with <D>Goodbye</D>
The expressions on the left and right side of the comma can be evaluated in any order.
No error is raised. At the end of the snapshot, the children of $A will consist of a single text node with the content "Goodbye".
XQuery Update Facility 3.0 provides extensions to XQuery built-in function library, as specified in this section.
fn:put($node as node(), $uri as xs:string) as empty-sequence()fn:put($node as node(), $uri as xs:string, $params as element(output:serialization-parameters)?) as empty-sequence()The fn:put function stores a document or element to the location specified by $uri.
This function is normally invoked to create a resource on an external storage system
such as a file system or a
database.
The external effects of fn:put are implementation-defined,
since they occur outside the domain of XQuery. The intent is that, if fn:put is invoked on a document node and no error is raised, a
subsequent query can access the stored document by invoking fn:doc with the same URI.
The $params argument is used to identify a set of serialization parameters.
These are supplied in the form of an output:serialization-parameters element,
having the format described in Section
3.1 Setting Serialization Parameters by Means of a Data Model Instance
SER30.
The two-argument version of this function, or the three argument version with the
empty sequence as the third argument, are equivalent to passing an
output:serialization-parameters element with no child elements.
fn:put is an updating function.
If $node is not a document node or an element node, and the implementation does not support
fn:put on the given node kind, a dynamic error is
raised [err:FOUP0001].
If
$uri is not a valid lexical representation of the xs:anyURI type, a dynamic error is
raised [err:FOUP0002]. If $uri is a relative URI reference, it is resolved
relative to the value of the base URI property in the static
context.
An implementation that serializes $node during storage MUST use the
serialization parameters to determine how serialization is performed. In this case,
the implementation
should raise a dynamic error if setting the serialization parameters produces a serialization
error
or if an invalid parameter value is detected. An implementation may ignore the $params
argument (because it does not perform serialization) but must not raise an error because
serialization
parameters are specified.
The result of a call to fn:put is an empty XDM instance and a pending update list
containing the following update primitive:
upd:put($node,$uri,$params).
Notes:
The results of fn:put do not become effective until after completion of the current snapshot. The fn:put function has no effect on the set of available documents or collections seen by the
current snapshot.
If a node that is an operand of fn:put is affected by updating expressions in the current snapshot, the fn:put function operates on the node after these updating expressions are made effective.
As a result, after completion of the current snapshot, the effects of updates to $node can be seen via $uri. (For details on application of updates, see [8.2.3 upd:applyUpdates].)
If multiple calls to fn:put in the same snapshot operate on the same URI (after any necessary resolution of relative URIs), a dynamic
error [err:XUDY0031] is raised. The dynamic error is raised by an expression at some level of the query
that contains more than one call to fn:put. For a normative description of this error, see [8.2.2 upd:mergeUpdates] and [8.2.3 upd:applyUpdates].
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].
This section describes the update operations defined by XQuery Update Facility 3.0. Although these update operations are described using a functional notation, they are not true functions because many of them have no return value. These update operations are used in defining the semantics of XQuery expressions, but they are not directly available to users.
Update operations consist of update primitives, which are the components of pending update lists, and update routines, which are used in defining XQuery semantics but do not appear on pending update lists.
The update primitives described in this section may be held on pending update lists. When an update primitive is held on a pending update list, its node operands are
represented by their node identities. The semantics of an update primitive do not become effective until their pending
update list is processed by the upd:applyUpdates routine.
upd:insertBefore( $target as node(), $content as node()+)
Inserts $content immediately before $target.
$target must be an element, text, processing
instruction, or comment node with a non-empty parent property. $content must be a sequence containing only element, text, processing instruction,
and comment nodes.
Effects on nodes in $content:
For each node in $content, the parent property is set to parent($target).
If the type-name property of parent($target) is xs:untyped, then upd:setToUntyped() is invoked on each element or attribute node in $content.
Effects on parent($target):
The children property of parent($target) is modified to add the nodes in $content just before $target, preserving their order.
If at least one of the nodes in $content is an element or text node, upd:removeType(parent($target)) is invoked.
All the namespace bindings of parent($target) are marked for namespace propagation.
upd:insertAfter( $target as node(), $content as node()+)
Inserts $content immediately after $target.
$target must be an element, text, processing
instruction, or comment node with a non-empty parent property. $content must be a sequence containing only element, text, processing instruction,
and comment nodes.
The semantics of upd:insertAfter are identical to the semantics of upd:insertBefore, except that Rule 2a is changed as follows:
The children property of parent($target) is modified to add the nodes in $content just after $target, preserving their order.
upd:insertInto( $target as node(), $content as node()+)
Inserts $content as the children of $target, in an implementation-dependent position.
$target must be an element or document node. $content must be a sequence containing only element, text, processing instruction,
and comment nodes.
The semantics of upd:insertInto are identical to the semantics of upd:insertBefore, except that $target is substituted everywhere for parent($target), and Rule 2a is changed as follows:
The children property of $target is changed to add the nodes in $content in implementation-dependent positions, preserving their relative order.
upd:insertIntoAsFirst( $target as node(), $content as node()+)
Inserts $content as the first children of $target.
$target must be an element or document node. $content must be a sequence containing only element, text, processing instruction,
and comment nodes.
The semantics of upd:insertIntoAsFirst are identical to the semantics of upd:insertBefore, except that $target is substituted everywhere for parent($target), and Rule 2a is changed as follows:
The children property of $target is changed to add the nodes in $content as the first children, preserving their order.
upd:insertIntoAsLast( $target as node(), $content as node()+)
Inserts $content as the last children of $target.
$target must be an element or document node. $content must be a sequence containing only element, text, processing instruction,
and comment nodes.
The semantics of upd:insertIntoAsLast are identical to the semantics of upd:insertBefore, except that $target is substituted everywhere for parent($target), and Rule 2a is changed as follows:
The children property of $target is changed to add the nodes in $content as the last children, preserving their order.
upd:insertAttributes( $target as element(), $content as attribute()+)
Inserts $content as attributes of $target.
None
For each node $A in $content:
The parent property of $A is set to $target.
If the type-name property of $target is xs:untyped, then upd:setToUntyped($A) is invoked.
The following properties of $target are changed:
attributes: Modified to add the nodes in $content.
namespaces: Modified to add namespace bindings for any attribute namespace prefixes in $content that did not already have bindings.
These bindings are marked for namespace propagation.
upd:removeType($target) is invoked.
upd:delete( $target as node())
None
If $target has a parent node $P, then:
The parent property of $target is set to empty.
If $target is an attribute node, the attributes property of $P is modified to remove $target.
If $target is a non-attribute node, the children property of $P is modified to remove $target.
If $target is an element, attribute, or text node, and $P is an element node, then upd:removeType($P) is invoked.
If $target has no parent, the XDM instance is unchanged.
Note:
Deleted nodes are detached from their parent nodes; however, a node deletion has no effect on variable bindings or on the set of available documents or collections during processing of the current query.
Note:
Multiple upd:delete operations may be applied to the same node during execution of a query; this is not
an error.
upd:replaceNode( $target as node(), $replacement as node()*)
Replaces $target with $replacement.
$target must be a node that has a parent. If $target is an attribute node, $replacement must consist of zero or more attribute nodes. If $target is an element, text, comment, or processing instruction node, $replacement must be consist of zero or more element, text, comment, or processing instruction
nodes.
Effects on nodes in $replacement:
For each node in $replacement, the parent property is set to parent($target).
If the type-name property of parent($target) is xs:untyped, then upd:setToUntyped() is invoked on each node in $replacement.
Effect on $target:
The parent property of $target is set to empty.
Effects on parent($target):
If $target is an attribute node, the attributes property of parent($target) is modified by removing $target and adding the nodes in $replacement (if any).
If $target is an attribute node, the namespaces property of parent($target) is modified to add namespace bindings for any attribute namespace prefixes in $replacement that did not already have bindings. These bindings are marked for namespace propagation.
If $target is an element, text, comment, or processing instruction node, the children property of parent($target) is modified by removing $target and adding the nodes in $replacement (if any) in the former position of $target, preserving their order.
If $target or any node in $replacement is an element, attribute, or text
node, upd:removeType(parent($target)) is invoked.
upd:replaceValue( $target as node(), $string-value as xs:string)
Replaces the string value of $target with $string-value.
$target must be an attribute, text, comment, or processing instruction node.
If $target is an attribute node:
string-value of $target is set to $string-value.
upd:removeType($target) is invoked.
If $target is a text, comment, or processing instruction node: content of $target is set to $string-value.
If $target is a text node that has a parent, upd:removeType(parent($target)) is invoked.
upd:replaceElementContent( $target as element(), $text as text()?)
Replaces the existing children of the element node $target by the optional text node $text. The attributes of $target are not affected.
None.
For each node $C that is a child of $target, the parent property of $C is set to empty.
The parent property of $text is set to $target.
Effects on $target:
children is set to consist exclusively of $text. If $text is an empty sequence, then $target has no children.
typed-value and string-value are set to the content property of $text. If $text is an empty sequence, then typed-value is an empty sequence and string-value is an empty string.
upd:removeType($target) is invoked.
upd:rename( $target as node(), $newName as xs:QName)
Changes the node-name of $target to $newName.
$target must be an element, attribute, or processing instruction node.
If $target is an element node:
node-name of $target is set to $newName.
upd:removeType($target) is invoked.
If $newname has no prefix and no namespace URI,
the namespaces property of $target is modified by removing the binding (if any)
for the empty prefix.
The namespaces property of $target is modified to add a namespace binding derived from $newName, if this binding did not already exist.
This binding is marked for namespace propagation.
If $target is an attribute node:
node-name of $target is set to $newName.
upd:removeType($target) is invoked.
If $newName is xml:id, the is-id property of $target is set to true.
If $target has a parent, the namespaces property of parent($target) is modified to add a namespace binding derived from $newName, if this binding did not already exist.
This binding is marked for namespace propagation.
If $target is a processing instruction node, its target property is set to the local part of $newName.
Note:
At the end of a snapshot, if multiple attribute nodes with the same parent have the same qualified name, an
error will be raised by upd:applyUpdates.
upd:put( $node as node(), $uri as xs:string, $params as element(output:serialization-parameters))
The XDM node tree rooted at $node is stored to the location specified by $uri.
$uri must be a valid absolute URI.
The external effects of upd:put are implementation-defined,
since they occur outside the domain of XQuery. The intent is that, if upd:put is invoked on a document node and no error is raised, a
subsequent query can access the stored document by invoking
fn:doc with the same URI.
An implementation that uses serialization when storing the node MUST use the serialization parameters identified by $params.
upd:compatibilityCheck( $pul as pending-update-list)
Performs compatibility checking against a pending update list, raising errors if problems are found.
None.
A dynamic error if any of the following conditions are detected:
Two or more upd:rename primitives in $pul have the same target node [err:XUDY0015].
Two or more upd:replaceNode primitives in $pul have the same target node [err:XUDY0016].
Two or more upd:replaceValue primitives in $pul have the same target node [err:XUDY0017].
Two or more upd:replaceElementContent primitives in $pul have the same target node [err:XUDY0017].
Two or more upd:put primitives in $pul have the same $uri operand [err:XUDY0031].
Two or more primitives in $pul create conflicting namespace bindings for the same element node [err:XUDY0024]. The following kinds of primitives create namespace bindings:
upd:insertAttributes creates one namespace binding on the $target element
corresponding to the implied namespace binding of the name of each attribute node in
$content.
upd:replaceNode creates one namespace binding on the $target element
corresponding to the implied namespace binding of the name of each attribute node in
$replacement.
upd:rename creates a namespace binding on $target, or on the parent (if any) of
$target if $target is an attribute node, corresponding to the implied namespace binding of $newName.
upd:mergeUpdates( $pul1 as pending-update-list, $pul2 as pending-update-list)
Merges two pending update lists.
None.
The two pending update lists are merged and a single pending update list containing all the update primitives from both lists. The resulting pending update list is returned.
Optionally, upd:compatibilityCheck may be executed against the resulting pending update list.
upd:applyUpdates( $pul as pending-update-list, $revalidation-mode as xs:string, $inherit-namespaces as xs:boolean)
This routine ends a snapshot by making effective the semantics of all the update primitives on a pending update list and by revalidating the resulting XDM instance.
$revalidation-mode must be "strict", "lax", or "skip"
Checks the update primitives on $pul for compatibility using
upd:compatibilityCheck.
The semantics of all update primitives on $pul, other than upd:put primitives, are made effective in the following order:
First, all upd:insertInto, upd:insertAttributes, upd:replaceValue, and upd:rename primitives are applied.
Next, all upd:insertBefore, upd:insertAfter, upd:insertIntoAsFirst, and upd:insertIntoAsLast primitives are applied.
Next, all upd:replaceNode primitives are applied.
Next, all upd:replaceElementContent primitives are applied.
Next, all upd:delete primitives are applied.
If, as a net result of the above steps, the children property of some node contains adjacent text nodes, these adjacent text nodes are
merged into a single text node. The string-value of the resulting text node is the
concatenated string-values of the adjacent text nodes, with no intervening space added.
The node identity of the resulting text node is implementation-dependent.
If, as a net result of the above steps, the children property of some node contains an empty text node, that empty text node is deleted
from the children property.
If, after applying the updates, any XDM instance (including a node that has been deleted or detached from its parent, or that is a descendant of such a node) violates any constraint specified in [XQuery and XPath Data Model (XDM) 3.0], a dynamic error is raised [err:XUDY0021].
Note:
For example, a data model constraint violation might occur if multiple attributes with the same parent have the same qualified name (see Section 6.2.1 OverviewDM.)
Note:
During processing of a pending update list, an XDM instance may temporarily violate a data model constraint. An error is raised only if a constraint
remains unsatisfied after all update primitives other than upd:put have been applied.
If $inherit-namespaces is true, then upd:propagate-namespace($element, $prefix, $uri) is invoked
for each namespace binding that was marked for namespace propagation, where $element is the element node on which the namespace binding appears, $prefix is the namespace prefix, and $uri is the namespace URI. Each of these nodes is then unmarked.
For each document or element node $top that was marked for revalidation by one of the earlier steps, upd:revalidate($top, $revalidation-mode) is invoked. Each of these nodes is then unmarked.
As the final step, all upd:put primitives on $pul are applied.
The upd:applyUpdates operation is atomic with respect to the data model. In other words, if upd:applyUpdates terminates normally, the resulting XDM instance reflects the result of all update primitives; but if upd:applyUpdates raises an error, the resulting XDM instance reflects no changes. Atomicity is guaranteed only with respect to operations on
XDM instances,
and only with respect to error conditions specified in this document.
Note:
The results of implementation-dependent error conditions such as exceeding resource limits are beyond the scope of this specification.
Propagation of XDM changes to an underlying persistent store is beyond the scope of this specification. For example, the effect on persistent storage of deleting a node that has no parent is beyond the scope of this specification.
upd:revalidate( $top as node(), $revalidation-mode as xs:string)
$top must be a document node or an element node.
$revalidation-mode must be "strict", "lax", or "skip".
Schema validation is applied to the subtree rooted at $top in order to recover the types of updated nodes while preserving their node identities.
If $revalidation-mode is skip, upd:revalidate performs no action. Otherwise:
If $revalidation-mode is lax, define $topV as the result of the XQuery expression validate lax {$top}. If $revalidation-mode is strict, define $topV as the result of the XQuery expression validate strict {$top}. During computation of $topV, it is necessary to maintain a mapping between each node in $topV and the corresponding node (if any) in the subtree rooted at $top (this mapping is maintained in an implementation-dependent way.)
Note:
This step may raise an error [err:XQDY0027]XQ30 if $top is found to be invalid.
Some of the nodes in $topV (for example, default attributes generated by the validation process) may have no
corresponding nodes in $top.
For each node $nV in $topV that has a corresponding node $n in $top, replace the following properties of $n with the corresponding properties of $nV: type-name, typed-value, string-value, is-id, is-idrefs, namespace-bindings, nilled.
For each node $nV in $topV that does not have a corresponding node in $top, insert the node $nV into the subtree rooted at $top as a child or attribute of the node corresponding to the parent of $nV.
The result of upd:revalidate is to modify the properties of the nodes rooted at $top and possibly to add some new nodes to this subtree. When the revalidation process
is complete, $topV can be discarded.
Note:
After revalidation, the type annotations of the nodes in the validated subtree are consistent with their content. It is expected that implementations will optimize the revalidation process by taking into account which nodes have been modified since they were last validated.
upd:removeType( $N as node())
$N must be an element or attribute node
This routine is applied to a node whose name or content has been modified, in order to remove specific type information from the node and its ancestors, pending revalidation.
If $N is an element node, its properties are changed as follows:
If type-name is not equal to xs:untyped, then
type-name is set to xs:anyType
If the parent of N is an element node, then upd:removeType(parent($N)) is invoked.
string-value is set equal to the concatenated contents of the text node descendants, in document
order.
typed-value is set equal to the string-value property, as an instance of xs:untypedAtomic.
Note:
The data model allows some flexibility to implementations regarding whether string-value and/or typed-value are stored or computed dynamically.
nilled, is-id, and is-idrefs are set to false.
If $N is an attribute node, its properties are changed as follows:
type-name is set to xs:untypedAtomic.
typed-value is set equal to the string-value property, as an instance of xs:untypedAtomic.
is-id and is-idrefs are set to false.
If $N has a parent, upd:removeType(parent($N)) is invoked.
The topmost ancestor of $N is marked for revalidation.
[Definition: To mark a node means to identify the node as participating in a later operation.] Marking of nodes is accomplished in an implementation-dependent way--for example, an implementation might maintain a list of marked nodes.
upd:setToUntyped( $N as node())
$N must be an element or attribute node
This routine is applied to a node that has been inserted into an untyped context, which requires that the node and its descendants be untyped as well.
If $N is an element node, its properties are changed as follows:
type-name is set to xs:untyped.
typed-value is set equal to the string-value property, as an instance of xs:untypedAtomic.
Note:
The data model allows some flexibility to implementations regarding whether string-value and/or typed-value are stored or computed dynamically.
nilled, is-id, and is-idrefs are set to false.
upd:setToUntyped() is invoked on the attributes and child element nodes of $N.
If $N is an attribute node, its properties are changed as follows:
type-name is set to xs:untypedAtomic.
typed-value is set equal to the string-value property, as an instance of xs:untypedAtomic.
is-idrefs is set to false.
is-id is set to false if the attribute name is not xml:id.
upd:propagateNamespace( $element as element(), $prefix as xs:NCName, $uri as xs:anyURI)
None
Propagates a namespace binding to all descendants of an element.
For each element $child among the children of $element that does not have a namespace binding for $prefix,
add a namespace binding ($prefix, $uri) to $child
call upd:propagateNamespace($child, $prefix, $uri)
This section defines the conformance criteria for an XQuery processor. In this section, the following terms are used to indicate the requirement levels defined in [RFC 2119]. [Definition: MUST means that the item is an absolute requirement of the specification.] [Definition: MAY means that an item is truly optional.] [Definition: SHOULD means that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.]
An XQuery processor that claims to conform to this specification MUST include a claim of Minimal Conformance as defined in [9.1 Minimal Conformance]. In addition to a claim of Minimal Conformance, it MAY claim conformance to one or more optional features defined in [9.2 Optional Features].
[Definition: An XQuery processor MAY claim conformance to a subset of the XQuery Update 3.0 specification called "XQuery with Multiple Results" as defined in [9.3 XQuery with Multiple Results].] Implementations conforming to this subset but not to the Minimal Conformance may not claim to implement this specification.
Minimal Conformance to this specification MUST include all of the following items:
Minimal Conformance to [XQuery 3.0: An XML Query Language].
Support for everything specified in this document except those features specified in [9.2 Optional Features] to be optional and [E XML Syntax (XQueryX) for XQuery Update Facility 3.0]. If an implementation does not provide a given optional feature, it MUST implement any requirements specified in [9.2 Optional Features] for implementations that do not provide that feature.
A definition of every item specified to be implementation-defined, unless that item is part of an optional feature that is not supported by the implementation. A list of implementation-defined items can be found in [B Implementation-Defined Items].
Note:
Implementations are not required to define items specified to be implementation-dependent.
An implementation of XQuery that includes the Update Facility MAY also support the Optional Features of [XQuery 3.0: An XML Query Language]. These are Schema Import Feature, Schema Validation Feature, Full Axis Feature, Module Feature, and Serialization Feature.
A subset of the XQuery Update 3.0 specification called "XQuery with Multiple Results" is defined for the purposes of implementations only wishing to allow multiple results to be returned from an XQuery program. Implementations claiming conformance to the "XQuery with Multiple Results" subset MUST include all of the following items:
Minimal Conformance to [XQuery 3.0: An XML Query Language].
Support for the facilities described in the following sections of this document:
[4.2 Function Declaration]
excluding %updating and %simple annotations.
[4.3 Variable Declaration]
excluding %updating and %simple annotations.
Use of other types of XQuery Update 3.0 expression SHOULD result in an error [err:XPST0003]XP30.
This section defines the conformance criteria for an XQueryX processor that includes the Update Facility.
In this section, the terms MUST, MAY, and SHOULD are used as defined in [9 Conformance].
An XQueryX processor that claims to conform to this specification MUST implement the XQueryX syntax as defined in [E XML Syntax (XQueryX) for XQuery Update Facility 3.0] and include a claim of Minimal Conformance as defined in [9 Conformance]. In addition to a claim of Minimal Conformance, it MAY claim conformance to one or more optional features defined in [9.2 Optional Features].
The EBNF in this document and in this section is aligned with the current XML Query 3.0 grammar (see [XQuery 3.0: An XML Query Language]).
| [1] | Module |
::= | VersionDecl? (LibraryModule | MainModule) |
| [2] | VersionDecl |
::= | "xquery" (("encoding" StringLiteral) | ("version" StringLiteral ("encoding" StringLiteral)?)) Separator |
| [3] | MainModule |
::= | Prolog QueryBody |
| [4] | LibraryModule |
::= | ModuleDecl Prolog |
| [5] | ModuleDecl |
::= | "module" "namespace" NCName "=" URILiteral Separator |
| [6] | Prolog |
::= | ((DefaultNamespaceDecl | Setter | NamespaceDecl | Import) Separator)* ((ContextItemDecl | AnnotatedDecl | OptionDecl) Separator)* |
| [7] | Separator |
::= | ";" |
| [8] | Setter |
::= | BoundarySpaceDecl | DefaultCollationDecl | BaseURIDecl | ConstructionDecl | OrderingModeDecl | EmptyOrderDecl | RevalidationDecl | CopyNamespacesDecl | DecimalFormatDecl |
| [9] | BoundarySpaceDecl |
::= | "declare" "boundary-space" ("preserve" | "strip") |
| [10] | DefaultCollationDecl |
::= | "declare" "default" "collation" URILiteral |
| [11] | BaseURIDecl |
::= | "declare" "base-uri" URILiteral |
| [12] | ConstructionDecl |
::= | "declare" "construction" ("strip" | "preserve") |
| [13] | OrderingModeDecl |
::= | "declare" "ordering" ("ordered" | "unordered") |
| [14] | EmptyOrderDecl |
::= | "declare" "default" "order" "empty" ("greatest" | "least") |
| [15] | CopyNamespacesDecl |
::= | "declare" "copy-namespaces" PreserveMode "," InheritMode |
| [16] | PreserveMode |
::= | "preserve" | "no-preserve" |
| [17] | InheritMode |
::= | "inherit" | "no-inherit" |
| [18] | DecimalFormatDecl |
::= | "declare" (("decimal-format" EQName) | ("default" "decimal-format")) (DFPropertyName "=" StringLiteral)* |
| [19] | DFPropertyName |
::= | "decimal-separator" | "grouping-separator" | "infinity" | "minus-sign" | "NaN"
| "percent" | "per-mille" | "zero-digit" | "digit" | "pattern-separator" |
| [20] | Import |
::= | SchemaImport | ModuleImport |
| [21] | SchemaImport |
::= | "import" "schema" SchemaPrefix? URILiteral ("at" URILiteral ("," URILiteral)*)? |
| [22] | SchemaPrefix |
::= | ("namespace" NCName "=") | ("default" "element" "namespace") |
| [23] | ModuleImport |
::= | "import" "module" ("namespace" NCName "=")? URILiteral ("at" URILiteral ("," URILiteral)*)? |
| [24] | NamespaceDecl |
::= | "declare" "namespace" NCName "=" URILiteral |
| [25] | DefaultNamespaceDecl |
::= | "declare" "default" ("element" | "function") "namespace" URILiteral |
| [26] | AnnotatedDecl |
::= | "declare" (CompatibilityAnnotation | Annotation)* (VarDecl | FunctionDecl) |
| [27] | CompatibilityAnnotation |
::= | "updating" |
| [28] | Annotation |
::= | "%" EQName ("(" Literal ("," Literal)* ")")? |
| [29] | VarDecl |
::= | "variable" "$" VarName TypeDeclaration? ((":=" VarValue) | ("external" (":=" VarDefaultValue)?)) |
| [30] | VarValue |
::= | ExprSingle |
| [31] | VarDefaultValue |
::= | ExprSingle |
| [32] | ContextItemDecl |
::= | "declare" "context" "item" ("as" ItemType)? ((":=" VarValue) | ("external" (":=" VarDefaultValue)?)) |
| [33] | FunctionDecl |
::= | "function" EQName "(" ParamList? ")" ("as" SequenceType)? (FunctionBody | "external") |
| [34] | ParamList |
::= | Param ("," Param)* |
| [35] | Param |
::= | "$" EQName TypeDeclaration? |
| [36] | FunctionBody |
::= | EnclosedExpr |
| [37] | EnclosedExpr |
::= | "{" Expr "}" |
| [38] | OptionDecl |
::= | "declare" "option" EQName StringLiteral |
| [39] | QueryBody |
::= | Expr |
| [40] | Expr |
::= | ExprSingle ("," ExprSingle)* |
| [41] | ExprSingle |
::= | FLWORExpr |
| [42] | FLWORExpr |
::= | InitialClause IntermediateClause* ReturnClause |
| [43] | InitialClause |
::= | ForClause | LetClause | WindowClause |
| [44] | IntermediateClause |
::= | InitialClause | WhereClause | GroupByClause | OrderByClause | CountClause |
| [45] | ForClause |
::= | "for" ForBinding ("," ForBinding)* |
| [46] | ForBinding |
::= | "$" VarName TypeDeclaration? AllowingEmpty? PositionalVar? "in" ExprSingle |
| [47] | AllowingEmpty |
::= | "allowing" "empty" |
| [48] | PositionalVar |
::= | "at" "$" VarName |
| [49] | LetClause |
::= | "let" LetBinding ("," LetBinding)* |
| [50] | LetBinding |
::= | "$" VarName TypeDeclaration? ":=" ExprSingle |
| [51] | WindowClause |
::= | "for" (TumblingWindowClause | SlidingWindowClause) |
| [52] | TumblingWindowClause |
::= | "tumbling" "window" "$" VarName TypeDeclaration? "in" ExprSingle WindowStartCondition WindowEndCondition? |
| [53] | SlidingWindowClause |
::= | "sliding" "window" "$" VarName TypeDeclaration? "in" ExprSingle WindowStartCondition WindowEndCondition |
| [54] | WindowStartCondition |
::= | "start" WindowVars "when" ExprSingle |
| [55] | WindowEndCondition |
::= | "only"? "end" WindowVars "when" ExprSingle |
| [56] | WindowVars |
::= | ("$" CurrentItem)? PositionalVar? ("previous" "$" PreviousItem)? ("next" "$" NextItem)? |
| [57] | CurrentItem |
::= | EQName |
| [58] | PreviousItem |
::= | EQName |
| [59] | NextItem |
::= | EQName |
| [60] | CountClause |
::= | "count" "$" VarName |
| [61] | WhereClause |
::= | "where" ExprSingle |
| [62] | GroupByClause |
::= | "group" "by" GroupingSpecList |
| [63] | GroupingSpecList |
::= | GroupingSpec ("," GroupingSpec)* |
| [64] | GroupingSpec |
::= | GroupingVariable (TypeDeclaration? ":=" ExprSingle)? ("collation" URILiteral)? |
| [65] | GroupingVariable |
::= | "$" VarName |
| [66] | OrderByClause |
::= | (("order" "by") | ("stable" "order" "by")) OrderSpecList |
| [67] | OrderSpecList |
::= | OrderSpec ("," OrderSpec)* |
| [68] | OrderSpec |
::= | ExprSingle OrderModifier |
| [69] | OrderModifier |
::= | ("ascending" | "descending")? ("empty" ("greatest" | "least"))? ("collation"
URILiteral)? |
| [70] | ReturnClause |
::= | "return" ExprSingle |
| [71] | QuantifiedExpr |
::= | ("some" | "every") "$" VarName TypeDeclaration? "in" ExprSingle ("," "$" VarName TypeDeclaration? "in" ExprSingle)* "satisfies" ExprSingle |
| [72] | SwitchExpr |
::= | "switch" "(" Expr ")" SwitchCaseClause+ "default" "return" ExprSingle |
| [73] | SwitchCaseClause |
::= | ("case" SwitchCaseOperand)+ "return" ExprSingle |
| [74] | SwitchCaseOperand |
::= | ExprSingle |
| [75] | TypeswitchExpr |
::= | "typeswitch" "(" Expr ")" CaseClause+ "default" ("$" VarName)? "return" ExprSingle |
| [76] | CaseClause |
::= | "case" ("$" VarName "as")? SequenceTypeUnion "return" ExprSingle |
| [77] | SequenceTypeUnion |
::= | SequenceType ("|" SequenceType)* |
| [78] | IfExpr |
::= | "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle |
| [79] | TryCatchExpr |
::= | TryClause CatchClause+ |
| [80] | TryClause |
::= | "try" "{" TryTargetExpr "}" |
| [81] | TryTargetExpr |
::= | Expr |
| [82] | CatchClause |
::= | "catch" CatchErrorList "{" Expr "}" |
| [83] | CatchErrorList |
::= | NameTest ("|" NameTest)* |
| [84] | OrExpr |
::= | AndExpr ( "or" AndExpr )* |
| [85] | AndExpr |
::= | ComparisonExpr ( "and" ComparisonExpr )* |
| [86] | ComparisonExpr |
::= | StringConcatExpr ( (ValueComp |
| [87] | StringConcatExpr |
::= | RangeExpr ( "||" RangeExpr )* |
| [88] | RangeExpr |
::= | AdditiveExpr ( "to" AdditiveExpr )? |
| [89] | AdditiveExpr |
::= | MultiplicativeExpr ( ("+" | "-") MultiplicativeExpr )* |
| [90] | MultiplicativeExpr |
::= | UnionExpr ( ("*" | "div" | "idiv" | "mod") UnionExpr )* |
| [91] | UnionExpr |
::= | IntersectExceptExpr ( ("union" | "|") IntersectExceptExpr )* |
| [92] | IntersectExceptExpr |
::= | InstanceofExpr ( ("intersect" | "except") InstanceofExpr )* |
| [93] | InstanceofExpr |
::= | TreatExpr ( "instance" "of" SequenceType )? |
| [94] | TreatExpr |
::= | CastableExpr ( "treat" "as" SequenceType )? |
| [95] | CastableExpr |
::= | CastExpr ( "castable" "as" SingleType )? |
| [96] | CastExpr |
::= | TransformWithExpr ( "cast" "as" SingleType )? |
| [97] | TransformWithExpr |
::= | UnaryExpr ( "transform" "with" "{" Expr? "}" )? |
| [98] | UnaryExpr |
::= | ("-" | "+")* ValueExpr |
| [99] | ValueExpr |
::= | ValidateExpr | ExtensionExpr | SimpleMapExpr |
| [100] | GeneralComp |
::= | "=" | "!=" | "<" | "<=" | ">" | ">=" |
| [101] | ValueComp |
::= | "eq" | "ne" | "lt" | "le" | "gt" | "ge" |
| [102] | NodeComp |
::= | "is" | "<<" | ">>" |
| [103] | ValidateExpr |
::= | "validate" (ValidationMode | ("type" TypeName))? "{" Expr "}" |
| [104] | ValidationMode |
::= | "lax" | "strict" |
| [105] | ExtensionExpr |
::= | Pragma+ "{" Expr? "}" |
| [106] | Pragma |
::= | "(#" S? EQName (S PragmaContents)? "#)" |
| [107] | PragmaContents |
::= | (Char* - (Char* '#)' Char*)) |
| [108] | SimpleMapExpr |
::= | PathExpr ("!" PathExpr)* |
| [109] | PathExpr |
::= | ("/" RelativePathExpr?) |
| [110] | RelativePathExpr |
::= | StepExpr (("/" | "//") StepExpr)* |
| [111] | StepExpr |
::= | PostfixExpr | AxisStep |
| [112] | AxisStep |
::= | (ReverseStep | ForwardStep) PredicateList |
| [113] | ForwardStep |
::= | (ForwardAxis NodeTest) | AbbrevForwardStep |
| [114] | ForwardAxis |
::= | ("child" "::") |
| [115] | AbbrevForwardStep |
::= | "@"? NodeTest |
| [116] | ReverseStep |
::= | (ReverseAxis NodeTest) | AbbrevReverseStep |
| [117] | ReverseAxis |
::= | ("parent" "::") |
| [118] | AbbrevReverseStep |
::= | ".." |
| [119] | NodeTest |
::= | KindTest | NameTest |
| [120] | NameTest |
::= | EQName | Wildcard |
| [121] | Wildcard |
::= | "*" |
| [122] | PostfixExpr |
::= | PrimaryExpr (Predicate | ArgumentList)* |
| [123] | ArgumentList |
::= | "(" (Argument ("," Argument)*)? ")" |
| [124] | PredicateList |
::= | Predicate* |
| [125] | Predicate |
::= | "[" Expr "]" |
| [126] | PrimaryExpr |
::= | Literal |
| [127] | Literal |
::= | NumericLiteral | StringLiteral |
| [128] | NumericLiteral |
::= | IntegerLiteral | DecimalLiteral | DoubleLiteral |
| [129] | VarRef |
::= | "$" VarName |
| [130] | VarName |
::= | EQName |
| [131] | ParenthesizedExpr |
::= | "(" Expr? ")" |
| [132] | ContextItemExpr |
::= | "." |
| [133] | OrderedExpr |
::= | "ordered" "{" Expr "}" |
| [134] | UnorderedExpr |
::= | "unordered" "{" Expr "}" |
| [135] | FunctionCall |
::= | EQName ArgumentList |
| [136] | Argument |
::= | ExprSingle | ArgumentPlaceholder |
| [137] | ArgumentPlaceholder |
::= | "?" |
| [138] | Constructor |
::= | DirectConstructor |
| [139] | DirectConstructor |
::= | DirElemConstructor |
| [140] | DirElemConstructor |
::= | "<" QName DirAttributeList ("/>" | (">" DirElemContent* "</" QName S? ">")) |
| [141] | DirAttributeList |
::= | (S (QName S? "=" S? DirAttributeValue)?)* |
| [142] | DirAttributeValue |
::= | ('"' (EscapeQuot | QuotAttrValueContent)* '"') |
| [143] | QuotAttrValueContent |
::= | QuotAttrContentChar |
| [144] | AposAttrValueContent |
::= | AposAttrContentChar |
| [145] | DirElemContent |
::= | DirectConstructor |
| [146] | CommonContent |
::= | PredefinedEntityRef | CharRef | "{{" | "}}" | EnclosedExpr |
| [147] | DirCommentConstructor |
::= | "<!--" DirCommentContents "-->" |
| [148] | DirCommentContents |
::= | ((Char - '-') | ('-' (Char - '-')))* |
| [149] | DirPIConstructor |
::= | "<?" PITarget (S DirPIContents)? "?>" |
| [150] | DirPIContents |
::= | (Char* - (Char* '?>' Char*)) |
| [151] | CDataSection |
::= | "<![CDATA[" CDataSectionContents "]]>" |
| [152] | CDataSectionContents |
::= | (Char* - (Char* ']]>' Char*)) |
| [153] | ComputedConstructor |
::= | CompDocConstructor |
| [154] | CompDocConstructor |
::= | "document" "{" Expr "}" |
| [155] | CompElemConstructor |
::= | "element" (EQName | ("{" Expr "}")) "{" ContentExpr? "}" |
| [156] | ContentExpr |
::= | Expr |
| [157] | CompAttrConstructor |
::= | "attribute" (EQName | ("{" Expr "}")) "{" Expr? "}" |
| [158] | CompNamespaceConstructor |
::= | "namespace" (Prefix | ("{" PrefixExpr "}")) "{" URIExpr "}" |
| [159] | Prefix |
::= | NCName |
| [160] | PrefixExpr |
::= | Expr |
| [161] | URIExpr |
::= | Expr |
| [162] | CompTextConstructor |
::= | "text" "{" Expr "}" |
| [163] | CompCommentConstructor |
::= | "comment" "{" Expr "}" |
| [164] | CompPIConstructor |
::= | "processing-instruction" (NCName | ("{" Expr "}")) "{" Expr? "}" |
| [165] | FunctionItemExpr |
::= | NamedFunctionRef | InlineFunctionExpr |
| [166] | NamedFunctionRef |
::= | EQName "#" IntegerLiteral |
| [167] | InlineFunctionExpr |
::= | Annotation* "function" "(" ParamList? ")" ("as" SequenceType)? FunctionBody |
| [168] | SingleType |
::= | SimpleTypeName "?"? |
| [169] | TypeDeclaration |
::= | "as" SequenceType |
| [170] | SequenceType |
::= | ("empty-sequence" "(" ")") |
| [171] | OccurrenceIndicator |
::= | "?" | "*" | "+" |
| [172] | ItemType |
::= | KindTest | ("item" "(" ")") | FunctionTest | AtomicOrUnionType | ParenthesizedItemType |
| [173] | AtomicOrUnionType |
::= | EQName |
| [174] | KindTest |
::= | DocumentTest |
| [175] | AnyKindTest |
::= | "node" "(" ")" |
| [176] | DocumentTest |
::= | "document-node" "(" (ElementTest | SchemaElementTest)? ")" |
| [177] | TextTest |
::= | "text" "(" ")" |
| [178] | CommentTest |
::= | "comment" "(" ")" |
| [179] | NamespaceNodeTest |
::= | "namespace-node" "(" ")" |
| [180] | PITest |
::= | "processing-instruction" "(" (NCName | StringLiteral)? ")" |
| [181] | AttributeTest |
::= | "attribute" "(" (AttribNameOrWildcard ("," TypeName)?)? ")" |
| [182] | AttribNameOrWildcard |
::= | AttributeName | "*" |
| [183] | SchemaAttributeTest |
::= | "schema-attribute" "(" AttributeDeclaration ")" |
| [184] | AttributeDeclaration |
::= | AttributeName |
| [185] | ElementTest |
::= | "element" "(" (ElementNameOrWildcard ("," TypeName "?"?)?)? ")" |
| [186] | ElementNameOrWildcard |
::= | ElementName | "*" |
| [187] | SchemaElementTest |
::= | "schema-element" "(" ElementDeclaration ")" |
| [188] | ElementDeclaration |
::= | ElementName |
| [189] | AttributeName |
::= | EQName |
| [190] | ElementName |
::= | EQName |
| [191] | SimpleTypeName |
::= | TypeName |
| [192] | TypeName |
::= | EQName |
| [193] | FunctionTest |
::= | Annotation* (AnyFunctionTest |
| [194] | AnyFunctionTest |
::= | "function" "(" "*" ")" |
| [195] | TypedFunctionTest |
::= | "function" "(" (SequenceType ("," SequenceType)*)? ")" "as" SequenceType |
| [196] | ParenthesizedItemType |
::= | "(" ItemType ")" |
| [197] | URILiteral |
::= | StringLiteral |
| [198] | RevalidationDecl |
::= | "declare" "revalidation" ("strict" | "lax" | "skip") |
| [199] | InsertExprTargetChoice |
::= | (("as" ("first" | "last"))? "into") |
| [200] | InsertExpr |
::= | "insert" ("node" | "nodes") SourceExpr InsertExprTargetChoice TargetExpr |
| [201] | DeleteExpr |
::= | "delete" ("node" | "nodes") TargetExpr |
| [202] | ReplaceExpr |
::= | "replace" ("value" "of")? "node" TargetExpr "with" ExprSingle |
| [203] | RenameExpr |
::= | "rename" "node" TargetExpr "as" NewNameExpr |
| [204] | SourceExpr |
::= | ExprSingle |
| [205] | TargetExpr |
::= | ExprSingle |
| [206] | NewNameExpr |
::= | ExprSingle |
| [207] | UpdatingFunctionCall |
::= | "invoke" "updating" PrimaryExpr "(" (ExprSingle ("," ExprSingle)*)? ")" |
| [208] | CopyModifyExpr |
::= | "copy" "$" VarName ":=" ExprSingle ("," "$" VarName ":=" ExprSingle)* "modify" ExprSingle "return" ExprSingle |
| [209] | EQName |
::= | QName | URIQualifiedName |
| [210] | IntegerLiteral |
::= | Digits |
| [211] | DecimalLiteral |
::= | ("." Digits) | (Digits "." [0-9]*) |
| [212] | DoubleLiteral |
::= | (("." Digits) | (Digits ("." [0-9]*)?)) [eE] [+-]? Digits |
| [213] | StringLiteral |
::= | ('"' (PredefinedEntityRef | CharRef | EscapeQuot | [^"&])* '"') | ("'" (PredefinedEntityRef | CharRef | EscapeApos | [^'&])* "'") |
| [214] | URIQualifiedName |
::= | BracedURILiteral NCName |
| [215] | BracedURILiteral |
::= | "Q" "{" (PredefinedEntityRef | CharRef | [^&{}])* "}" |
| [216] | PredefinedEntityRef |
::= | "&" ("lt" | "gt" | "amp" | "quot" | "apos") ";" |
| [217] | EscapeQuot |
::= | '""' |
| [218] | EscapeApos |
::= | "''" |
| [219] | ElementContentChar |
::= | (Char - [{}<&]) |
| [220] | QuotAttrContentChar |
::= | (Char - ["{}<&]) |
| [221] | AposAttrContentChar |
::= | (Char - ['{}<&]) |
| [222] | Comment |
::= | "(:" (CommentContents | Comment)* ":)" |
| [223] | PITarget |
::= | [http://www.w3.org/TR/REC-xml#NT-PITarget]XML |
| [224] | CharRef |
::= | [http://www.w3.org/TR/REC-xml#NT-CharRef]XML |
| [225] | QName |
::= | [http://www.w3.org/TR/REC-xml-names/#NT-QName]Names |
| [226] | NCName |
::= | [http://www.w3.org/TR/REC-xml-names/#NT-NCName]Names |
| [227] | S |
::= | [http://www.w3.org/TR/REC-xml#NT-S]XML |
| [228] | Char |
::= | [http://www.w3.org/TR/REC-xml#NT-Char]XML |
The following symbols are used only in the definition of terminal symbols; they are not terminal symbols in the grammar of [A EBNF for XQuery 3.0 Grammar with Update extensions].
| [229] | Digits |
::= | [0-9]+ |
| [230] | CommentContents |
::= | (Char+ - (Char* ('(:' | ':)') Char*)) |
The following items in this specification are implementation-defined:
The revalidation modes that are supported by this implementation.
The default revalidation mode for this implementation.
The mechanism (if any) by which an external function can return an XDM instance and/or a pending update list to the invoking query.
The semantics of fn:put(), including the kinds of nodes accepted
as operands by this function.
It is a static error if an updating expression is used where the expression category rules prohibit it.
It is a static error if a Prolog contains more than one revalidation declaration.
It is a type error if the insertion sequence of an insert expression contains an attribute node following a node that is not an attribute node.
In an insert expression where into, as first into, or as last into is specified, it is a type error if the target expression returns a non-empty result
that does not consist of a single element or document node.
In an insert expression where before or after is specified, it is a type error if the target expression returns a non-empty result
that does not consist of a single element, text, comment, or processing instruction
node.
It is a type error if the target expression of a delete expression does not return a sequence of zero or more nodes.
In a replace expression, it is a type error if the target expression returns a non-empty result that does not consist of a single element, attribute, text, comment, or processing instruction node.
In a replace expression where value of is not specified, it is a dynamic error if the node returned by the target expression
does not have a parent.
In a replace expression where value of is not specified and the target is an element, text, comment, or processing instruction
node, it is a type error if the replacement sequence does not consist of zero or more
element, text, comment, or processing instruction nodes.
In a replace expression where value of is not specified and the target is an attribute node, it is a type error if the replacement
sequence does not consist of zero or more attribute nodes.
In a rename expression, it is a type error if the target expression returns a non-empty result that does not consist of a single element, attribute, or processing instruction node.
In a copy modify expression, it is a type error if a source expression in the copy clause does not return a single node.
In a copy modify expression, it is a dynamic error if the modify clause modifies any node that was not created by the copy clause.
It is a dynamic error if any node is the target of more than one rename expression within the same query.
It is a dynamic error if any node is the target of more than one replace expression (without value of being specified) within the same query.
It is a dynamic error if any node is the target of more than one replace value of expression within the same query.
It is a dynamic error if a function that was declared to be external but not updating returns a non-empty pending update list.
It is a dynamic error if the XDM instance that would result from applying all the updates in a query violates any constraint specified in [XQuery and XPath Data Model (XDM) 3.0]. In this case, none of the updates in the query are made effective.
It is a type error if an insert expression specifies the insertion of an attribute node into a document node.
It is a dynamic error if an insert, replace, or rename expression affects an element node by introducing a new namespace binding that conflicts with one of its existing namespace bindings.
It is a dynamic error if the effect of a set of updating expressions is to introduce conflicting namespace bindings into an element node.
(Not currently used.)
It is a static error if a revalidation declaration in a Prolog specifies a revalidation mode that is not supported by the current implementation.
It is a dynamic error if the target expression of an insert, replace, or rename expression evaluates to an empty sequence.
In an insert expression where before or after is specified, it is a dynamic error if the node returned by the target expression
does not have a parent.
It is a dynamic error if an insert expression specifies the insertion of an attribute node before or after a child of a document node.
It is a dynamic error if multiple calls to fn:put in the same snapshot specify the same URI
(after resolution of relative URIs).
It is a static error if an %updating or %simple annotation is used on a
VarDecl.
It is a static error to use more than one %updating or %simple annotation in a
given annotation set.
It is a static error to use more than one updating function assertion in the function assertionXQ30 set of a FunctionTest.
It is a dynamic error if the
pending update list
returned by the modify expression of a CopyModifyExpr
or TransformWithExpr contains a upd:put
update primitive.
It is a dynamic error if the function returned by the PrimaryExpr of a dynamic function invocation is an updating function, and the dynamic function invocation is not a partial function applicationXQ30.
It is a dynamic error if the first operand of fn:put is not a node of a supported kind.
It is a dynamic error if the second operand of fn:put is not a valid lexical representation of the xs:anyURI type.
It is a dynamic error if a constructor or replace expression would result in a processing
instruction node whose content includes the string "?>".
It is a dynamic error if the name assigned to a processing node by a constructor
or rename expression cannot be cast to the type xs:NCName.
It is a dynamic error if a constructor or replace expression would result in a comment node whose content ends with a hyphen or contains two adjacent hyphens.
It is a dynamic error if the value of the name expression in a computed element constructor, computed attribute constructor, or rename expression cannot be converted to an expanded QName (for example, because it contains a namespace prefix not found in the statically known namespaces.)
[XQueryX 3.0] defines an XML representation of [XQuery 3.0: An XML Query Language]. [XQuery Update Facility 3.0 Requirements and Use Cases] states "The syntax for updates MAY have more than one syntax binding. One syntax MUST be convenient for humans to read and write. One syntax MUST be expressed in XML in a way that reflects the underlying structure of the operations." This appendix specifies an XML Schema that defines the XML representation of XQuery Update Facility 3.0 by representing the abstract syntax found in [A EBNF for XQuery 3.0 Grammar with Update extensions]. This XML representation for XQuery Update Facility 3.0 integrates with the XML representation for XQuery 3.0.
The XML Schema specified in this appendix accomplishes its integration by importing the XML Schema defined for XQueryX in [XQueryX 3.0], incorporating all of its type and element definitions. It then extends that schema by adding definitions of new types and elements in a namespace belonging to the Update Facility specification, as well as redefining one complex type.
This section specifies the two XML Schemas that define the complex types and elements for XQueryX in support of XQuery Update Facility 3.0, including changes to the prolog and the addition of several new expressions.
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xqx="http://www.w3.org/2005/XQueryX"
xmlns:xqxuf="http://www.w3.org/2007/xquery-update-10"
targetNamespace="http://www.w3.org/2007/xquery-update-10"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<!-- Initial creation 2006-08-17: Jim Melton -->
<!-- Added ufRevalidationDecl 2006-08-21: Jim Melton -->
<!-- Overhaul to bring up to date 2007-08-07: Jim Melton -->
<!-- Reconfirmed correctness for CR 2008-02-27: Jim Melton -->
<!-- Added copyModifyExpr as alias for
transformExpr 2014-11-06: Jim Melton -->
<!-- Added transformWithExpr 2014-11-06: Jim Melton -->
<!-- Added updatingFunctionCall 2014-11-06: Jim Melton -->
<xsd:import namespace="http://www.w3.org/2005/XQueryX"
schemaLocation="http://www.w3.org/2007/xquery-update-10/
xquery-update-10-xqueryx-redef.xsd"/>
<!-- Add revalidationDecl to alternatives in prolog setters -->
<xsd:element name="revalidationDecl"
substitutionGroup="xqx:prologPartOneItem">
<xsd:simpleType>
<xsd:restriction base="xsd:NMTOKEN">
<xsd:enumeration value="strict"/>
<xsd:enumeration value="lax"/>
<xsd:enumeration value="skip"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<!-- Create substitution group for update facility exprs -->
<xsd:complexType name="expr">
<xsd:complexContent>
<xsd:extension base="xqx:expr"/>
</xsd:complexContent>
</xsd:complexType>
<!-- Make the update facilities subst grp part of expr grp -->
<xsd:element name="expr" type="xqxuf:expr" abstract="true"
substitutionGroup="xqx:expr"/>
<!-- InsertExpr -->
<xsd:complexType name="insertExpr">
<xsd:complexContent>
<xsd:extension base="xqxuf:expr">
<xsd:sequence>
<xsd:element name="sourceExpr"
type="xqx:exprWrapper"/>
<xsd:choice>
<xsd:element name="insertInto">
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:choice>
<xsd:element name="insertAsFirst"
type="xqx:emptyContent"/>
<xsd:element name="insertAsLast"
type="xqx:emptyContent"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="insertAfter"
type="xqx:emptyContent"/>
<xsd:element name="insertBefore"
type="xqx:emptyContent"/>
</xsd:choice>
<xsd:element name="targetExpr"
type="xqx:exprWrapper"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="insertExpr" type="xqxuf:insertExpr"
substitutionGroup="xqxuf:expr"/>
<!-- DeleteExpr -->
<xsd:complexType name="deleteExpr">
<xsd:complexContent>
<xsd:extension base="xqxuf:expr">
<xsd:sequence>
<xsd:element name="targetExpr"
type="xqx:exprWrapper"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="deleteExpr" type="xqxuf:deleteExpr"
substitutionGroup="xqxuf:expr"/>
<!-- ReplaceExpr -->
<xsd:complexType name="replaceExpr">
<xsd:complexContent>
<xsd:extension base="xqxuf:expr">
<xsd:sequence>
<xsd:element name="replaceValue"
type="xqx:emptyContent"
minOccurs="0" maxOccurs="1"/>
<xsd:element name="targetExpr"
type="xqx:exprWrapper"/>
<xsd:element name="replacementExpr"
type="xqx:exprWrapper"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="replaceExpr" type="xqxuf:replaceExpr"
substitutionGroup="xqxuf:expr"/>
<!-- RenameExpr -->
<xsd:complexType name="renameExpr">
<xsd:complexContent>
<xsd:extension base="xqxuf:expr">
<xsd:sequence>
<xsd:element name="targetExpr"
type="xqx:exprWrapper"/>
<xsd:element name="newNameExpr"
type="xqx:exprWrapper"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="renameExpr" type="xqxuf:renameExpr"
substitutionGroup="xqxuf:expr"/>
<!-- TransformExpr -->
<xsd:complexType name="transformExpr">
<xsd:complexContent>
<xsd:extension base="xqxuf:expr">
<xsd:sequence>
<xsd:element name="transformCopies">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="transformCopy" minOccurs="1"
maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="xqx:varRef"/>
<xsd:element name="copySource"
type="xqx:exprWrapper"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="modifyExpr"
type="xqx:exprWrapper"/>
<xsd:element name="returnExpr"
type="xqx:exprWrapper"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="transformExpr" type="xqxuf:transformExpr"
substitutionGroup="xqxuf:expr"/>
<xsd:element name="copyModifyExpr" type="xqxuf:transformExpr"
substitutionGroup="xqxuf:expr"/>
<!-- TransformWithExpr -->
<xsd:complexType name="transformWithExpr">
<xsd:complexContent>
<xsd:extension base="xqxuf:expr">
<xsd:sequence>
<xsd:element ref="pathExpr"/>
<xsd:element ref="xqxuf:expr" minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="transformWithExpr" type="xqxuf:transformWithExpr"
substitutionGroup="xqxuf:expr"/>
<!-- UpdatingFunctionCall -->
<xsd:element name="updatingFunctionCall" type="xqx:functionCallExpr"
substitutionGroup="xqxuf:expr"/>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.w3.org/2005/XQueryX"
targetNamespace="http://www.w3.org/2005/XQueryX"
elementFormDefault="qualified" attributeFormDefault="qualified">
<!-- Redefine one or more components of the XQueryX XML Schema -->
<xsd:redefine schemaLocation="http://www.w3.org/2005/XQueryX/xqueryx.xsd">
<!-- Redefine the functionDecl complex type -->
<xsd:complexType name="functionDecl">
<xsd:complexContent>
<xsd:extension base="functionDecl">
<xsd:attribute name="updatingFunction"
type="xsd:boolean" default="false"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<!-- Redefine the simpleMapExpr complex type -->
<xsd:complexType name="simpleMapExpr">
<xsd:complexContent>
<xsd:extension base="expr">
<xsd:sequence minOccurs="2" maxOccurs="unbounded">
<xsd:choice>
<xsd:element ref="pathExpr"/>
<xsd:element ref="transformWithExpr"/>
</xsd:choice>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:redefine>
</xsd:schema>
This section specifies the XSLT stylesheet that defines the semantics of XQueryX in support of XQuery Update Facility 3.0. It imports the XSLT stylesheet defined in [XQueryX 3.0], and provides additional templates that define the semantics of the XQueryX representation of XQuery Update Facility 3.0 by transforming that XQueryX representation into the human readable syntax of XQuery Update Facility 3.0.
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xqxuf="http://www.w3.org/2007/xquery-update-10"
xmlns:xqx="http://www.w3.org/2005/XQueryX">
<!-- Initial creation 2006-08-17: Jim Melton -->
<!-- Added revalidationDecl 2006-08-21: Jim Melton -->
<!-- Bring up to date with spec 2007-08-07: Jim Melton -->
<!-- Surround updating exprs w/parens 2007-09-13: Jim Melton -->
<!-- Added copyModifyExpr as alias for
transformExpr 2014-11-06: Jim Melton -->
<!-- Added transformWithExpr 2014-11-06: Jim Melton -->
<!-- Added updatingFunctionCall 2014-11-06: Jim Melton -->
<xsl:import href="http://www.w3.org/2005/XQueryX/xqueryx.xsl"/>
<!-- revalidationDecl -->
<xsl:template match="xqxuf:revalidationDecl">
<xsl:text>declare revalidation </xsl:text>
<xsl:apply-templates/>
</xsl:template>
<!-- insertExpr -->
<xsl:template match="xqxuf:insertExpr">
<xsl:value-of select="$LPAREN"/>
<xsl:text>insert nodes </xsl:text>
<xsl:value-of select="$NEWLINE"/>
<xsl:apply-templates select="xqxuf:sourceExpr"/>
<xsl:value-of select="$NEWLINE"/>
<xsl:apply-templates select="xqxuf:insertInto |
xqxuf:insertBefore |
xqxuf:insertAfter"/>
<xsl:value-of select="$NEWLINE"/>
<xsl:apply-templates select="xqxuf:targetExpr"/>
<xsl:value-of select="$RPAREN"/>
</xsl:template>
<!-- sourceExpr -->
<xsl:template match="xqxuf:sourceExpr">
<xsl:apply-templates/>
</xsl:template>
<!-- insertInto -->
<xsl:template match="xqxuf:insertInto">
<xsl:if test="child::node()">
<xsl:text>as </xsl:text>
</xsl:if>
<xsl:apply-templates/>
<xsl:text>into </xsl:text>
</xsl:template>
<!-- insertAsFirst -->
<xsl:template match="xqxuf:insertAsFirst">
<xsl:text>first </xsl:text>
</xsl:template>
<!-- insertAsLast -->
<xsl:template match="xqxuf:insertAsLast">
<xsl:text>last </xsl:text>
</xsl:template>
<!-- insertAfter -->
<xsl:template match="xqxuf:insertAfter">
<xsl:text>after </xsl:text>
</xsl:template>
<!-- insertBefore -->
<xsl:template match="xqxuf:insertBefore">
<xsl:text>before </xsl:text>
</xsl:template>
<!-- targetExpr -->
<xsl:template match="xqxuf:targetExpr">
<xsl:apply-templates/>
</xsl:template>
<!-- deleteExpr -->
<xsl:template match="xqxuf:deleteExpr">
<xsl:value-of select="$LPAREN"/>
<xsl:text>delete nodes </xsl:text>
<xsl:apply-templates/>
<xsl:value-of select="$RPAREN"/>
</xsl:template>
<!-- replaceExpr -->
<xsl:template match="xqxuf:replaceExpr">
<xsl:value-of select="$LPAREN"/>
<xsl:text>replace </xsl:text>
<xsl:if test="xqxuf:replaceValue">
<xsl:text>value of </xsl:text>
</xsl:if>
<xsl:text>node </xsl:text>
<xsl:apply-templates select="xqxuf:targetExpr"/>
<xsl:text> with </xsl:text>
<xsl:apply-templates select="xqxuf:replacementExpr"/>
<xsl:value-of select="$RPAREN"/>
</xsl:template>
<!-- replacementExpr -->
<xsl:template match="xqxuf:replacementExpr">
<xsl:apply-templates/>
</xsl:template>
<!-- renameExpr -->
<xsl:template match="xqxuf:renameExpr">
<xsl:value-of select="$LPAREN"/>
<xsl:text>rename node </xsl:text>
<xsl:apply-templates select="xqxuf:targetExpr"/>
<xsl:text> as </xsl:text>
<xsl:apply-templates select="xqxuf:newNameExpr"/>
<xsl:value-of select="$RPAREN"/>
</xsl:template>
<!-- newNameExpr -->
<xsl:template match="xqxuf:newNameExpr">
<xsl:apply-templates/>
</xsl:template>
<!-- transformExpr/copyModifyExpr -->
<xsl:template match="xqxuf:transformExpr | xqxuf:copyModifyExpr">
<xsl:value-of select="$LPAREN"/>
<xsl:text>copy </xsl:text>
<xsl:apply-templates select="xqxuf:transformCopies"/>
<xsl:value-of select="$NEWLINE"/>
<xsl:text> modify </xsl:text>
<xsl:apply-templates select="xqxuf:modifyExpr"/>
<xsl:value-of select="$NEWLINE"/>
<xsl:text> return </xsl:text>
<xsl:apply-templates select="xqxuf:returnExpr"/>
<xsl:value-of select="$RPAREN"/>
</xsl:template>
<!-- Part of transformExpr -->
<xsl:template match="xqxuf:transformCopies">
<xsl:call-template name="commaSeparatedList"/>
</xsl:template>
<!-- Part of transformExpr -->
<xsl:template match="xqxuf:transformCopy">
<xsl:apply-templates select="xqx:varRef"/>
<xsl:text> := </xsl:text>
<xsl:apply-templates select="xqxuf:copySource"/>
</xsl:template>
<!-- Part of transformExpr -->
<xsl:template match="xqxuf:copySource">
<xsl:apply-templates/>
</xsl:template>
<!-- Part of transformExpr -->
<xsl:template match="xqxuf:modifyExpr">
<xsl:apply-templates/>
</xsl:template>
<!-- Part of transformExpr -->
<xsl:template match="xqxuf:returnExpr">
<xsl:apply-templates/>
</xsl:template>
<!-- Over-ride the template for functionDecl in XQueryX.xsd -->
<!-- [33] FunctionDecl ::= "function" EQName "(" ParamList? ")" ("as" SequenceType)? (FunctionBody | "external") -->
<xsl:template match="xqx:functionDecl" priority="100">
<xsl:text>declare</xsl:text>
<xsl:apply-templates select="xqx:annotation"/>
<xsl:if test="@xqx:updatingFunction and
@xqx:updatingFunction = 'true'">
<xsl:text>updating </xsl:text>
</xsl:if>
<xsl:text> function </xsl:text>
<xsl:apply-templates select="xqx:functionName"/>
<xsl:apply-templates select="xqx:paramList"/>
<xsl:apply-templates select="xqx:typeDeclaration"/>
<xsl:choose>
<xsl:when test="xqx:externalDefinition">
<xsl:text> external </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="xqx:functionBody"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="xqx:functionDecl" priority="100">
<xsl:text>declare </xsl:text>
<xsl:if test="@xqx:updatingFunction and
@xqx:updatingFunction = 'true'">
<xsl:text>updating </xsl:text>
</xsl:if>
<xsl:text>function </xsl:text>
<xsl:apply-templates select="xqx:functionName"/>
<xsl:apply-templates select="xqx:paramList"/>
<xsl:apply-templates select="xqx:typeDeclaration"/>
<xsl:apply-templates select="xqx:functionBody"/>
<xsl:if test="xqx:externalDefinition">
<xsl:text> external </xsl:text>
</xsl:if>
</xsl:template>
<!-- transformWithExpr -->
<xsl:template match="xqx:transformWithExpr">
<xsl:text>transform with</xsl:text>
<xsl:value-of select="$SPACE"/>
<xsl:value-of select="$LBRACE"/>
<xsl:value-of select="$SPACE"/>
<xsl:apply-templates select="."/>
<xsl:value-of select="$SPACE"/>
<xsl:value-of select="$RBRACE"/>
<xsl:value-of select="$NEWLINE"/>
</xsl:template>
<!-- updatingFunctionCall -->
<xsl:template match="xqx:updatingFunctionCall">
<xsl:if test="(xqx:functionName = 'node' or
xqx:functionName = 'document-node' or
xqx:functionName = 'element' or
xqx:functionName = 'attribute' or
xqx:functionName = 'schema-element' or
xqx:functionName = 'schema-attribute' or
xqx:functionName = 'processing-instruction' or
xqx:functionName = 'comment' or
xqx:functionName = 'text' or
xqx:functionName = 'function' or
xqx:functionName = 'namespace-node' or
xqx:functionName = 'item' or
xqx:functionName = 'if' or
xqx:functionName = 'switch' or
xqx:functionName = 'typeswitch' or
xqx:functionName = 'empty-sequence') and
((not(xqx:functionName/@xqx:prefix) and not(xqx:functionName/@xqx:URI)) or
xqx:functionName/@xqx:prefix = '' or
xqx:functionName/@xqx:URI = '')">
<xsl:variable name="message">
<xsl:text>Incorrect XQueryX: function calls must not use unqualified "reserved" name "</xsl:text>
<xsl:value-of select="xqx:functionName"/>
<xsl:text>"</xsl:text>
</xsl:variable>
<xsl:message terminate="yes"><xsl:value-of select="$message"/></xsl:message>
</xsl:if>
<xsl:text>invoke updating </xsl:text>
<xsl:apply-templates select="xqx:functionName"/>
<xsl:choose>
<xsl:when test="xqx:arguments">
<xsl:for-each select="xqx:arguments">
<xsl:call-template name="parenthesizedList"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$LPAREN"/>
<xsl:value-of select="$RPAREN"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The following example is based on the data and queries in the use cases in [XQuery Update Facility 3.0 Requirements and Use Cases]. In this example, we show the English description of the query, the XQuery Update Facility solution given in [XQuery Update Facility 3.0 Requirements and Use Cases], an XQueryX solution, and the XQuery Update Facility expression that results from applying the Update Facility XQueryX-to-XQuery Update Facility transformation defined by the stylesheet in [E.2 Stylesheet] to the Update Facility XQueryX solution. The XQuery Update Facility expression that is produced is presented only as a sanity-check—the intent of the stylesheet is not to recreate the original XQuery expression, but to produce a valid XQuery expression with the same semantics. The semantics of the Update Facility XQueryX solution are determined by the semantics of the XQuery Update Facility expression that results from that transformation. The "correctness" of that transformation is determined by asking the following the question: Can some Update Facility XQueryX processor QX process some Update Facility XQueryX document D1 to produce results R1, after which the stylesheet is used to translate D1 into an XQuery Update Facility expression E1 that, when processed by some XQuery Update Facility processor Q, produces results R2 that are equivalent (under some meaningful definition of "equivalent") to results R1?
Comparison of the results of the Update Facility XQueryX-to-XQuery Update Facility transformation given in this document with the XQuery Update Facility solutions in [XQuery Update Facility 3.0 Requirements and Use Cases] may be helpful in evaluating the correctness of the Update Facility XQueryX solution in each example.
The XQuery Update Facility Use Cases solution given for each example is provided only to assist readers of this document in understanding the Update Facility XQueryX solution. There is no intent to imply that this document specifies a "compilation" or "transformation" of XQuery Update Facility syntax into Update Facility XQueryX syntax.
In the following example, note that path expressions are expanded to show their structure. Also, note that the prefix syntax for binary operators like "and" makes the precedence explicit. In general, humans find it easier to read an XML representation that does not expand path expressions, but it is less convenient for programmatic representation and manipulation. XQueryX is designed as a language that is convenient for production and modification by software, and not as a convenient syntax for humans to read and write.
Finally, please note that white space, including new lines, have been added to some of the Update Facility XQueryX documents and XQuery Update Facility expressions for readability. That additional white space is not produced by the Update Facility XQueryX-to-XQuery Update Facility transformation.
This example is based on Q6 from [XQuery Update Facility 3.0 Requirements and Use Cases], use case Parts: "modifying recursive documents":
for $keyword at $i in ("car", "skateboard", "canoe"),
$parent in doc("part-tree.xml")//part[@name=$keyword]
let $descendants := $parent//part
for $p in ($parent, $descendants)
return
replace value of node $p/@partid with $i*1000+$p/@partid
<?xml version="1.0"?>
<xqx:module xmlns:xqxuf="http://www.w3.org/2007/xquery-update-10"
xmlns:xqx="http://www.w3.org/2005/XQueryX"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2007/xquery-update-10
http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsd
http://www.w3.org/2005/XQueryX
http://www.w3.org/2005/XQueryX/xqueryx.xsd">
<xqx:versionDecl>
<xqx:version>1.0</xqx:version>
</xqx:versionDecl>
<xqx:mainModule>
<xqx:queryBody>
<xqx:flworExpr>
<xqx:forClause>
<xqx:forClauseItem>
<xqx:typedVariableBinding>
<xqx:varName>keyword</xqx:varName>
</xqx:typedVariableBinding>
<xqx:positionalVariableBinding>i
</xqx:positionalVariableBinding>
<xqx:forExpr>
<xqx:sequenceExpr>
<xqx:stringConstantExpr>
<xqx:value>car</xqx:value>
</xqx:stringConstantExpr>
<xqx:stringConstantExpr>
<xqx:value>skateboard</xqx:value>
</xqx:stringConstantExpr>
<xqx:stringConstantExpr>
<xqx:value>canoe</xqx:value>
</xqx:stringConstantExpr>
</xqx:sequenceExpr>
</xqx:forExpr>
</xqx:forClauseItem>
<xqx:forClauseItem>
<xqx:typedVariableBinding>
<xqx:varName>parent</xqx:varName>
</xqx:typedVariableBinding>
<xqx:forExpr>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:filterExpr>
<xqx:functionCallExpr>
<xqx:functionName
xqx:prefix="fn">doc</xqx:functionName>
<xqx:arguments>
<xqx:stringConstantExpr>
<xqx:value>part-tree.xml</xqx:value>
</xqx:stringConstantExpr>
</xqx:arguments>
</xqx:functionCallExpr>
</xqx:filterExpr>
</xqx:stepExpr>
<xqx:stepExpr>
<xqx:xpathAxis>descendant-or-self</xqx:xpathAxis>
<xqx:nameTest>part</xqx:nameTest>
<xqx:predicates>
<xqx:equalOp>
<xqx:firstOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:xpathAxis>attribute</xqx:xpathAxis>
<xqx:nameTest>name</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:varRef>
<xqx:name>keyword</xqx:name>
</xqx:varRef>
</xqx:secondOperand>
</xqx:equalOp>
</xqx:predicates>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:forExpr>
</xqx:forClauseItem>
</xqx:forClause>
<xqx:letClause>
<xqx:letClauseItem>
<xqx:typedVariableBinding>
<xqx:varName>descendants</xqx:varName>
</xqx:typedVariableBinding>
<xqx:letExpr>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:filterExpr>
<xqx:varRef>
<xqx:name>parent</xqx:name>
</xqx:varRef>
</xqx:filterExpr>
</xqx:stepExpr>
<xqx:stepExpr>
<xqx:xpathAxis>descendant-or-self</xqx:xpathAxis>
<xqx:nameTest>part</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:letExpr>
</xqx:letClauseItem>
</xqx:letClause>
<xqx:forClause>
<xqx:forClauseItem>
<xqx:typedVariableBinding>
<xqx:varName>p</xqx:varName>
</xqx:typedVariableBinding>
<xqx:forExpr>
<xqx:sequenceExpr>
<xqx:varRef>
<xqx:name>parent</xqx:name>
</xqx:varRef>
<xqx:varRef>
<xqx:name>descendants</xqx:name>
</xqx:varRef>
</xqx:sequenceExpr>
</xqx:forExpr>
</xqx:forClauseItem>
</xqx:forClause>
<xqx:returnClause>
<xqxuf:replaceExpr>
<xqxuf:replaceValue/>
<xqxuf:targetExpr>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:filterExpr>
<xqx:varRef>
<xqx:name>p</xqx:name>
</xqx:varRef>
</xqx:filterExpr>
</xqx:stepExpr>
<xqx:stepExpr>
<xqx:xpathAxis>attribute</xqx:xpathAxis>
<xqx:nameTest>partid</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqxuf:targetExpr>
<xqxuf:replacementExpr>
<xqx:addOp>
<xqx:firstOperand>
<xqx:multiplyOp>
<xqx:firstOperand>
<xqx:varRef>
<xqx:name>i</xqx:name>
</xqx:varRef>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:integerConstantExpr>
<xqx:value>1000</xqx:value>
</xqx:integerConstantExpr>
</xqx:secondOperand>
</xqx:multiplyOp>
</xqx:firstOperand>
<xqx:secondOperand>
<xqx:pathExpr>
<xqx:stepExpr>
<xqx:filterExpr>
<xqx:varRef>
<xqx:name>p</xqx:name>
</xqx:varRef>
</xqx:filterExpr>
</xqx:stepExpr>
<xqx:stepExpr>
<xqx:xpathAxis>attribute</xqx:xpathAxis>
<xqx:nameTest>partid</xqx:nameTest>
</xqx:stepExpr>
</xqx:pathExpr>
</xqx:secondOperand>
</xqx:addOp>
</xqxuf:replacementExpr>
</xqxuf:replaceExpr>
</xqx:returnClause>
</xqx:flworExpr>
</xqx:queryBody>
</xqx:mainModule>
</xqx:module>
Application of the stylesheet in [E.2 Stylesheet] to the Update Facility XQueryX representation results in the following XQuery representation:
xquery version "1.0";
( for $keyword at $i in ("car", "skateboard", "canoe"),
$parent in
fn:doc("part-tree.xml")/descendant-or-self::part
[(attribute::name = $keyword)]
let $descendants:=$parent/descendant-or-self::part
for $p in ($parent, $descendants)
return
replace value of node $p/attribute::partid
with (($i*1000)+$p/attribute::partid)
)
The term XDM instance denotes an unconstrained sequence of zero or more nodes and/or atomic values as defined by the data model.
Within this document, the term XQuery 3.0 refers to the language specified by [XQuery 3.0: An XML Query Language].
An XQuery processor MAY claim conformance to a subset of the XQuery Update 3.0 specification called "XQuery with Multiple Results" as defined in [9.3 XQuery with Multiple Results].
Five new kinds of expressions named basic updating expression are introduced, including insert, delete, replace, rename, and dynamic updating function invocation expressions. Basic updating expression are always classified as updating expressions.
Two namespace bindings are said to conflict if their namespace prefixes (or absence thereof) are the same but their namespace URI's (or absence thereof) are different.
The term data model refers to the data model specified by [XQuery and XPath Data Model (XDM) 3.0].
The implied namespace binding of a QName is the association of its namespace prefix (or absence thereof) with its namespace URI (or absence thereof).
To mark a node means to identify the node as participating in a later operation.
MAY means that an item is truly optional.
MUST means that the item is an absolute requirement of the specification.
The term node identity denotes the unique identity that is a property of every node in an XDM instance (see Section 2.3 Node Identity DM30.)
A pending update list is an unordered collection of update primitives, which represent node state changes that have not yet been applied.
A revalidation declaration sets the revalidation mode in the static context of the module, overriding any implementation-defined default.
Revalidation mode, which may be strict, lax, or skip,
is a component of the static context that controls the behavior of the
upd:revalidate operation.
SHOULD means that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.
A simple expression is any XQuery expression that is not an updating expression.
If a function is not an updating function, then it is a simple function.
A snapshot is a scope within which expressions are evaluated with respect to a fixed XDM instance and updates are held pending.
The first argument of an update primitive, called its target node, is the principal node to be affected by the update primitive.
Update operations are used in defining the semantics of XQuery updates, but are not directly available to users. Update operations are defined in [8 Update Operations].
Update primitives are the components of pending update lists. Each update primitive represents a node state change that has not yet been applied.
Update routines are sequences of actions that are used in the definition of XQuery semantics but do not appear on pending update lists.
An updating expression is an expression that can return a non-empty pending update list. This includes basic updating expressions, static function calls to an updating function, or any expression that directly contains an updating expression (other than the modify expression of a copy modify or transform with expression).
An updating function is a functionDM30 which can return a non-empty pending update list when called.
An updating function assertion is a function assertionXQ30 that can be used to control how a FunctionTest matches updating functions.
In [8.2.3 upd:applyUpdates], semantic rules specify the order in which the update primitives on a pending update list are applied. The purpose of this ordering is to ensure that the result of applying the pending update list is deterministic. The order of application of the update primitives was derived from the following reasoning:
insertAttribute, replaceValue, and rename primitives do not conflict with any
other primitives other than put.
insertIntoprimitives must be applied before insertIntoAsFirst/Last and
insertBefore/Afterprimitives. Reason: if an unpositioned insert were applied after a
positioned insert, it might interfere with the position established by the earlier
positioned insert.
For example, suppose node A is inserted "before" node B.
A later unpositioned insert into the common parent of A and B might intervene between
A and B,
which is not allowed by the semantics of "insert before."
insertBefore/Afterprimitives must be applied before replaceNode primitives.
Reason: After a node has been replaced, it no longer has a parent, so "before" and
"after" the replaced node
are no longer defined.
insertIntoAsFirst/Lastprimitives must be applied before replaceElementContent primitives.
Reason: this was a decision of the working group.
The intent of this decision is that, if both of these primitives are applied to the
same target node in a query,
the effective result is determined by the replaceElementContent primitive.
replaceNodeprimitives must be applied before replaceElementContent primitives.
Reason: if element content that includes a node N has been replaced, then N no longer
has a parent.
In this case, "replace node N" is undefined.
replaceNodeprimitives must be applied before delete primitives. Reason: After a node has been
deleted, it no longer has a parent. Replacing a node that has no parent is undefined.
putprimitives must be applied after all other primitives in order that
documents stored by a snapshot will reflect all update operations applied by the snapshot.
This log records the substantive changes that have been made to this document since the XQuery Update 3.0 Working Draft of 13 December 2011. Minor editorial changes are not included in this log.
Removed require-feature()/prohibit-feature() due to implementation experience.
Implemented Dynamic Updating Function Invocation, according to the 2013-09-23 proposal by Ghislain Fourny, accepted in meeting #551 on 2013-10-01.
Implemented serialization parameters for fn:put(), according to the 2013-01-30 proposal by Josh Spiegel, accepted in meeting #551 on 2013-10-01.
Update XQueryX schema and stylesheet to reflect new syntax in XQuery Update 3.0.
Added the %simple annotation, bug 14667, accepted in meeting #494
Changed transform expressions to say that they don't copy the document-uri, bug 13027, accepted in meeting #527
Clarified from which module the revalidation mode is used, bug 13300, accepted in meeting #527
Raise an error for an fn:put update primitive returned to the modify clause of a copy modify expression, bug 13970, accepted in meeting #527
Implemented the "XQuery with Multiple Results" conformance level, bug 9064, accepted in meeting #555
Implemented the ability for results to contain both non-empty XDM instances and non-empty PUL, accepted in meeting #579, clarified in the minutes of meeting #580
Added the %updating("allowed"), %updating("prohibited"), and %updating("required") function assertions, bug 14662, accepted in meeting #579
Implemented the simple transform expression, bug 23643, accepted in meeting #563
Renamed the transform expression to copy modify, and the simple transform expression to transform with, bug 23643, accepted in meeting #585
Changed all [err:TBD] to real error codes.
Raising upd:mergeUpdate related errors is required at the end of a try clause, accepted in meeting #591
The %updating annotation is not required to create an updating function as an inline function, accepted in meeting #591