This document is also available in these non-normative formats: XML.
Copyright © 2007 W3C® (MIT, ERCIM, Keio), All Rights Reserved. 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 provides expressions that can be used to make persistent changes to instances of the XQuery 1.0 and XPath 2.0 Data Model.
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 http://www.w3.org/TR/.
This is a Last Call Working Draft for review by W3C Members and other interested parties. This document was produced following the procedures set out for the W3C Process and was defined by the XML Query Working Group (part of the XML Activity). It is designed to be read in conjunction with the following documents: [XQuery 1.0], [XQuery Update Facility Requirements], and [XQuery Update Facility 1.0 Use Cases].
Publication as a Working Draft 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 defines a facility for updating instances of the XQuery 1.0 and XPath 2.0 Data Model; the language is specified in the form of extensions to XQuery 1.0. Organizations and individuals should review this document to determine the degree to which the facility fulfills requirements for updating XDM instances. The Working Group believes that this work is essentially complete and intends to advance it as soon as possible.
Since the last version of this document, several significant changes have been made. Several new update primitives have been added, removing the need for the compatibility table by introducing new mappings from updating expressions onto update primitives. Considerable clarification of the handling of namespace bindings have been made. The semantics of node deletion and of parentless node value replacement have been clarified. Finally, the XQueryX specification for the XQuery Update Facility has been added in an appendix. Additional information about changes made since the last version of this document can be found at [H.3 28 Aug. 2007 Last Call Publication].
Of the XQuery Update Facility documents, only this document, XQuery Update Facility 1.0, is a Last Call document. The XQuery Update Facility Requirements [XQuery Update Facility Requirements], although not on the Recommendation track, is being republished concurrently with this document in order to demonstrate the degree to which this document satisfies those Requirements. The XQuery Update Facility Use Cases [XQuery Update Facility 1.0 Use Cases], although not on the Recommendation track, is being republished concurrently with this document in order to illustrate various use cases that guided the design of the XQuery Update Facility specification.
Public Last Call comments on this document and its open issues are invited. Comments on this document are due by 31 October 2007. Comments on this document should be made in W3C's public Bugzilla system for this specification (instructions can be found at http://www.w3.org/XML/2005/04/qt-bugzilla). When entering comments, select the Product named "XPath / XQuery / XSLT", the Component named "Update Facility", and the Version named "Last Call drafts". This repository includes open issues recorded by the Query Working Group as well as by members of the public. If access to the Bugzilla system is not feasible, you may send your comments to the W3C XSLT/XPath/XQuery mailing list, public-qt-comments@w3.org. It will be very helpful if you include the string [UPD] in the subject line of your comment, whether made in Bugzilla or in email. Each Bugzilla entry and email message should contain only one comment. Archives of the comments and responses are available at http://lists.w3.org/Archives/Public/public-qt-comments/.
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.
1 Introduction
1.1 Terminology
2 Extensions to XQuery 1.0
2.1 Extensions to the Processing Model
2.2 Extensions to the Prolog
2.3 Extensions to the Static Context
2.4 New Kinds of Expressions
2.4.1 Insert
2.4.2 Delete
2.4.3 Replace
2.4.3.1 Replacing a Node
2.4.3.2 Replacing the Value of a Node
2.4.4 Rename
2.4.5 Transform
2.4.6 Compatibility of Updating Expressions
2.5 Extensions to Existing Expressions
2.5.1 FLWOR Expression
2.5.2 Typeswitch Expression
2.5.3 Conditional Expression
2.5.4 Comma Expression
2.5.5 Parenthesized Expression
2.5.6 Function Declaration
2.5.7 Function Call
2.5.8 Other Expressions
2.6 Extensions to Built-in Function Library
2.6.1 fn:put
3 Update Operations
3.1 Update Primitives
3.1.1 upd:insertBefore
3.1.2 upd:insertAfter
3.1.3 upd:insertInto
3.1.4 upd:insertIntoAsFirst
3.1.5 upd:insertIntoAsLast
3.1.6 upd:insertAttributes
3.1.7 upd:delete
3.1.8 upd:replaceNode
3.1.9 upd:replaceValue
3.1.10 upd:replaceElementContent
3.1.11 upd:rename
3.2 Update Routines
3.2.1 upd:mergeUpdates
3.2.2 upd:applyUpdates
3.2.3 upd:revalidate
3.2.4 upd:removeType
3.2.5 upd:setToUntyped
4 Static Typing Feature
4.1 Overview and notations
4.2 Core Grammar
4.3 XQuery Update Facility 1.0 Prolog
4.4 XQuery Update Facility 1.0 Expressions
4.4.1 Insert
4.4.2 Delete
4.4.3 Replace
4.4.4 Rename
4.4.5 Transform
4.4.6 Examples
A EBNF for XQuery 1.0 Grammar with Update
extensions
A.1 Terminal Symbols
B Implementation-Defined Items
C References
C.1 Normative References
C.2 Non-normative References
D Error Conditions
D.1 New Error Codes
D.2 Amendments to Existing Error Codes
E XML Syntax (XQueryX) for XQuery Update Facility 1.0
E.1 Schema
E.2 Stylesheet
E.3 Example
E.3.1 XQuery Representation
E.3.2 XQueryX Representation
E.3.3 Transformed XQuery Representation
F Glossary (Non-Normative)
G Rationale for Precedence of Update Primitives (Non-Normative)
H Revision Log (Non-Normative)
H.1 8 May 2006 Publication
H.2 11 July 2006 Publication
H.3 28 Aug. 2007 Last Call Publication
This document defines the syntax and semantics of an extension to [XQuery 1.0] called the XQuery Update Facility 1.0. This language extension is designed to meet the requirements for updating instances of the [XQuery/XPath Data Model (XDM)], as defined in [XQuery Update Facility Requirements].
The XQuery Update Facility 1.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 1.0. The most recent versions of the two XQueryX XML Schemas and the XQueryX XSLT stylesheet for the XQuery Update Facility 1.0 are available at http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsd, http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx-redef.xsd, and http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsl, respectively.
[Definition: Within this document, the term XQuery refers to the language specified by [XQuery 1.0].] [Definition: The term data model refers to the data model specified by [XQuery/XPath Data Model (XDM)].] [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 IdentityDM.)]
As described in Section 3.3.3 QNames and NOTATIONSDM, 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.
The basic building block of XQuery is the expression. XQuery 1.0 provides several kinds of expressions that can be composed with each other in arbitrary ways. An XQuery 1.0 expression takes one or more XDM instances as input and returns an XDM instance as a result. In XQuery 1.0, an expression never modifies the state of an existing node; however, constructor expressions create new nodes with new node identities.
XQuery Update Facility 1.0 introduces a new category of expression called an updating expression, which can potentially modify the state of an existing node.
The extensions to XQuery 1.0 provided by XQuery Update Facility 1.0 may be characterized as follows:
XQuery Update Facility 1.0 introduces five new kinds of expressions, called insert, delete, replace, rename, and transform expressions, and specifies the syntax and semantics of each new kind of expression.
XQuery Update Facility 1.0 classifies XQuery expressions into the following categories:
[Definition: A basic updating expression is an insert, delete, replace, or rename expression, or a call to an updating function.]
[Definition: An updating expression is a basic updating expression or any expression (other than a transform expression) that directly contains an updating expression.]
Note:
The definition of an updating expression is recursive.
[Definition: A non-updating expression is any XQuery expression that is not an updating expression.]
XQuery Update Facility 1.0 defines the places where updating and non-updating expressions can be used. In so doing, it makes small extensions to the syntax and semantics of certain existing expressions.
XQuery Update Facility 1.0 defines the following extensions to the XQuery processing model:
In XQuery 1.0, the result of each expression is an XDM instance. XQuery Update Facility 1.0 extends the XQuery processing model so that the result of an expression consists of both an XDM instance and a pending update list (either or both of which may be empty). [Definition: A pending update list is an unordered collection of update primitives, which represent node state changes that have not yet been applied.]
Note:
In the current specification, no expression returns both a non-empty XDM instance and a non-empty pending update list.
XQuery Update Facility 1.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 [3 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 pending update list, upd:applyUpdates
is implicitly applied to this pending update list. This invocation of upd:applyUpdates
may raise an error (see [3.2.2 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 1.0 currently defines an entire query as one snapshot.
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.
[7] | Setter | ::= | BoundarySpaceDecl | DefaultCollationDecl | BaseURIDecl | ConstructionDecl | OrderingModeDecl | EmptyOrderDecl | RevalidationDecl | CopyNamespacesDecl |
[141] | 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, 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 [3.2.3 upd:revalidate]
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 revalidation declaration specifies a revalidation mode that is not supported by the current implementation, a static error is raised [err:XUST0026].
The following definition is added to the XQuery static context (documented in Section 2.1.1 Static ContextXQ):
[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.]
The following entry is added to the table of static context components (documented in Section C.1 Static Context ComponentsXQ):
Component: Revalidation mode
Default initial value: strict
.
Can be overwritten by an implementation: Yes (implementation defined.)
Can be overwritten by a query: Yes, overwritable by declaration in query prolog.
Scope: Global.
Consistency rules: Must be strict
, lax
, or skip
.
[32] | ExprSingle | ::= | FLWORExpr |
XQuery Update Facility 1.0 extends the syntax of ExprSingle by adding five new kinds of expressions, called insert, delete, replace, rename, and transform expressions. The syntax and semantics of these expressions are described in the following sections.
Note:
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. For more details on type loss and recovery, see the update primitives associated with each updating expression; see also [3.2.4 upd:removeType] and [3.2.3 upd:revalidate].
[143] | InsertExpr | ::= | "insert" ("node" | "nodes") SourceExpr InsertExprTargetChoice TargetExpr |
[142] | InsertExprTargetChoice | ::= | (("as" ("first" | "last"))? "into") |
[147] | SourceExpr | ::= | ExprSingle |
[148] | TargetExpr | ::= | ExprSingle |
An insert expression is an updating expression that 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 is preserved.
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 is preserved.
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 is preserved.
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.
Examples:
Insert a year
element after the publisher of the first book.
insert node <year>2005</year> after fn:doc("bib.xml")/books/book[1]/publisher
Navigating 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
The semantics of an insert expression are as follows:
SourceExpr must be a non-updating expression; otherwise a static error is raised [err:XUST0001]. SourceExpr is evaluated as though it were an enclosed
expression in an element constructor (see Rule 1e in Section
3.7.1.3 ContentXQ). 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.
The target expression must be a non-updating expression; otherwise a static error is raised [err:XUST0001]. The target expression 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].
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].
The result of the insert expression is an empty XDM instance and a pending update list constructed as follows:
If as first into
is specified, the pending update list consists of 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 consists of 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 consists of 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 consists of 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 consists of the following update primitives:
If $alist
is not empty, upd:insertAttributes($parent, $alist)
If $clist
is not empty, upd:insertAfter($target, $clist)
[144] | DeleteExpr | ::= | "delete" ("node" | "nodes") TargetExpr |
[148] | 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.
Examples:
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")]
The semantics of a delete expression are as follows:
The target expression must be a non-updating expression; otherwise a static error is raised [err:XUST0001]. The target expression 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.
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 (together with an empty XDM instance) is the result of the delete expression.
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 upd:delete($tnode)
primitive causes the given node to be detached from its parent after completion of the current query. If the given node has no parent, it is implementation-defined whether a dynamic error is raised [err:XUDY0020].
The effects of a delete expression on persistent storage (if any) are beyond the scope of this specification.
[145] | ReplaceExpr | ::= | "replace" ("value" "of")? "node" TargetExpr "with" ExprSingle |
[148] | TargetExpr | ::= | ExprSingle |
A replace expression is an updating expression. 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. Example:
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]/publisher
The semantics of this form of replace expression are as follows:
The expression following the keyword with
must be a non-updating expression; otherwise a static error is raised [err:XUST0001]. This expression is evaluated as though it were an enclosed
expression in an element constructor (see Rule 1e in Section
3.7.1.3 ContentXQ). 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.
The target expression must be a non-updating expression; otherwise a static error is raised [err:XUST0001]. The target expression 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].
The result of the replace expression is an empty XDM instance and a pending update list consisting of the following update primitive:
upd:replaceNode($target, $rlist)
If value of
is specified,
a replace expression is used to modify the value of a node while preserving
its node identity. Example:
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
The semantics of this form of replace expression are as follows:
The expression following the keyword with
must be a non-updating expression; otherwise a static error is raised [err:XUST0001]. This expression is evaluated as though it were the content
expression of a text node constructor (see Section 3.7.3.4 of
[XQuery 1.0].) 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.
The target expression must be a non-updating expression; otherwise a static error is raised [err:XUST0001]. The target expression 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 consisting of the following update primitive: 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 containing the following update primitive:
upd:replaceValue($target, $string)
.
[146] | RenameExpr | ::= | "rename" "node" TargetExpr "as" NewNameExpr |
[148] | TargetExpr | ::= | ExprSingle |
[149] | 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.
Examples:
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 $newname
The semantics of a rename expression are as follows:
The target expression must be a non-updating expression; otherwise a static error is raised [err:XUST0001]. The target expression 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 must be a non-updating expression; otherwise a static error is raised [err:XUST0001]. NewNameExpr is
evaluated as though it were the name expression of a computed element
constructor (see Section 3.7.3.1 of [XQuery 1.0].)
The result is either an error or an expanded QName. Let $QName
be this expanded QName.
The following checks are performed for error conditions:
If $target
is an element node, the "namespaces" property of $target
must not include any namespace binding that conflicts with the implied namespace binding of $QName
[err:XUDY0023].
If $target
is an attribute node that has a parent, the "namespaces" property of parent($target)
must not include any namespace binding that conflicts with the implied namespace binding of $QName
[err:XUDY0023].
If $target
is processing instruction node, $QName
must not include a non-empty namespace prefix. [err:XUDY0025].
The result of the rename expression is an empty XDM instance and a pending update list
containing the following update primitive:
upd:rename($target, $QName)
.
Note:
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)
[150] | TransformExpr | ::= | "copy" "$" VarName ":=" ExprSingle ("," "$" VarName ":=" ExprSingle)* "modify" ExprSingle "return" ExprSingle |
A transform expression can be used to create modified copies of existing nodes in an XDM instance. Each node created by a transform expression has a new node identity. The result of a transform expression is an XDM instance that may include both nodes that were created by the transform expression and other, previously existing nodes. A transform expression is a non-updating expression because it does not modify the value of any existing nodes.
Examples:
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 by $newx * 2) return ($oldx, $newx)
Note:
No persistent changes to the underlying data result from this example.
A transform expression consists of three clauses, denoted by the keywords copy
, modify
, and return
. The semantics of a transform expression are as follows:
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 source expression must be a non-updating expression; otherwise a static error is raised [err:XUST0001]. The source expression is evaluated as though it were an enclosed expression in an element constructor (see Rule 1e in Section 3.7.1.3 ContentXQ.) The result of this step must be a single node [err:XUTY0013].
Note:
The node returned by the source expression is a new node whose node identity is distinct from that of any previously existing node.
The variable name is bound to the node returned by the source expression. The scope of this variable binding includes all subexpressions of the containing transform 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 modify
clause must contain either an updating expression, an empty expression ( )
, or a call to the fn:error
function; otherwise a static error is raised [err:XUST0002]. The expression in the modify
clause is evaluated, resulting in a pending update list. If the target node of any update primitive on this pending update list is a node that was not newly created in Step 1, a dynamic error is raised [err:XUDY0014]. Let $pul
be the pending update list generated by this step.
The following update operation is invoked: upd:applyUpdates($pul)
. 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 [3.2.2 upd:applyUpdates].
The return
clause must contain a non-updating expression; otherwise a static error is raised [err:XUST0001]. The return
clause is evaluated, and its result is the result of the transform expression. During evaluation of the return
clause, changes applied to copied nodes by the preceding step are visible.
The rules defining compatibility of updating expressions within a snapshot are defined in [3.2.2 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].
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 1.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. Its semantics are extended as follows:
If a for
,
let
, where
, or order by
clause contains an updating expression, a static error is raised [err:XUST0001].
If the return
clause contains a non-updating expression, the FLWOR expression is a non-updating expression, and its semantics are as specified in Section 3.8 of [XQuery 1.0].
If the return
clause contains an updating expression, the FLWOR expression is an updating expression, and its semantics are as follows:
The semantics of the for
,
let
, where
, and order by
clauses are as specified in Section 3.8 of [XQuery 1.0]. These clauses generate a stream of tuples of bound
variables.
For each tuple
generated by the previous step, the updating expression in the
return
clause is evaluated, resulting in a pending update list.
All the pending update lists generated by the
previous step are merged by successive invocations of the upd:mergeUpdates
operation. The resulting merged pending update list is the
result of the FLWOR expression.
Note:
In the event of incompatible updates, the upd:mergeUpdates
operation may raise an error, as described in [3.2.1 upd:mergeUpdates].
The following example illustrates the use of an updating expression in a FLWOR expression:
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
The syntax of the typeswitch expression is not changed. Its semantics are extended as
follows (the term "branch" refers to any case
or default
clause in the typeswitch expression):
If the operand expression of a typeswitch is an updating expression, a static error is raised [err:XUST0001].
If any branch contains an updating expression, the typeswitch expression is an updating expression; otherwise it is a non-updating expression.
If the typeswitch expression is a non-updating expression, its semantics are as specified in Section 3.12.2 of [XQuery 1.0].
If the typeswitch expression is an updating expression, then all of its branches must contain either an updating expression, an empty expression ( )
, or a call to the fn:error
function; otherwise a static error is raised [err:XUST0001]. In this case, selection of the effective case and
binding of variables is performed as specified in Section 3.12.2 of
[XQuery 1.0]. The expression in the return
clause of the effective case (or default) is then evaluated, resulting
in a pending update list, which serves as the result of
the typeswitch expression.
The semantics of
conditional expressions are extended as follows (the term "branch" refers to the then
and else
clauses in the conditional expression):
If the if-clause contains an updating expression, a static error is raised [err:XUST0001].
If either branch contains an updating expression, the conditional expression is an updating expression; otherwise it is a non-updating expression.
If the conditional expression is a non-updating expression, its semantics are as specified in Section 3.10 of [XQuery 1.0].
If the conditional expression is an updating expression, then both of its branches must contain either an updating expression, an empty expression ( )
, or a call to the fn:error
function; otherwise a static error is raised [err:XUST0001]. In this case, the test
expression is evaluated and the then
or else
clause is selected and evaluated as specified in Section 3.10 of
[XQuery 1.0]. The result of the conditional expression is
the pending update list returned by the
selected branch.
The following example illustrates the use of updating expressions in a conditional expression:
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
The semantics of comma expressions (composed of one or more expressions concatenated by the comma operator, as described in Section 3.3.1 of [XQuery 1.0]) are extended as follows:
If any operand of the comma expression is an updating expression, the comma expression is an updating expression; otherwise it is a non-updating expression.
If the comma expression is a non-updating expression, its semantics are as specified in Section 3.3.1 of [XQuery 1.0].
If the comma expression is an updating expression, then each of its operands must be either an updating expression, an empty expression ( )
, or a call to the fn:error
function; otherwise a static error is raised [err:XUST0001]. In this case, the operand expressions are evaluated (in any order), and the pending update lists
returned by the operand expressions are merged by the upd:mergeUpdates
operation. The resulting merged pending update list is the result of the comma expression.
The following example illustrates the use of an updating comma expression:
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 )
The semantics of a parenthesized expression (any XQuery expression enclosed in parentheses) are extended as follows:
The category of a parenthesized expression is the same as the category of its operand expression, which may be an updating expression or a non-updating expression. The result of a parenthesized expression is also the same as the result of its operand expression. An empty parenthesized expression ( )
is a non-updating expression, and its result is an empty sequence.
[26] | FunctionDecl | ::= | "declare" "updating"? "function" QName "(" ParamList? ")" ("as" SequenceType)? (EnclosedExpr | "external") |
The syntax of a function declaration is extended to include an optional keyword: updating
. [Definition: A function whose declaration contains the keyword updating is called an updating function.] The semantics of a function declaration, described in Section 4.15 of [XQuery 1.0], are extended as follows:
If updating
is not specified:
If external
is not specified, the EnclosedExpr in the function declaration must be a non-updating expression; otherwise a static error is raised [err:XUST0001].
If external
is specified, the external function must not return a non-empty pending update list; otherwise a dynamic error is raised [err:XUDY0018].
If updating
is specified:
A return type must not be specified [err:XUST0028]. The return type of an updating function is assumed to be the empty sequence.
If external
is not specified, the EnclosedExpr in the function declaration must be an updating expression, an empty expression ( )
, or a call to the fn:error
function; otherwise a static error is raised [err:XUST0002].
If external
is specified, the external function may return a non-empty pending update list but it must not return a non-empty XDM instance; otherwise a dynamic error is raised [err:XUDY0019].
The means by which an external function returns an XDM instance or a pending update list is implementation-defined.
The following example illustrates a declaration of an updating function.
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 }
The semantics of a function call are extended as follows:
The function call is evaluated as specified in Section 3.1.5 of [XQuery 1.0]. If any input parameter of the function call is an updating expression, a static error is raised [err:XUST0001]. If the called function was declared with the updating
keyword, the function call is an updating expression. If the called function was declared without the updating
keyword, the function call is a non-updating expression.
The semantics of all XQuery expressions other than FLWOR expressions, typeswitch expressions, conditional expressions, comma expressions, parenthesized expressions, and function calls are extended as follows:
If any operand of this expression is an updating expression, a static error is raised [err:XUST0001].
In addition, the initializing expression of a variable declaration in a Prolog may not be an updating expression [err:XUST0001].
XQuery Update Facility 1.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()
Summary: 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.
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.
The semantics of fn:put
are implementation-defined,
since they occur completely 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 results of fn:put
do not become effective until after completion of the query containing the fn:put
function--that is, until after completion of the upd:applyUpdates
operation invoked by the outermost expression in the current query. The fn:put
function has no effect on the current query. (For example, it does not change the set of available documents or collections seen by the current query.)
This section describes the update operations defined by XQuery Update Facility 1.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.
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 include 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 include 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 include 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
Error checks:
If the QNames of any two attribute nodes in $content
have implied namespace bindings that conflict with each other, a dynamic error is raised [err:XUDY0024].
If the QName of any attribute node in $content
has an implied namespace binding that conflicts with a namespace binding in the "namespaces" property of $target
, a dynamic error is raised [err:XUDY0024].
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 include the nodes in $content
.
namespaces:
Modified to include namespace bindings for any attribute namespace prefixes in $content
that did not already have bindings.
upd:removeType($target)
is invoked.
upd:delete( $target as node())
None
If $target
has no parent, the XDM instance is unchanged. An implementation may (but is not required to) raise a dynamic error if $target
had no parent before execution of the query began. [err:XUDY0020].
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.
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.
Error checks:
If the QNames of any two attribute nodes in $replacement
have implied namespace bindings that conflict with each other, a dynamic error is raised [err:XUDY0024].
If the QName of any attribute node in $replacement
has an implied namespace binding that conflicts with a namespace binding in the "namespaces" property of parent($target)
, a dynamic error is raised [err:XUDY0024].
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 element 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 include namespace bindings for any attribute namespace prefixes in $replacement
that did not already have bindings.
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.
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 an implied namespace binding that conflicts with an existing namespace binding in the namespaces
property of $target
, a dynamic error is raised [err:XUDY0024].
The namespaces
property of $target
is modified to include a namespace binding derived from $newName
, if this binding did not already exist.
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, and $newName
has an implied namespace binding that conflicts with a namespace binding in the namespaces
property of parent($target)
, a dynamic error is raised [err:XUDY0024].
If $target
has a parent, the namespaces
property of parent($target)
is modified to include a namespace binding derived from $newName
, if this binding did not already exist.
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: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 is returned.
Optionally, upd:mergeUpdates
may raise a dynamic error if any of the following conditions are detected:
Two or more upd:rename
primitives on the merged list have the same target node [err:XUDY0015].
Two or more upd:replaceNode
primitives on the merged list have the same target node [err:XUDY0016].
Two or more upd:replaceValue
primitives on the merged list have the same target node [err:XUDY0017].
Two or more upd:replaceElementContent
primitives on the merged list have the same target node [err:XUDY0017].
upd:applyUpdates( $pul as pending-update-list)
None.
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.
Checks the update primitives on $pul
for compatibility. Raises a dynamic error if any of the following conditions are detected:
Two or more upd:rename
primitives on $pul
have the same target node [err:XUDY0015].
Two or more upd:replaceNode
primitives on $pul
have the same target node [err:XUDY0016].
Two or more upd:replaceValue
primitives on $pul
have the same target node [err:XUDY0017].
Two or more upd:replaceElementContent
primitives on $pul
have the same target node [err:XUDY0017].
The semantics of all the update primitives on $pul
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.
Finally, 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.
For each document or element node $top
that was marked for revalidation by one of the earlier steps, upd:revalidate($top)
is invoked.
If the resulting XDM instance violates any constraint specified in [XQuery/XPath Data Model (XDM)], 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.)
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())
$top
must be a document node or an element node.
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 in the static context is skip
, upd:revalidate
performs no action. Otherwise:
If revalidation mode in the static context 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]XQ 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-id
and is-idrefs
are set to false
.
XQuery 1.0 includes an optional static typing feature. This section describes the static typing feature for the XQuery Update Facility 1.0. Implementations of this specification that support optional static typing must implement the following static typing rules, along with the XQuery 1.0 static typing rules defined in [XQuery 1.0 and XPath 2.0 Formal Semantics].
The concepts and notations used in this specification are the same as those used to define the static typing feature for XQuery 1.0. For convenience, we recall here some of the main concepts and notations. We refer the reader to [XQuery 1.0 and XPath 2.0 Formal Semantics] for a more detailed introduction.
The static typing feature for the XQuery Update Facility 1.0 is defined based on a processing model similar to the one of XQuery 1.0. We first define the XQuery Update Facility 1.0 Core, as a subset of the XQuery Update Facility 1.0. Then for each kind of updating expression, we give the normalization rules from the XQuery Update Facility 1.0 into that Core, as well as the inference rules that compute the type for each Core expression.
Notation
Normalization rules map expressions in the XQuery Update Facility 1.0 into expressions in the XQuery Update Facility 1.0 Core. They are written as follows.
[Expr]Expr |
== |
CoreExpr |
Notation
The static semantics is specified through a judgment which gives for each expression its corresponding static type. The meaning of that judgment is defined through inference rules as in [XQuery 1.0 and XPath 2.0 Formal Semantics].
The judgment
holds when, in the static environment statEnv, the expression Expr has type Type.
Notation
The static environment is the same as the one defined in [XQuery 1.0 and XPath 2.0 Formal Semantics], extended with an entry corresponding to the revalidation mode, as follows.
statEnv.revalidationMode |
|
We extend the XQuery Core defined in [XQuery 1.0 and XPath 2.0 Formal Semantics] with five expressions needed to support the XQuery Update Facility 1.0: insert, delete, rename, replace, and transform.
[23 (Core)] | ExprSingle | ::= | FLWORExpr |
[99 (Core)] | InsertExpr | ::= | "insert" "nodes" SourceExpr InsertExprTargetChoice TargetExpr |
[98 (Core)] | InsertExprTargetChoice | ::= | (("as" ("first" | "last"))? "into") |
[103 (Core)] | SourceExpr | ::= | ExprSingle |
[104 (Core)] | TargetExpr | ::= | ExprSingle |
[100 (Core)] | DeleteExpr | ::= | "delete" "nodes" TargetExpr |
[101 (Core)] | ReplaceExpr | ::= | "replace" ("value" "of")? "node" TargetExpr "with" ExprSingle |
[102 (Core)] | RenameExpr | ::= | "rename" "node" TargetExpr "as" NewNameExpr |
[105 (Core)] | NewNameExpr | ::= | ExprSingle |
[106 (Core)] | TransformExpr | ::= | "copy" "$" VarName ":=" ExprSingle ("," "$" VarName ":=" ExprSingle)* "modify" ExprSingle "return" ExprSingle |
The core grammar production for IfExpr
can be found in [XQuery 1.0 and XPath 2.0 Formal Semantics]
The core grammar production for OrExpr
can be found in [XQuery 1.0 and XPath 2.0 Formal Semantics]
The core grammar production for FLWORExpr
can be found in [XQuery 1.0 and XPath 2.0 Formal Semantics]
The core grammar production for QuantifiedExpr
can be found in [XQuery 1.0 and XPath 2.0 Formal Semantics]
The core grammar production for TypeswitchExpr
can be found in [XQuery 1.0 and XPath 2.0 Formal Semantics]
The core grammar production for VarName
can be found in [XQuery 1.0 and XPath 2.0 Formal Semantics]
In addition to the normalization rules defined in [XQuery 1.0 and XPath 2.0 Formal Semantics] for the XQuery 1.0 prolog, the following normalization rules apply to the revalidation mode setter.
Revalidation declarations are left unchanged through normalization.
[RevalidationDecl]PrologDecl |
== |
RevalidationDecl |
The revalidation declaration modifies the revalidation mode in the static context.
In addition to the normalization and static typing rules defined in [XQuery 1.0 and XPath 2.0 Formal Semantics] for XQuery 1.0 expressions, the normalization and static typing rules described in this specification apply to the expressions in the XQuery Update Facility 1.0. For each expression except the transform expression, the final type is the empty type which corresponds to the value being returned. In each case, the static typing rules check that every sub-expression is well-typed, and that the resulting value is consistent with the constraints specific to each expression. For instance, the expression used in a delete must return a sequence of nodes.
The following normalization rules applies to insert expressions. Note that whether the expression is written using the 'nodes' or 'node' modifier, the normalized expression always uses the 'nodes' modifier.
[insert (node|nodes) Expr1 InsertExprTargetChoice Expr2]Expr |
== |
insert nodes fs:item-sequence-to-node-sequence ([Expr1]Expr)
InsertExprTargetChoice
[Expr2]Expr
|
Where fs:item-sequence-to-node-sequence
is the special function used
for computing element content and is defined in [XQuery 1.0 and XPath 2.0 Formal Semantics].
The static typing rule for insert depends on whether it is an
insert into
, or an insert before
or
after
.
In the case of an insert into
, the inference
depends on whether the target node is an element or a document
node (in which case it does not allow attribute nodes to be
inserted). This is expressed by the two following rules.
| |||||
|
| |||||
|
In the case of an insert before
or
after
, the type of the target node must be either
an element, text, comment or processing-instruction node. This
is expressed by the following rule.
The following normalization rule applies to delete expressions. Note that whether the expression is written using the 'nodes' or 'node' modifier, the normalized expression always uses the 'nodes' modifier.
The static typing rule for delete is as follows.
The following normalization rules applies to replace expressions.
[replace node Expr1 with Expr2]Expr |
== |
replace node [Expr1]Expr with fs:item-sequence-to-node-sequence ([Expr2]Expr)
|
Normalization of replace value of expressions.
[replace value of node Expr1 with Expr2]Expr |
== |
replace value of node [Expr1]Expr with [text { Expr2 }]Expr |
If the value of
modifier is not specified, a
replace expression replaces one node with a new sequence of zero
or more nodes.
An attribute node can be replaced only by zero or more attribute nodes.
| |||||
|
An element, text, comment, or processing instruction node can be replaced only by zero or more element, text, comment, or processing instruction nodes.
| |||||
|
If the value of
modifier is specified, a
replace expression replaces the content of a single node,
which must not be a document node by either a single text node
or empty.
The following normalization rule applies to rename expressions.
The target of a rename expression must be either an
element, attribute or processing-instruction, and its new name
must be either of type xs:QName
, xs:string
, or
xs:untypedAtomic
.
The following normalization rule applies to transform expressions.
[
| |||||
== | |||||
|
The transform expression is type checked using the following inference rule.
| ||||||||||||
|
Examples
Here are a few example queries and their corresponding static typing. In each case, if the query passes static typing, its static type is the empty type.
insert node <x/> into <a/>
Passes static typing
insert node 1 into <a/>
Passes static typing
insert node 1 into (<a/>,<a/>)
Fails static typing because the target expression does not return a single node
insert node (element a {()}, attribute b {()}) into <doc/>
Fails static typing because the attribute node is not at the head of the insertion list
insert node <x/> into //a
Fails static typing because the target expression may not
return a single node (assuming the schema allows //a
to return multiple a
elements)
rename node <a/> as "b"
Passes static typing
rename node <a/> as 1
Fails static typing because the new name does not have one of the permissible types
The EBNF in this document and in this section is aligned with the current XML Query 1.0 grammar (see [XQuery 1.0]).
[1] | Module | ::= | VersionDecl? (LibraryModule | MainModule) |
[2] | VersionDecl | ::= | "xquery" "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)* ((VarDecl | FunctionDecl | OptionDecl) Separator)* |
[7] | Setter | ::= | BoundarySpaceDecl | DefaultCollationDecl | BaseURIDecl | ConstructionDecl | OrderingModeDecl | EmptyOrderDecl | RevalidationDecl | CopyNamespacesDecl |
[8] | Import | ::= | SchemaImport | ModuleImport |
[9] | Separator | ::= | ";" |
[10] | NamespaceDecl | ::= | "declare" "namespace" NCName "=" URILiteral |
[11] | BoundarySpaceDecl | ::= | "declare" "boundary-space" ("preserve" | "strip") |
[12] | DefaultNamespaceDecl | ::= | "declare" "default" ("element" | "function") "namespace" URILiteral |
[13] | OptionDecl | ::= | "declare" "option" QName StringLiteral |
[14] | OrderingModeDecl | ::= | "declare" "ordering" ("ordered" | "unordered") |
[15] | EmptyOrderDecl | ::= | "declare" "default" "order" "empty" ("greatest" | "least") |
[16] | CopyNamespacesDecl | ::= | "declare" "copy-namespaces" PreserveMode "," InheritMode |
[17] | PreserveMode | ::= | "preserve" | "no-preserve" |
[18] | InheritMode | ::= | "inherit" | "no-inherit" |
[19] | DefaultCollationDecl | ::= | "declare" "default" "collation" URILiteral |
[20] | BaseURIDecl | ::= | "declare" "base-uri" URILiteral |
[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] | VarDecl | ::= | "declare" "variable" "$" QName TypeDeclaration? ((":=" ExprSingle) | "external") |
[25] | ConstructionDecl | ::= | "declare" "construction" ("strip" | "preserve") |
[26] | FunctionDecl | ::= | "declare" "updating"? "function" QName "(" ParamList? ")" ("as" SequenceType)? (EnclosedExpr | "external") |
[27] | ParamList | ::= | Param ("," Param)* |
[28] | Param | ::= | "$" QName TypeDeclaration? |
[29] | EnclosedExpr | ::= | "{" Expr "}" |
[30] | QueryBody | ::= | Expr |
[31] | Expr | ::= | ExprSingle ("," ExprSingle)* |
[32] | ExprSingle | ::= | FLWORExpr |
[33] | FLWORExpr | ::= | (ForClause | LetClause)+ WhereClause? OrderByClause? "return" ExprSingle |
[34] | ForClause | ::= | "for" "$" VarName TypeDeclaration? PositionalVar? "in" ExprSingle ("," "$" VarName TypeDeclaration? PositionalVar? "in" ExprSingle)* |
[35] | PositionalVar | ::= | "at" "$" VarName |
[36] | LetClause | ::= | "let" "$" VarName TypeDeclaration? ":=" ExprSingle ("," "$" VarName TypeDeclaration? ":=" ExprSingle)* |
[37] | WhereClause | ::= | "where" ExprSingle |
[38] | OrderByClause | ::= | (("order" "by") | ("stable" "order" "by")) OrderSpecList |
[39] | OrderSpecList | ::= | OrderSpec ("," OrderSpec)* |
[40] | OrderSpec | ::= | ExprSingle OrderModifier |
[41] | OrderModifier | ::= | ("ascending" | "descending")? ("empty" ("greatest" | "least"))? ("collation" URILiteral)? |
[42] | QuantifiedExpr | ::= | ("some" | "every") "$" VarName TypeDeclaration? "in" ExprSingle ("," "$" VarName TypeDeclaration? "in" ExprSingle)* "satisfies" ExprSingle |
[43] | TypeswitchExpr | ::= | "typeswitch" "(" Expr ")" CaseClause+ "default" ("$" VarName)? "return" ExprSingle |
[44] | CaseClause | ::= | "case" ("$" VarName "as")? SequenceType "return" ExprSingle |
[45] | IfExpr | ::= | "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle |
[46] | OrExpr | ::= | AndExpr ( "or" AndExpr )* |
[47] | AndExpr | ::= | ComparisonExpr ( "and" ComparisonExpr )* |
[48] | ComparisonExpr | ::= | RangeExpr ( (ValueComp |
[49] | RangeExpr | ::= | AdditiveExpr ( "to" AdditiveExpr )? |
[50] | AdditiveExpr | ::= | MultiplicativeExpr ( ("+" | "-") MultiplicativeExpr )* |
[51] | MultiplicativeExpr | ::= | UnionExpr ( ("*" | "div" | "idiv" | "mod") UnionExpr )* |
[52] | UnionExpr | ::= | IntersectExceptExpr ( ("union" | "|") IntersectExceptExpr )* |
[53] | IntersectExceptExpr | ::= | InstanceofExpr ( ("intersect" | "except") InstanceofExpr )* |
[54] | InstanceofExpr | ::= | TreatExpr ( "instance" "of" SequenceType )? |
[55] | TreatExpr | ::= | CastableExpr ( "treat" "as" SequenceType )? |
[56] | CastableExpr | ::= | CastExpr ( "castable" "as" SingleType )? |
[57] | CastExpr | ::= | UnaryExpr ( "cast" "as" SingleType )? |
[58] | UnaryExpr | ::= | ("-" | "+")* ValueExpr |
[59] | ValueExpr | ::= | ValidateExpr | PathExpr | ExtensionExpr |
[60] | GeneralComp | ::= | "=" | "!=" | "<" | "<=" | ">" | ">=" |
[61] | ValueComp | ::= | "eq" | "ne" | "lt" | "le" | "gt" | "ge" |
[62] | NodeComp | ::= | "is" | "<" | ">" |
[63] | ValidateExpr | ::= | "validate" ValidationMode? "{" Expr "}" |
[64] | ValidationMode | ::= | "lax" | "strict" |
[65] | ExtensionExpr | ::= | Pragma+ "{" Expr? "}" |
[66] | Pragma | ::= | "(#" S? QName (S PragmaContents)? "#)" |
[67] | PragmaContents | ::= | (Char* - (Char* '#)' Char*)) |
[68] | PathExpr | ::= | ("/" RelativePathExpr?) |
[69] | RelativePathExpr | ::= | StepExpr (("/" | "//") StepExpr)* |
[70] | StepExpr | ::= | FilterExpr | AxisStep |
[71] | AxisStep | ::= | (ReverseStep | ForwardStep) PredicateList |
[72] | ForwardStep | ::= | (ForwardAxis NodeTest) | AbbrevForwardStep |
[73] | ForwardAxis | ::= | ("child" "::") |
[74] | AbbrevForwardStep | ::= | "@"? NodeTest |
[75] | ReverseStep | ::= | (ReverseAxis NodeTest) | AbbrevReverseStep |
[76] | ReverseAxis | ::= | ("parent" "::") |
[77] | AbbrevReverseStep | ::= | ".." |
[78] | NodeTest | ::= | KindTest | NameTest |
[79] | NameTest | ::= | QName | Wildcard |
[80] | Wildcard | ::= | "*" |
[81] | FilterExpr | ::= | PrimaryExpr PredicateList |
[82] | PredicateList | ::= | Predicate* |
[83] | Predicate | ::= | "[" Expr "]" |
[84] | PrimaryExpr | ::= | Literal | VarRef | ParenthesizedExpr | ContextItemExpr | FunctionCall | OrderedExpr | UnorderedExpr | Constructor |
[85] | Literal | ::= | NumericLiteral | StringLiteral |
[86] | NumericLiteral | ::= | IntegerLiteral | DecimalLiteral | DoubleLiteral |
[87] | VarRef | ::= | "$" VarName |
[88] | VarName | ::= | QName |
[89] | ParenthesizedExpr | ::= | "(" Expr? ")" |
[90] | ContextItemExpr | ::= | "." |
[91] | OrderedExpr | ::= | "ordered" "{" Expr "}" |
[92] | UnorderedExpr | ::= | "unordered" "{" Expr "}" |
[93] | FunctionCall | ::= | QName "(" (ExprSingle ("," ExprSingle)*)? ")" |
[94] | Constructor | ::= | DirectConstructor |
[95] | DirectConstructor | ::= | DirElemConstructor |
[96] | DirElemConstructor | ::= | "<" QName DirAttributeList ("/>" | (">" DirElemContent* "</" QName S? ">")) |
[97] | DirAttributeList | ::= | (S (QName S? "=" S? DirAttributeValue)?)* |
[98] | DirAttributeValue | ::= | ('"' (EscapeQuot | QuotAttrValueContent)* '"') |
[99] | QuotAttrValueContent | ::= | QuotAttrContentChar |
[100] | AposAttrValueContent | ::= | AposAttrContentChar |
[101] | DirElemContent | ::= | DirectConstructor |
[102] | CommonContent | ::= | PredefinedEntityRef | CharRef | "{{" | "}}" | EnclosedExpr |
[103] | DirCommentConstructor | ::= | "<!--" DirCommentContents "-->" |
[104] | DirCommentContents | ::= | ((Char - '-') | ('-' (Char - '-')))* |
[105] | DirPIConstructor | ::= | "<?" PITarget (S DirPIContents)? "?>" |
[106] | DirPIContents | ::= | (Char* - (Char* '?>' Char*)) |
[107] | CDataSection | ::= | "<![CDATA[" CDataSectionContents "]]>" |
[108] | CDataSectionContents | ::= | (Char* - (Char* ']]>' Char*)) |
[109] | ComputedConstructor | ::= | CompDocConstructor |
[110] | CompDocConstructor | ::= | "document" "{" Expr "}" |
[111] | CompElemConstructor | ::= | "element" (QName | ("{" Expr "}")) "{" ContentExpr? "}" |
[112] | ContentExpr | ::= | Expr |
[113] | CompAttrConstructor | ::= | "attribute" (QName | ("{" Expr "}")) "{" Expr? "}" |
[114] | CompTextConstructor | ::= | "text" "{" Expr "}" |
[115] | CompCommentConstructor | ::= | "comment" "{" Expr "}" |
[116] | CompPIConstructor | ::= | "processing-instruction" (NCName | ("{" Expr "}")) "{" Expr? "}" |
[117] | SingleType | ::= | AtomicType "?"? |
[118] | TypeDeclaration | ::= | "as" SequenceType |
[119] | SequenceType | ::= | ("empty-sequence" "(" ")") |
[120] | OccurrenceIndicator | ::= | "?" | "*" | "+" |
[121] | ItemType | ::= | KindTest | ("item" "(" ")") | AtomicType |
[122] | AtomicType | ::= | QName |
[123] | KindTest | ::= | DocumentTest |
[124] | AnyKindTest | ::= | "node" "(" ")" |
[125] | DocumentTest | ::= | "document-node" "(" (ElementTest | SchemaElementTest)? ")" |
[126] | TextTest | ::= | "text" "(" ")" |
[127] | CommentTest | ::= | "comment" "(" ")" |
[128] | PITest | ::= | "processing-instruction" "(" (NCName | StringLiteral)? ")" |
[129] | AttributeTest | ::= | "attribute" "(" (AttribNameOrWildcard ("," TypeName)?)? ")" |
[130] | AttribNameOrWildcard | ::= | AttributeName | "*" |
[131] | SchemaAttributeTest | ::= | "schema-attribute" "(" AttributeDeclaration ")" |
[132] | AttributeDeclaration | ::= | AttributeName |
[133] | ElementTest | ::= | "element" "(" (ElementNameOrWildcard ("," TypeName "?"?)?)? ")" |
[134] | ElementNameOrWildcard | ::= | ElementName | "*" |
[135] | SchemaElementTest | ::= | "schema-element" "(" ElementDeclaration ")" |
[136] | ElementDeclaration | ::= | ElementName |
[137] | AttributeName | ::= | QName |
[138] | ElementName | ::= | QName |
[139] | TypeName | ::= | QName |
[140] | URILiteral | ::= | StringLiteral |
[141] | RevalidationDecl | ::= | "declare" "revalidation" ("strict" | "lax" | "skip") |
[142] | InsertExprTargetChoice | ::= | (("as" ("first" | "last"))? "into") |
[143] | InsertExpr | ::= | "insert" ("node" | "nodes") SourceExpr InsertExprTargetChoice TargetExpr |
[144] | DeleteExpr | ::= | "delete" ("node" | "nodes") TargetExpr |
[145] | ReplaceExpr | ::= | "replace" ("value" "of")? "node" TargetExpr "with" ExprSingle |
[146] | RenameExpr | ::= | "rename" "node" TargetExpr "as" NewNameExpr |
[147] | SourceExpr | ::= | ExprSingle |
[148] | TargetExpr | ::= | ExprSingle |
[149] | NewNameExpr | ::= | ExprSingle |
[150] | TransformExpr | ::= | "copy" "$" VarName ":=" ExprSingle ("," "$" VarName ":=" ExprSingle)* "modify" ExprSingle "return" ExprSingle |
[151] | IntegerLiteral | ::= | Digits |
[152] | DecimalLiteral | ::= | ("." Digits) | (Digits "." [0-9]*) |
[153] | DoubleLiteral | ::= | (("." Digits) | (Digits ("." [0-9]*)?)) [eE] [+-]? Digits |
[154] | StringLiteral | ::= | ('"' (PredefinedEntityRef | CharRef | EscapeQuot | [^"&])* '"') | ("'" (PredefinedEntityRef | CharRef | EscapeApos | [^'&])* "'") |
[155] | PredefinedEntityRef | ::= | "&" ("lt" | "gt" | "amp" | "quot" | "apos") ";" |
[156] | EscapeQuot | ::= | '"' |
[157] | EscapeApos | ::= | "''" |
[158] | ElementContentChar | ::= | Char - [{}<&] |
[159] | QuotAttrContentChar | ::= | Char - ["{}<&] |
[160] | AposAttrContentChar | ::= | Char - ['{}<&] |
[161] | Comment | ::= | "(:" (CommentContents | Comment)* ":)" |
[162] | PITarget | ::= | [http://www.w3.org/TR/REC-xml#NT-PITarget]XML |
[163] | CharRef | ::= | [http://www.w3.org/TR/REC-xml#NT-CharRef]XML |
[164] | QName | ::= | [http://www.w3.org/TR/REC-xml-names/#NT-QName]Names |
[165] | NCName | ::= | [http://www.w3.org/TR/REC-xml-names/#NT-NCName]Names |
[166] | S | ::= | [http://www.w3.org/TR/REC-xml#NT-S]XML |
[167] | 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 1.0 Grammar with Update extensions].
[168] | Digits | ::= | [0-9]+ |
[169] | 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.
Whether the implementation raises dynamic error [err:XUDY0020] if a node is deleted that had no parent before execution of the query began.
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 in any position other than one of the following:
The topmost expression in the body of a query.
The modify
clause of a transform expression.
The return
clause of a FLWOR expression.
The return
clauses of a typeswitch expression in which every return
clause contains an updating expression, an empty expression ( )
, or a call to the fn:error
function.
The then
and else
clauses of a conditional statement in which both the then
and else
clauses contain either an updating expression, an empty expression ( )
, or a call to the fn:error
function.
An operand of a comma expression in which each operand is either an updating expression, an empty expression ( )
, or a call to the fn:error
function.
The content of a parenthesized expression.
The body of a function declaration in which the keyword updating
is specified.
It is a static error if an non-updating expression other than an empty expression ( )
or a call to the fn:error
function is used in one of the following positions:
The modify
clause of a transform expression.
The top-level expression in the body of a function declaration in which the keyword updating
is specified.
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 transform expression, it is a type error if a source expression in the copy
clause does not return a single node.
In a transform 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 a function that was declared to be both external
and updating
returns a non-empty data model instance.
An implementation may (but is not required to) raise a dynamic error if a node is deleted that had no parent before execution of the query began.
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/XPath Data Model (XDM)]. 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.
It is a dynamic error if the target of a rename expression is a processing instruction node, and the new name expression returns a QName with a non-empty namespace prefix.
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.
It is a static error if a function declaration specifies both updating
and a return type.
In an insert expression where before
or after
is specified, it is a dynamic error if 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 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 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 1.0] defines an XML representation of [XQuery 1.0]. [XQuery Update Facility Requirements] 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 1.0 by representing the abstract syntax found in [A EBNF for XQuery 1.0 Grammar with Update extensions]. This XML representation for XQuery Update Facility 1.0 integrates with the XML representation for XQuery 1.0.
The XML Schema specified in this appendix accomplishes its integration by importing the XML Schema defined for XQueryX in [XQueryX 1.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 1.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 --> <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: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 complext type --> <xsd:complexType name="functionDeclType"> <xsd:complexContent> <xsd:extension base="functionDeclType"> <xsd:attribute name="updatingFunction" type="xsd:boolean" default="false"/> </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 1.0. It imports the XSLT stylesheet defined in [XQueryX 1.0], and provides additional templates that define the semantics of the XQueryX representation of XQuery Update Facility 1.0 by transforming that XQueryX representation into the human readable syntax of XQuery Update Facility 1.0.
<xsl:stylesheet version="1.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 --> <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: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: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:text>delete nodes </xsl:text> <xsl:apply-templates/> </xsl:template> <!-- replaceExpr --> <xsl:template match="xqxuf:replaceExpr"> <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:template> <!-- replacementExpr --> <xsl:template match="xqxuf:replacementExpr"> <xsl:apply-templates/> </xsl:template> <!-- renameExpr --> <xsl:template match="xqxuf:renameExpr"> <xsl:text>rename node </xsl:text> <xsl:apply-templates select="xqxuf:targetExpr"/> <xsl:text> as </xsl:text> <xsl:apply-templates select="xqxuf:newNameExpr"/> </xsl:template> <!-- newNameExpr --> <xsl:template match="xqxuf:newNameExpr"> <xsl:apply-templates/> </xsl:template> <!-- transformExpr --> <xsl:template match="xqxuf:transformExpr"> <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: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 --> <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> </xsl:stylesheet>
The following example is based on the data and queries in the use cases in [XQuery Update Facility 1.0 Use Cases]. In this example, we show the English description of the query, the XQuery Update Facility solution given in [XQuery Update Facility 1.0 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 1.0 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 1.0 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) )
A basic updating expression is an insert, delete, replace, or rename expression, or a call to an updating function.
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/XPath Data Model (XDM)].
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.
The term node identity denotes the unique identity that is a property of every node in an XDM instance (see Section 2.3 Node IdentityDM.)
A non-updating expression is any XQuery expression that is not an updating expression.
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, 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.
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 [3 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 a basic updating expression or any expression (other than a transform expression) that directly contains an updating expression.
A function whose declaration contains the keyword updating is called an updating function.
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 refers to the language specified by [XQuery 1.0].
In [3.2.2 upd:applyUpdates], semantic rule 2 specifies an 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:
The insertAttribute
, replaceValue
, and rename
primitives do not conflict with any
other primitives, and can be applied at any time.
insertInto
primitives must be applied before insertIntoAsFirst/Last
and
insertBefore/After
primitives. 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/After
primitives 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/Last
primitives 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.
replaceNode
primitives 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.
replaceNode
primitives 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.
This log records the substantive changes that have been made to this document since the Initial Working Draft of 27 January 2006. Minor editorial changes are not included in this log.
Grammar changes:
Add do
as initial keyword in InsertExpr, DeleteExpr, ReplaceExpr, RenameExpr.
Eliminate curly braces around first operands of all updating expressions (as a result, DirectConstructor is no longer a special case in InsertExpr).
Eliminate do
keyword from FLWOR and typeswitch expressions (any updating
subexpressions must be in the return
clause).
In TransformExpr, change do
keyword to modify
, and change
ExprSingle to Expr in modify-clause.
In ReplaceExpr, keep only a single action-clause (earlier syntax allowed one or more action-clauses).
In RenameExpr, change to
keyword to as
(avoids an ambiguity).
A comma expression no longer permits its operands to include a mixture of updating and non-updating expressions.
In a function declaration, if updating
is specified, the function does not return a value, and no result type may be declared.
Added clarifying details:
It is a static error if the operand expression of a typeswitch is an updating expression.
if (text) then ( ) else ( )
is a non-updating expression.
An empty parenthesized expression ( )
is a non-updating expression.
The body of an updating function may contain an empty expression ( )
or a call to the fn:error
function.
Specified that upd:applyUpdates
is an atomic operation with respect to the data model, but that propagation of data model changes to an underlying physical representation is beyond the
scope of this specification.
Eliminated the incompatibility between primitive operations insert into
and insert into as last
when these operations are applied to the same target node.
Replaced all occurrences of the xdt
: namespace prefix with xs:
, following a joint decision by the Query and XSLT Working Groups.
Simplification of the rules for compatibility of updating expressions. Creates three new update primitives: upd:insertAsFirst
, upd:replaceNode,
and upd:replaceValue
. Eliminates the compatibility table and introduces new mappings of XQuery updating expressions onto update primitives as suggested in http://lists.w3.org/Archives/Member/member-query-ultf/2006Mar/0028.html. Introduces new definition of upd:applyUpdates
, removing many incompatibilities.
More specific definition of the upd:revalidate
update operation.
More formal definitions of updating and non-updating expressions.
Corrections to error XUST0001 (formerly XUST0101) and definition of a new error XUST0002.
Define replacement of a node as substitution of new nodes in the position of the original node. As a result, an attribute node can be replaced only by attribute nodes, and content (element, text, comment, and PI) nodes can be replaced only by content nodes.
Revised the mappings of replace
expressions onto underlying primitives to make the compatibility rules more consistent. The new mappings require one new update primitive, called upd:replaceElementContent
, which is applied immediately before the final deletion of nodes.
Created new subheadings inside the "Replace" section to call attention to the two forms of a replace expression (editorial change).
Added the function fn:put
for storing a document or element to a location.
Clarified the semantics of node deletion: the deleted node is detached from its parent. If the node to be deleted has no parent, no change is made to the data model instance, and it is implementation-defined whether an error is raised. Node deletions have no effect on variable bindings or available documents and collections within the current snapshot. Affected sections: 2.3.2 (Delete), 3.2.2 (upd:applyUpdates).
Added a rule that each variable binding in the copy clause of a transform statement must create exactly one copied node.
Simplified the description of fn:put
, eliminating one signature and two error conditions.
Semantics of fn:put
are implementation-defined and occur after completion of the current snapshot.
Clarified result when the value of a node is replaced by an empty sequence.
Corrected error in upd:replaceNode, Rule 3a, regarding replacement of attribute nodes (attributes that were not replaced remain unaffected.)
Clarified that it is not an error to insert zero nodes (the insertion list may be empty.)
Added a new error code [err:XUDY0022] for the case in which a user attempts to insert an attribute node as a child of a document node.
In Section 3.1.9 (upd:replaceValue), clarified what happens when the target is
a text node that has no parent.
(Value is replaced, no error is raised, upd:removeType
is not invoked.)
In Section 3.1.11 (upd:rename), clarified what happens when the target is an attribute node that has no parent. (Node is renamed, no error is raised.)
In Section 2.3.1 (Insert), changed semantic rule 2 to allow the target node to be a text,
comment, or PI node when before
or after
is specified.
Also affects error code err:XUTY0006.
Clarified the effects of insert, replace, and rename expressions on namespace bindings. The main points are (1) these expressions may not introduce namespace conflicts (the same namespace prefix bound to two or more different namespace URIs within the scope of a single element; (2) the effects of a rename expression are limited to a single target node and do not affect the descendants of the target node; and (3) new error codes XUDY0023 and XUDY0024.
In Section 3.2.2 (upd:applyUpdates), added an example of how a global data model constraint might be violated.
In Section 2.4.3 (Conditional Expression), added a rule that the if-clause may not contain an updating expression. (This rule was intended but overlooked in previous drafts.) Closes Bug 3798.
In Section 2.3.3.2 (Replacing the Value of a Node), edited semantic rule 4
to raise an error if an updated comment node ends with a hyphen
or contains two adjacent hyphens, or if an updated PI node contains the string "?>
".
Results in amendments to error codes XQDY0026 and XQDY0072.
In Section 3.2.2 (upd:applyUpdates), added a new semantic rule that
deletes empty text nodes from the children
property of
any element node after all updates have been applied. Closes Bug 4313.
In Section 2.1 (Extensions to the Processing Model), stated that propagation of XDM updates to an underlying persistent store is beyond the scope of the current specification. Also, in Section 3.2.2 (upd:applyUpdates), stated in Rule 7 that atomicity is guaranteed only with respect to error conditions specified in this document. Together, these changes close Bug 4168.
In Section 2.5 (Extensions to Built-in Function Library), specified that the
return type of fn:put()
is empty-sequence()
.
In Section 2.3.4 (Rename), specified a dynamic error [err:XUDY0025] if the new name of a processing instruction node includes a non-empty namespace prefix. Closes Bug 4169.
Made support for each of the three revalidation modes implementation-defined, and added a static error [err:XUDY0026]) for specifying an unsupported revalidation mode. Closes Bug 4287.
Removed all references to "marking a node for deletion." Sections affected: upd:delete, upd:replaceNode, and upd:applyUpdates. This change simplifies the description of the update primitives without changing the result of any query.
Added revised definitions for existing error codes XQDY0026, XQDY0072, and XQDY0074 (these errors can now be raised by updating expressions.)
Added better definitions for "updating expression," "snapshot," and "node identity".
Removed a redundant definition of compatibility of updating expressions (Section 2.4.6 now refers to Section 3.2.2 for the normative definition.)
Added a rule that the initializing expression in a variable declaration must be a non-updating expression.
Added parentheses to example in Section 2.5.4 (Comma Expression). Closes Bug 3799.
Reorganized error codes relating to the target of an updating expression, reducing the amount of static checking that is required. Codes XUTY0005, XUTY0006, XUTY0007, XUTY0008, XUTY0010, XUTY0011, and XUTY0012 are type errors. Codes XUDY0009, XUDY0022, XUDY0023, XUDY0025, XUDY0027, XUDY0029, XQDY0026, and XQDY0072 are dynamic errors. Closes Bug 4526.
Added requirements relating to preserving the relative order and adjacency of inserted nodes. Closes Bugs 4527, 4528, 4529, and 4574.
Added a new error code [XUST0028] for an updating function declaration that specifies a return type. Closes Bug 4611.
Split the former error code XUTY0006 into a type error XUTY0006 and a dynamic error XUDY0029. Also split the former error code XUDY0022 into a type error XUTY0022 and a dynamic error XUDY0030.
Deleted the keyword transform
from the syntax of a transform expression.
Closes Bug 4540.
Modified the grammar to eliminate the do
keyword from all
updating expressions and to add the keyword node
or nodes
to these expressions. This change affects many sections of the document.
Added a new Section 4 describing the Static Typing Feature for updating expressions.
Added a new Appendix listing the implementation-defined items introduced by the XQuery Update Facility.
Added a new Appendix documenting the reasons for the order in which update primitives are applied when processing a pending update list.
Added a new Appendix specifying XQueryX syntax for updating expressions.