ConceptioArchiveW3C TR
W3C TRopen access

xquery update 10

W3C · w3c_tr
W3C TR · Standards · License: Open Access
Open Source ↗
w3c, standard

XQuery Update Facility 1.0 /**/ code { font-family: monospace; }

div.constraint, div.issue, div.note, div.notice { margin-left: 2em; }

div.issue p.title { margin-left: -2em; }

ol.enumar { list-style-type: decimal; } ol.enumla { list-style-type: lower-alpha; } ol.enumlr { list-style-type: lower-roman; } ol.enumua { list-style-type: upper-alpha; } ol.enumur { list-style-type: upper-roman; }

li p { margin-top: 0.3em; margin-bottom: 0.3em; }

sup small { font-style: italic; color: #8F8F8F; } div.exampleInner pre { margin-left: 1em; margin-top: 0em; margin-bottom: 0em} div.exampleOuter {border: 4px double gray; margin: 0em; padding: 0em} div.exampleInner { background-color: #d5dee3; border-top-width: 4px; border-top-style: double; border-top-color: #d3d3d3; border-bottom-width: 4px; border-bottom-style: double; border-bottom-color: #d3d3d3; padding: 4px; margin: 0em } div.exampleWrapper { margin: 4px } div.exampleHeader { font-weight: bold; margin: 4px}

div.issue { border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1pt; margin-bottom: 20pt; }

th.issue-toc-head { border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1pt; }

table.small { font-size: x-small; }

a.judgment:visited, a.judgment:link { font-family: sans-serif; color: black; text-decoration: none } a.processing:visited, a.processing:link { color: black; text-decoration: none } a.env:visited, a.env:link { color: black; text-decoration: none } table.small { font-size: x-small; } a.judgment:visited, a.judgment:link { font-family: sans-serif; color: black; text-decoration: none } a.processing:visited, a.processing:link { color: black; text-decoration: none } a.env:visited, a.env:link { color: black; text-decoration: none } .advisement { border-color: orange; border-style: none solid; background: #fec; color: black; padding: .5em; border-width: .5em; page-break-inside: avoid; margin: 1em auto; }

/**/ Status Update (6 April 2021): Feedback, comments, error reports on this specification should be sent via GitHub https://github.com/w3c/qtspecs/issues [email protected] This version: http://www.w3.org/TR/2011/REC-xquery-update-10-20110317/ Latest version: http://www.w3.org/TR/xquery-update-10/ Previous version: http://www.w3.org/TR/2011/PR-xquery-update-10-20110125/ Editors: Jonathan Robie, Red Hat <[email protected]> Don Chamberlin Michael Dyck <[email protected]> Daniela Florescu, Oracle <[email protected]> Jim Melton, Oracle <[email protected]> Jérôme Siméon, IBM T.J. Watson Research Center <[email protected]> Please refer to the errata See also translations This document is also available in these non-normative formats: XML Recent revisions (HTML) Copyright W3C ® MIT ERCIM Keio liability trademark document use 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 This is a Recommendation XML Query Working Group XML Activity This document incorporates minor changes made against the Proposed Recommendation of 25 January 2011. Changes to this document since the Proposed Recommendation are detailed in [H Revision Log] http://www.w3.org/2010/02/qt-applets/xquery10-update/ A Test Suite has been created for this document. Implementors are encouraged to run this test suite and report their results. The Test Suite can be found at http://dev.w3.org/2007/xquery-update-10-test-suite/ http://dev.w3.org/2007/xquery-update-10-test-suite/results/ No substantive changes have been made to this specification since its publication as a Proposed Recommendation. Please report errors in this document using W3C's public Bugzilla system http://www.w3.org/XML/2005/04/qt-bugzilla [email protected] http://lists.w3.org/Archives/Public/public-qt-comments/ This document has been reviewed by W3C Members, by software developers, and by other W3C groups and interested parties, and is endorsed by the Director as a W3C Recommendation. It is a stable document and may be used as reference material or cited from another document. W3C's role in making the Recommendation is to draw attention to the specification and to promote its widespread deployment. This enhances the functionality and interoperability of the Web. This document was produced by a group operating under the 5 February 2004 W3C Patent Policy public list of any patent disclosures Essential Claim(s) section 6 of the W3C Patent Policy 1 Introduction Terminology Extensions to XQuery 1.0 Extensions to the Processing Model Extensions to the Prolog Revalidation Declaration Variable Declaration Function Declaration Extensions to the Static Context New Kinds of Expressions Insert Delete Replace Replacing a Node Replacing the Value of a Node Rename Transform Compatibility of Updating Expressions Extensions to Existing Expressions FLWOR Expression Typeswitch Expression Conditional Expression Comma Expression Parenthesized Expression Function Call Other Expressions Extensions to Built-in Function Library fn:put Update Operations Update Primitives upd:insertBefore upd:insertAfter upd:insertInto upd:insertIntoAsFirst upd:insertIntoAsLast upd:insertAttributes upd:delete upd:replaceNode upd:replaceValue upd:replaceElementContent upd:rename upd:put Update Routines upd:mergeUpdates upd:applyUpdates upd:revalidate upd:removeType upd:setToUntyped upd:propagateNamespace Static Typing Feature Overview and notations Change to Static Typing Rules of XQuery 1.0 Core Grammar XQuery Update Facility 1.0 Prolog XQuery Update Facility 1.0 Expressions Insert Delete Replace Rename Transform Examples Conformance Minimal Conformance Optional Features Update Facility Static Typing Feature XQueryX Conformance A EBNF for XQuery 1.0 Grammar with Update extensions Terminal Symbols Implementation-Defined Items References Normative References Non-normative References Error Conditions New Error Codes Amendments to Existing Error Codes XML Syntax (XQueryX) for XQuery Update Facility 1.0 Schema Stylesheet Example XQuery Representation XQueryX Representation Transformed XQuery Representation Glossary Rationale for Precedence of Update Primitives Revision Log This document defines the syntax and semantics of an extension to [XQuery 1.0] [XQuery 1.0 and XPath 2.0 Data Model] [XQuery Update Facility 1.0 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 http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsl [ Definition XQuery [XQuery 1.0] Definition data model [XQuery 1.0 and XPath 2.0 Data Model] Definition XDM instance data model Definition node identity XDM instance Section 2.3 Node Identity DM As described in Section 3.3.3 QNames and NOTATIONS DM Definition implied namespace binding Definition conflict In this document, examples and material labeled as "Note" are provided for explanatory purposes and are not normative. Some of the examples in this document will be rejected by an implementation that supports the [4 Static Typing Feature] 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 zero or more XDM instances XDM instance node identities XQuery Update Facility 1.0 introduces a new category of expression called an updating expression 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 basic updating expression updating function [ Definition updating expression basic updating expression updating expression Note: The definition of an updating expression [ Definition simple expression updating expression [ Definition vacuous expressions Note: Every vacuous expression is identified explicitly in this specification. Some expressions can be determined to either return an empty sequence or raise an error, but are nevertheless not defined to be vacuous. For convenience, here is a list of the vacuous expressions: A call to the built-in function fn:error An empty parenthesized expression ( ) is a vacuous expression. A non-empty parenthesized expression is a vacuous expression if the expression it contains is a vacuous expression. If all branches are vacuous expressions, the typeswitch expression is a vacuous expression. If both branches are vacuous expressions, the conditional expression is a vacuous expression. If all operands are vacuous expressions, the comma expression is a vacuous expression. If the return clause of a FLWOR Expression is vacuous, the FLWOR expression is a vacuous expression. XQuery Update Facility 1.0 defines the places in which each type of expression can be used. In so doing, it makes small extensions to the syntax and semantics of certain existing expressions. The classification of each expression into one of the above categories is performed by static analysis, according to rules specified in this document for each type of expression. 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 XDM instance pending update list Definition pending update list update primitives Section 2.3.4 Errors and Optimization XQ XDM instance pending update list Note: In XQuery Update Facility 1.0, no expression returns both a non-empty XDM instance pending update list XQuery Update Facility 1.0 also defines a set of update operations Definition Update operations [3 Update Operations] [ Definition Update primitives pending update lists update primitive Definition target node pending update lists upd:applyUpdates [ Definition Update routines pending update lists upd:applyUpdates If the outermost expression in a query returns a pending update list upd:applyUpdates XDM instance upd:applyUpdates [3.2.2 upd:applyUpdates] [ Definition snapshot XDM instance upd:applyUpdates This specification defines the semantics of updates to an XDM instance 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 Definition revalidation declaration revalidation mode err:XUST0003 Revalidation mode [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 rule is added: If the expression on the right-hand-side of a variable declaration (the initializing expression) is not a simple expression err:XUST0001 26 FunctionDecl ::= "declare" "updating"? "function" QName ParamList SequenceType EnclosedExpr The syntax of a function declaration is extended with an optional keyword: updating Definition updating fn:put updating functions [XQuery 1.0] If updating If external simple expression err:XUST0001 If external pending update list err:XUDY0018 If updating A return type must not be specified [ err:XUST0028 If external updating expression vacuous expression err:XUST0002 If external pending update list XDM instance err:XUDY0019 The means by which an external function returns an XDM instance pending update list 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 following definition is added to the XQuery static context (documented in Section 2.1.1 Static Context XQ [ Definition Revalidation mode strict lax skip upd:revalidate The following entry is added to the table of static context components (documented in Section C.1 Static Context Components XQ Component: Revalidation mode Default initial value: lax Can be overwritten by an implementation: Yes (implementation defined.) Can be overwritten by a query: Yes, overwritable by declaration in query prolog. Scope: Module. Consistency rules: Must be strict lax skip 32 ExprSingle ::= FLWORExpr QuantifiedExpr TypeswitchExpr IfExpr InsertExpr DeleteExpr RenameExpr ReplaceExpr TransformExpr OrExpr XQuery Update Facility 1.0 extends the syntax of ExprSingle Note: In general, updating expressions snapshot update primitives [3.2.4 upd:removeType] [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 node nodes If before after The inserted nodes become the preceding (or following) siblings of the target node. If multiple nodes are inserted by a single insert expression, the nodes remain adjacent and their order preserves the node ordering of the source expression. If multiple groups of nodes are inserted by multiple insert expressions in the same snapshot If as first into as last into The inserted nodes become the first (or last) children of the target node. If multiple nodes are inserted by a single insert expression, the nodes remain adjacent and their order preserves the node ordering of the source expression. If multiple groups of nodes are inserted by multiple insert expressions in the same snapshot If into as first as last The inserted nodes become children of the target node. If multiple nodes are inserted by a single insert expression, their order preserves the node ordering of the source expression. The positions of the inserted nodes are chosen so as not to interfere with the intended position of nodes that are inserted with the specification before after as first into as last into 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 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 simple expression err:XUST0001 SourceExpr Section 3.7.1.3 Content XQ insertion sequence err:XUTY0004 $alist $clist Note: Either $alist $clist The target expression must be a simple expression err:XUST0001 If the result is an empty sequence, [ err:XUDY0027 If any form of into err:XUTY0005 If before after err:XUTY0006 If before after parent err:XUDY0029 Let $target If $alist into $target err:XUTY0022 No attribute node in $alist implied namespace binding conflicts $target err:XUDY0023 Multiple attribute nodes in $alist implied namespace bindings conflict err:XUDY0024 If $alist before after parent($target) err:XUDY0030 No attribute node in $alist implied namespace binding conflicts parent($target) err:XUDY0023 Multiple attribute nodes in $alist implied namespace bindings conflict err:XUDY0024 The result of the insert expression is an empty XDM instance pending update list If as first into pending update list update primitives If $alist upd:insertAttributes If $clist upd:insertIntoAsFirst If as last into pending update list update primitives If $alist upd:insertAttributes If $clist upd:insertIntoAsLast($target, $clist) If into as first as last pending update list update primitives If $alist upd:insertAttributes If $clist upd:insertInto If before $parent $target pending update list update primitives If $alist upd:insertAttributes If $clist upd:insertBefore($target, $clist) If after $parent $target pending update list update primitives If $alist upd:insertAttributes If $clist upd:insertAfter 144 DeleteExpr ::= "delete" ("node" | "nodes") TargetExpr 148 TargetExpr ::= ExprSingle A delete expression deletes zero or more nodes from an XDM instance node nodes 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 simple expression err:XUST0001 err:XUTY0007 $tlist If any node in $tlist $tlist A new pending update list $tnode $tlist update primitive upd:delete($tnode) XDM instance Notes: Since node deletions do not become effective until the end of a snapshot The semantics of a delete expression are defined in terms of their effect on an XDM instance 145 ReplaceExpr ::= "replace" ("value" "of")? "node" TargetExpr ExprSingle 148 TargetExpr ::= ExprSingle A replace expression is an updating expression value of If value of 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 simple expression err:XUST0001 Section 3.7.1.3 Content XQ $rlist $rlist $rlist The target expression must be a simple expression err:XUST0001 If the result is an empty sequence, [ err:XUDY0027 If the result is non-empty and does not consist of a single element, attribute, text, comment, or processing instruction node, [ err:XUTY0008 If the result consists of a node whose parent property is empty, [ err:XUDY0009 Let $target $parent If $target $rlist err:XUTY0010 If $target $rlist err:XUTY0011 No attribute node in $rlist implied namespace binding conflicts $parent err:XUDY0023 Multiple attribute nodes in $rlist implied namespace bindings conflict err:XUDY0024 The result of the replace expression is an empty XDM instance pending update list update primitive upd:replaceNode If value of node identity 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 simple expression err:XUST0001 [XQuery 1.0] $text The target expression must be a simple expression err:XUST0001 If the result is an empty sequence, [ err:XUDY0027 If the result is non-empty and does not consist of a single element, attribute, text, comment, or processing instruction node, [ err:XUTY0008 Let $target If $target XDM instance pending update list update primitive upd:replaceElementContent If $target $string $string If $target $string err:XQDY0072 If $target $string ?> err:XQDY0026 In the absence of errors, the result of a replace expression is an empty XDM instance pending update list update primitive upd:replaceValue 146 RenameExpr ::= "rename" "node" TargetExpr NewNameExpr 148 TargetExpr ::= ExprSingle 149 NewNameExpr ::= ExprSingle A rename expression replaces the name data model updating expression Examples: Rename the first author principal-author rename node fn:doc("bib.xml")/books/book[1]/author[1] as "principal-author" Rename the first author $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 simple expression err:XUST0001 If the result is an empty sequence, [ err:XUDY0027 If the result is non-empty and does not consist of a single element, attribute, or processing instruction node, [ err:XUTY0012 Let $target NewNameExpr simple expression err:XUST0001 NewNameExpr If $target $QName NewNameExpr Section 3.7.3.1 Computed Element Constructors XQ $QName namespaces $target err:XUDY0023 If $target $QName NewNameExpr Section 3.7.3.2 Computed Attribute Constructors XQ $QName $QName namespaces $target err:XUDY0023 If $target $NCName NewNameExpr Section 3.7.3.5 Computed Processing Instruction Constructors XQ $QName fn:QName((), $NCName) The result of the rename expression is an empty XDM instance pending update list update primitive upd:rename 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 abc xyz 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 ExprSingle ExprSingle A transform expression can be used to create modified copies of existing nodes in an XDM instance node identity XDM instance simple expression Examples: Return a sequence consisting of all employee salary for $e in //employee[skill = "Java"] return copy $je := $e modify delete node $je/salary return $je The following example copies a node, modifies the copy, and returns both the original node and the modified copy: let $oldx := /a/b/x return copy $newx := $oldx modify (rename node $newx as "newx", replace value of node $newx with $newx * 2) return ($oldx, $newx) Note: No persistent changes to the underlying data result from this example. A transform expression consists of three clauses, denoted by the keywords copy modify return The copy source expression The source expression must be a simple expression err:XUST0001 The result of evaluating the source expression must be a single node [ err:XUTY0013 $node A new copy is made of $node $node copied nodes parent children attributes $node For a copied element node, the type-name xs:untyped nilled is-id is-idrefs false For a copied attribute node, the type-name xs:untypedAtomic is-idrefs false is-id true xml:id false The string value of each copied element and attribute node remains unchanged, and its typed value becomes equal to its string value as an instance of xs:untypedAtomic Note: Implementations that store only the typed value of a node are required at this point to convert the typed value to a string form. If copy-namespaces mode preserve copy-namespaces no-preserve All other properties of the copied nodes are preserved. The variable name is bound to the top-level copied node generated in the previous step. The scope of this variable binding includes all subexpressions of the containing 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 updating expression vacuous expression err:XUST0002 modify pending update list target node update primitive err:XUDY0014 Let $pul $revalidation-mode $inherit-namespaces true copy-namespaces inherit false copy-namespaces no-inherit update operation upd:applyUpdates modify Note: In the event of incompatible updates, the upd:applyUpdates [3.2.2 upd:applyUpdates] The return simple expression err:XUST0001 return return The rules defining compatibility of updating expressions snapshot [3.2.2 upd:applyUpdates] Note: The effect of these rules is as follows: If any node is affected by more than one rename snapshot err:XUDY0015 If any node is affected by more than one replace value of snapshot err:XUDY0016 If any node is affected by more than one replace value of snapshot err:XUDY0017 If multiple calls to fn:put snapshot err:XUDY0031 Within a given snapshot E replace value of E E replace value of Suppose that $A B 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 $A "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 order by updating expression err:XUST0001 The return return If the return simple expression Section 3.8 FLWOR Expressions XQ If the return updating expression The semantics of the for let where order by Section 3.8 FLWOR Expressions XQ For each tuple generated by the previous step, the updating expression in the return pending update list All the pending update lists upd:mergeUpdates Note: In the event of incompatible updates, the upd:mergeUpdates [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 /inventory $changes part partno 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. Let the expressions in the case default branches If the operand expression of a typeswitch is an updating expression err:XUST0001 If any branch is an updating expression updating vacuous expressions err:XUST0001 updating expression If all branches are vacuous expressions vacuous expression Otherwise, the typeswitch expression is a simple expression If the typeswitch expression is a simple vacuous Section 3.12.2 Typeswitch XQ If the typeswitch expression is an updating expression Section 3.12.2 Typeswitch XQ return pending update list The semantics of conditional expressions are extended as follows. Let the expressions in the then else branches If the if-clause contains an updating expression err:XUST0001 If either branch is an updating expression updating vacuous expressions err:XUST0001 updating expression If both branches are vacuous expressions vacuous expression Otherwise, the conditional expression is a simple expression If the conditional expression is a simple vacuous Section 3.10 Conditional Expressions XQ If the conditional expression is an updating expression Section 3.10 Conditional Expressions XQ pending update list The following example illustrates the use of updating expressions in a conditional expression: If the element bound to variable $e last-updated 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 Constructing Sequences XQ If any operand is an updating expression updating vacuous expressions err:XUST0001 updating expression If all operands are vacuous expressions vacuous expression Otherwise, the comma expression is a simple expression If the comma expression is a simple vacuous Section 3.3.1 Constructing Sequences XQ If the comma expression is an updating expression pending update lists upd:mergeUpdates pending update list 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" 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 the expression enclosed in parentheses, which may have any category. The result of a parenthesized expression is also the same as the result of the expression enclosed in parentheses. An empty parenthesized expression ( ) vacuous expression pending update list 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] updating expression err:XUST0001 The expression category of a function call is as follows: A call to the built-in function fn:error vacuous expression A call to an updating function updating expression A call to any other function is a simple expression Note: This includes calls to built-in functions other than fn:error updating 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 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: $uri The external effects of fn:put fn:put fn:doc Semantics: fn:put If $node fn:put err:FOUP0001 If $uri xs:anyURI err:FOUP0002 $uri The result of a call to fn:put XDM instance pending update list update primitive upd:put Notes: The results of fn:put snapshot fn:put snapshot If a node that is an operand of fn:put snapshot fn:put snapshot $node $uri [3.2.2 upd:applyUpdates] If multiple calls to fn:put snapshot err:XUDY0031 fn:put [3.2.1 upd:mergeUpdates] [3.2.2 upd:applyUpdates] 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 pending update lists update routines pending update lists The update primitives described in this section may be held on pending update lists node identities upd:applyUpdates Parameters upd:insertBefore( $target as node(), $content as node()+) Summary Inserts $content $target Constraints $target parent $content Semantics Effects on nodes in $content For each node in $content parent parent($target) If the type-name parent($target) xs:untyped upd:setToUntyped() $content Effects on parent($target) The children parent($target) $content $target If at least one of the nodes in $content upd:removeType All the namespace bindings of parent($target) marked for namespace propagation Parameters upd:insertAfter( $target as node(), $content as node()+) Summary Inserts $content $target Constraints $target parent $content Semantics The semantics of upd:insertAfter upd:insertBefore The children parent($target) $content $target Parameters upd:insertInto( $target as node(), $content as node()+) Summary Inserts $content $target Constraints $target $content Semantics The semantics of upd:insertInto upd:insertBefore $target parent($target) The children $target $content Parameters upd:insertIntoAsFirst( $target as node(), $content as node()+) Summary Inserts $content $target Constraints $target $content Semantics The semantics of upd:insertIntoAsFirst upd:insertBefore $target parent($target) The children $target $content Parameters upd:insertIntoAsLast( $target as node(), $content as node()+) Summary Inserts $content $target Constraints $target $content Semantics The semantics of upd:insertIntoAsLast upd:insertBefore $target parent($target) The children $target $content Parameters upd:insertAttributes( $target as element(), $content as attribute()+) Summary Inserts $content $target Constraints None Semantics For each node $A $content The parent $A $target If the type-name $target xs:untyped upd:setToUntyped The following properties of $target attributes $content namespaces: $content marked for namespace propagation upd:removeType Parameters upd:delete( $target as node()) Constraints None Semantics If $target $P The parent $target If $target attributes $P $target If $target children $P $target If $target $P upd:removeType If $target XDM instance 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 Parameters upd:replaceNode( $target as node(), $replacement as node()*) Summary Replaces $target $replacement Constraints $target $target $replacement $target $replacement Semantics Effects on nodes in $replacement For each node in $replacement parent parent($target) If the type-name parent($target) xs:untyped upd:setToUntyped $replacement Effect on $target The parent $target Effects on parent($target) If $target attributes parent($target) $target $replacement If $target namespaces parent($target) $replacement marked for namespace propagation If $target children parent($target) $target $replacement $target If $target $replacement upd:removeType Parameters upd:replaceValue( $target as node(), $string-value as xs:string) Summary Replaces the string value of $target $string-value Constraints $target Semantics If $target string-value $target $string-value upd:removeType If $target content $target $string-value If $target upd:removeType Parameters upd:replaceElementContent( $target as element(), $text as text()?) Summary Replaces the existing children of the element node $target $text $target Constraints None. Semantics For each node $C $target parent $C The parent $text $target Effects on $target children $text $text $target typed-value string-value content $text $text typed-value string-value upd:removeType($target) Parameters upd:rename( $target as node(), $newName as xs:QName) Summary Changes the node-name of $target $newName Constraints $target Semantics If $target node-name $target $newName upd:removeType If $newname namespaces $target The namespaces $target $newName marked for namespace propagation If $target node-name $target $newName upd:removeType If $newName xml:id is-id $target true If $target namespaces parent($target) $newName marked for namespace propagation If $target target $newName Note: At the end of a snapshot upd:applyUpdates Parameters upd:put( $node as node(), $uri as xs:string) Summary The XDM node tree rooted at $node $uri Constraints $uri Semantics The external effects of upd:put upd:put fn:doc Parameters upd:mergeUpdates( $pul1 as pending-update-list, $pul2 as pending-update-list) Summary Merges two pending update lists Constraints None. Semantics The two pending update lists Optionally, upd:mergeUpdates Two or more upd:rename err:XUDY0015 Two or more upd:replaceNode err:XUDY0016 Two or more upd:replaceValue err:XUDY0017 Two or more upd:replaceElementContent err:XUDY0017 Two or more upd:put $uri err:XUDY0031 Two or more primitives on the merged list create conflicting err:XUDY0024 upd:insertAttributes $target implied namespace binding $content upd:replaceNode parent($target) implied namespace binding $replacement upd:rename $target $target $target implied namespace binding $newName Parameters upd:applyUpdates( $pul as pending-update-list, $revalidation-mode as xs:string, $inherit-namespaces as xs:boolean) Summary This routine ends a snapshot pending update list XDM instance Constraints $revalidation-mode "strict" "lax" "skip" Semantics Checks the update primitives on $pul Two or more upd:rename $pul err:XUDY0015 Two or more upd:replaceNode $pul err:XUDY0016 Two or more upd:replaceValue $pul err:XUDY0017 Two or more upd:replaceElementContent $pul err:XUDY0017 Two or more upd:put $uri err:XUDY0031 Two or more primitives on $pul conflicting err:XUDY0024 upd:insertAttributes parent($target) implied namespace binding $content upd:replaceNode $target implied namespace binding $replacement upd:rename $target $target $target implied namespace binding $newName The semantics of all update primitives $pul upd:put First, all upd:insertInto upd:insertAttributes upd:replaceValue upd:rename Next, all upd:insertBefore upd:insertAfter upd:insertIntoAsFirst upd:insertIntoAsLast Next, all upd:replaceNode Next, all upd:replaceElementContent Next, all upd:delete If, as a net result of the above steps, the children node identity If, as a net result of the above steps, the children children If, after applying the updates, any XDM instance [XQuery 1.0 and XPath 2.0 Data Model] 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 Overview DM Note: During processing of a pending update list XDM instance upd:put If $inherit-namespaces true upd:propagateNamespace marked for namespace propagation $element $prefix $uri For each document or element node $top marked for revalidation upd:revalidate($top, $revalidation-mode) As the final step, all upd:put $pul The upd:applyUpdates upd:applyUpdates XDM instance upd:applyUpdates XDM instance 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. Parameters upd:revalidate( $top as node(), $revalidation-mode as xs:string) Constraints $top $revalidation-mode "strict" "lax" "skip" Summary Schema validation is applied to the subtree rooted at $top node identities Semantics If $revalidation-mode skip upd:revalidate If $revalidation-mode lax $topV validate lax {$top} $revalidation-mode strict $topV validate strict {$top} $topV $topV $top Note: This step may raise an error [ err:XQDY0027 XQ $top Some of the nodes in $topV $top For each node $nV $topV $n $top $n $nV type-name typed-value string-value is-id is-idrefs namespace-bindings nilled For each node $nV $topV $top $nV $top $nV The result of upd:revalidate $top $topV 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. Parameters upd:removeType( $N as node()) Constraints $N Summary 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. Semantics If $N If type-name xs:untyped type-name xs:anyType If the parent of N upd:removeType(parent($N)) string-value typed-value string-value xs:untypedAtomic Note: The data model string-value typed-value nilled is-id is-idrefs false If $N type-name xs:untypedAtomic typed-value string-value xs:untypedAtomic is-id is-idrefs false If $N upd:removeType(parent($N)) The topmost ancestor of $N marked [ Definition mark Parameters upd:setToUntyped( $N as node()) Constraints $N Summary 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. Semantics If $N type-name xs:untyped typed-value string-value xs:untypedAtomic Note: The data model string-value typed-value nilled is-id is-idrefs false upd:setToUntyped() $N If $N type-name xs:untypedAtomic typed-value string-value xs:untypedAtomic is-idrefs false is-id false xml:id Parameters upd:propagateNamespace( $element as element(), $prefix as xs:NCName, $uri as xs:anyURI) Constraints None Summary Propagates a namespace binding to all descendants of an element. Semantics For each element $child $element $prefix add a namespace binding ($prefix, $uri) $child call upd:propagateNamespace($child, $prefix, $uri) 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] 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 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 inference rules [XQuery 1.0 and XPath 2.0 Formal Semantics] The judgment statEnv |- Expr : Type holds when, in the static environment statEnv Expr Type Notation The static environment is the same as the one defined in [XQuery 1.0 and XPath 2.0 Formal Semantics] statEnv revalidationMode The statEnv revalidationMode revalidation mode The statEnv revalidationMode strict lax skip XQuery 1.0 specifies that err:XPST0005 is raised if the Static Typing Feature is in effect and the static type assigned to an expression other than ( ) data(( )) empty-sequence( ) simple expressions updating expressions We extend the XQuery Core defined in [XQuery 1.0 and XPath 2.0 Formal Semantics] 23 (Core) ExprSingle ::= FLWORExpr QuantifiedExpr TypeswitchExpr IfExpr InsertExpr DeleteExpr RenameExpr ReplaceExpr TransformExpr OrExpr 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 ExprSingle 102 (Core) RenameExpr ::= "rename" "node" TargetExpr NewNameExpr 105 (Core) NewNameExpr ::= ExprSingle 106 (Core) TransformExpr ::= "copy" "$" VarName ExprSingle VarName ExprSingle ExprSingle ExprSingle The core grammar production for IfExpr [XQuery 1.0 and XPath 2.0 Formal Semantics] The core grammar production for OrExpr [XQuery 1.0 and XPath 2.0 Formal Semantics] The core grammar production for FLWORExpr [XQuery 1.0 and XPath 2.0 Formal Semantics] The core grammar production for QuantifiedExpr [XQuery 1.0 and XPath 2.0 Formal Semantics] The core grammar production for TypeswitchExpr [XQuery 1.0 and XPath 2.0 Formal Semantics] The core grammar production for VarName [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] Normalization Revalidation declarations are left unchanged through normalization. [ RevalidationDecl ] PrologDecl == RevalidationDecl Static Context Processing The revalidation declaration modifies the revalidation mode in the static context. statEnv 1 statEnv revalidationMode RevalidationMode statEnv |- RevalidationMode => stat statEnv 1 In addition to the normalization and static typing rules defined in [XQuery 1.0 and XPath 2.0 Formal Semantics] Normalization The following normalization rules apply to insert expressions. Note that whether the expression is written using the 'nodes' or 'node' modifier, the normalized expression always uses the 'nodes' modifier. [ Expr 1 InsertExprTargetChoice Expr 2 ] Expr == insert nodes fs: item-sequence-to-node-sequence [ Expr 1 ] Expr InsertExprTargetChoice [ Expr 2 ] Expr Where fs: item-sequence-to-node-sequence [XQuery 1.0 and XPath 2.0 Formal Semantics] Static Type Analysis The static typing rule for insert depends on whether it is an insert into before after In the case of an insert into statEnv |- Expr 1 : Type 1 statEnv |- Type 1 <: statEnv |- Expr 2 : Type 2 statEnv |- Type 2 <: statEnv |- Expr 1 Expr 2 : empty statEnv |- Expr 1 : Type 1 statEnv |- Type 1 <: statEnv |- Expr 2 : Type 2 statEnv |- Type 2 <: [ ] sequencetype statEnv |- Expr 1 Expr 2 : empty In the case of an insert before after statEnv |- Expr 1 : Type 1 statEnv |- Type 1 <: statEnv |- Expr 2 : Type 2 statEnv |- Type 2 <: statEnv |- Expr 1 Expr 2 : empty Normalization 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. [ Expr 1 ] Expr == delete nodes [ Expr 1 ] Expr Static Type Analysis The static typing rule for delete is as follows. statEnv |- Expr : Type statEnv |- Type <: [ ] sequencetype statEnv |- Expr : empty Normalization The following normalization rules applies to replace expressions. [ Expr 1 Expr 2 ] Expr == replace node [ Expr 1 ] Expr fs: item-sequence-to-node-sequence [ Expr 2 ] Expr Normalization of replace value of expressions. [ Expr 1 Expr 2 ] Expr == replace value of node [ Expr 1 ] Expr [ Expr 2 ] Expr Static Type Analysis If the value of An attribute node can be replaced only by zero or more attribute nodes. statEnv |- Expr 1 : Type 1 statEnv |- Type 1 <: statEnv |- Expr 2 : Type 2 statEnv |- Type 2 <: statEnv |- Expr 1 Expr 2 : empty An element, text, comment, or processing instruction node can be replaced only by zero or more element, text, comment, or processing instruction nodes. statEnv |- Expr 1 : Type 1 statEnv |- Type 1 <: statEnv |- Expr 2 : Type 2 statEnv |- Type 2 <: statEnv |- Expr 1 Expr 2 : empty If the value of statEnv |- Expr 1 : Type 1 statEnv |- Type 1 <: statEnv |- Expr 2 : Type 2 statEnv |- Type 2 <: statEnv |- Expr 1 Expr 2 : empty Normalization The following normalization rule applies to rename expressions. [ Expr 1 Expr 2 ] Expr == rename node [ Expr 1 ] Expr fn:data [ Expr 2 ] Expr Static Type Analysis 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 xs:untypedAtomic statEnv |- Expr 1 : Type 1 statEnv |- Type 1 <: statEnv |- Expr 2 : Type 2 statEnv |- Type 2 <: xs:QName xs:string xs:untypedAtomic statEnv |- Expr 1 Expr 2 : empty Normalization The following normalization rule applies to transform expressions. [ copy VarName 1 Expr 1 ... VarName n Expr n modify Expr 0 Expr r ] Expr == copy VarName 1 [ Expr 1 ] Expr ... VarName n [ Expr n ] Expr modify [ Expr 0 ] Expr [ Expr r ] Expr Static Type Analysis The transform expression is type checked using the following inference rule. statEnv |- Expr 1 : Type 1 statEnv |- Type 1 <: [ ] sequencetype statEnv |- VarName 1 of var expands to Variable 1 statEnv 1 statEnv varType Variable 1 [ ] sequencetype ... statEnv n-1 |- Expr n : Type n statEnv n-1 |- Type n <: [ ] sequencetype statEnv |- VarName n of var expands to Variable n statEnv n statEnv n-1 varType Variable n [ ] sequencetype statEnv n |- Expr 0 : Type 0 statEnv n |- Expr r : Type r statEnv |- copy VarName 1 Expr 1 ... VarName n Expr n modify Expr 0 Expr r : Type r 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 must not return a single node (assuming the schema allows //a a 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 This section defines the conformance criteria for an XQuery processor. In this section, the following terms are used to indicate the requirement levels defined in [RFC 2119] Definition MUST Definition MAY Definition SHOULD An XQuery processor that claims to conform to this specification MUST [5.1 Minimal Conformance] MAY [5.2 Optional Features] Minimal Conformance to this specification MUST Minimal Conformance to [XQuery 1.0] Support for everything specified in this document except those features specified in [5.2 Optional Features] [E XML Syntax (XQueryX) for XQuery Update Facility 1.0] MUST [5.2 Optional Features] A definition of every item specified to be implementation-defined, unless that item is part of an optional feature that is not supported by the implementation. A list of implementation-defined items can be found in [B Implementation-Defined Items] Note: Implementations are not required to define items specified to be implementation-dependent. An implementation of XQuery that includes the Update Facility MAY [XQuery 1.0] If an implementation claims support of the Static Typing Feature, then it MAY [ Definition Update Facility Static Typing Feature [4 Static Typing Feature] If an implementation does not support the Update Static Typing Feature MAY Note: An implementation that does not support the Update Static Typing Feature MUST This section defines the conformance criteria for an XQueryX processor that includes the Update Facility. In this section, the terms MUST MAY SHOULD [5 Conformance] An XQueryX processor that claims to conform to this specification MUST [E XML Syntax (XQueryX) for XQuery Update Facility 1.0] [5.1 Minimal Conformance] MAY [5.2 Optional Features] 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 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 URILiteral URILiteral 22 SchemaPrefix ::= ("namespace" NCName 23 ModuleImport ::= "import" "module" ("namespace" NCName URILiteral URILiteral URILiteral 24 VarDecl ::= "declare" "variable" "$" QName TypeDeclaration ExprSingle 25 ConstructionDecl ::= "declare" "construction" ("strip" | "preserve") 26 FunctionDecl ::= "declare" "updating"? "function" QName ParamList SequenceType EnclosedExpr 27 ParamList ::= Param Param 28 Param ::= "$" QName TypeDeclaration 29 EnclosedExpr ::= "{" Expr 30 QueryBody ::= Expr 31 Expr ::= ExprSingle ExprSingle 32 ExprSingle ::= FLWORExpr QuantifiedExpr TypeswitchExpr IfExpr InsertExpr DeleteExpr RenameExpr ReplaceExpr TransformExpr OrExpr 33 FLWORExpr ::= ( ForClause LetClause WhereClause OrderByClause ExprSingle 34 ForClause ::= "for" "$" VarName TypeDeclaration PositionalVar ExprSingle VarName TypeDeclaration PositionalVar 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 ExprSingle VarName TypeDeclaration ExprSingle ExprSingle 43 TypeswitchExpr ::= "typeswitch" "(" Expr CaseClause VarName ExprSingle 44 CaseClause ::= "case" ("$" VarName SequenceType ExprSingle 45 IfExpr ::= "if" "(" Expr ExprSingle ExprSingle 46 OrExpr ::= AndExpr AndExpr 47 AndExpr ::= ComparisonExpr ComparisonExpr 48 ComparisonExpr ::= RangeExpr ValueComp GeneralComp NodeComp RangeExpr 49 RangeExpr ::= AdditiveExpr AdditiveExpr 50 AdditiveExpr ::= MultiplicativeExpr MultiplicativeExpr 51 MultiplicativeExpr ::= UnionExpr UnionExpr 52 UnionExpr ::= IntersectExceptExpr IntersectExceptExpr 53 IntersectExceptExpr ::= InstanceofExpr InstanceofExpr 54 InstanceofExpr ::= TreatExpr SequenceType 55 TreatExpr ::= CastableExpr SequenceType 56 CastableExpr ::= CastExpr SingleType 57 CastExpr ::= UnaryExpr 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 68 PathExpr ::= ("/" RelativePathExpr RelativePathExpr 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 ::= "*" NCName NCName 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 ComputedConstructor 95 DirectConstructor ::= DirElemConstructor DirCommentConstructor DirPIConstructor 96 DirElemConstructor ::= "<" QName DirAttributeList DirElemContent QName S 97 DirAttributeList ::= ( S QName S S DirAttributeValue 98 DirAttributeValue ::= ('"' ( EscapeQuot QuotAttrValueContent EscapeApos AposAttrValueContent 99 QuotAttrValueContent ::= QuotAttrContentChar CommonContent 100 AposAttrValueContent ::= AposAttrContentChar CommonContent 101 DirElemContent ::= DirectConstructor CDataSection CommonContent ElementContentChar 102 CommonContent ::= PredefinedEntityRef CharRef EnclosedExpr 103 DirCommentConstructor ::= "<!--" DirCommentContents 104 DirCommentContents ::= (( Char Char 105 DirPIConstructor ::= "<?" PITarget S DirPIContents 106 DirPIContents ::= ( Char 107 CDataSection ::= "<![CDATA[" CDataSectionContents 108 CDataSectionContents ::= ( Char 109 ComputedConstructor ::= CompDocConstructor CompElemConstructor CompAttrConstructor CompTextConstructor CompCommentConstructor CompPIConstructor 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" "(" ")") ItemType OccurrenceIndicator 120 OccurrenceIndicator ::= "?" | "*" | "+" 121 ItemType ::= KindTest AtomicType 122 AtomicType ::= QName 123 KindTest ::= DocumentTest ElementTest AttributeTest SchemaElementTest SchemaAttributeTest PITest CommentTest TextTest AnyKindTest 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 ExprSingle 146 RenameExpr ::= "rename" "node" TargetExpr NewNameExpr 147 SourceExpr ::= ExprSingle 148 TargetExpr ::= ExprSingle 149 NewNameExpr ::= ExprSingle 150 TransformExpr ::= "copy" "$" VarName ExprSingle VarName ExprSingle ExprSingle ExprSingle 151 IntegerLiteral ::= Digits 152 DecimalLiteral ::= ("." Digits Digits 153 DoubleLiteral ::= (("." Digits Digits 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 The following items in this specification are implementation-defined: The revalidation modes that are supported by this implementation. The default revalidation mode for this implementation. The mechanism (if any) by which an external function can return an XDM instance and/or a pending update list to the invoking query. The semantics of fn:put() XQuery Update Facility 1.0 Requirements latest version XQuery 1.0 and XPath 2.0 Data Model (XDM) (Second Edition) et. al. latest version XQuery 1.0: An XML Query Language (Second Edition) et. al. latest version XQuery 1.0 and XPath 2.0 Functions and Operators (Second Edition) latest version XML Syntax for XQuery 1.0 (XQueryX) (Second Edition) latest version XQuery 1.0 and XPath 2.0 Formal Semantics (Second Edition) et. al. latest version S. Bradner. Key Words for use in RFCs to Indicate Requirement Levels. http://www.ietf.org/rfc/rfc2119.txt Internet Engineering Task Force. An Extensible Markup Language (XML) Patch Operations Framework Utilizing XML Path Language (XPath) Selectors. http://datatracker.ietf.org/doc/draft-ietf-simple-xml-patch-ops/ XQuery Update Facility 1.0 Use Cases latest version It is a static error if an updating expression The topmost expression in the body of a query. The modify The return The return return updating expression vacuous expression The then else then else updating expression vacuous expression An operand of a comma expression in which each operand is either an updating expression vacuous expression The content of a parenthesized expression. The body of a function declaration in which the keyword updating It is a static error if a simple expression vacuous expression The modify The top-level expression in the body of a function declaration in which the keyword updating 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 as last into In an insert expression where before after 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 In a replace expression where value of In a replace expression where value of 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 In a transform expression, it is a dynamic error if the modify copy It is a dynamic error if any node is the target of more than one rename It is a dynamic error if any node is the target of more than one replace value of It is a dynamic error if any node is the target of more than one replace value of It is a dynamic error if a function that was declared to be external updating It is a dynamic error if a function that was declared to be both external updating It is a dynamic error if the XDM instance [XQuery 1.0 and XPath 2.0 Data Model] 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 It is a dynamic error if the effect of a set of updating expressions is to introduce conflicting (Not currently used.) It is a static error if a revalidation declaration in a Prolog specifies a revalidation mode that is not supported by the current implementation. It is a dynamic error if the target expression of an insert, replace, or rename expression evaluates to an empty sequence. It is a static error if a function declaration specifies both updating In an insert expression where before after It is a dynamic error if an insert expression specifies the insertion of an attribute node before or after a child of a document node. It is a dynamic error if multiple calls to fn:put It is a dynamic error if the first operand of fn:put It is a dynamic error if the second operand of fn:put xs:anyURI During the analysis phase, it is a static error if the static type assigned to a simple expression other than ( ) data(( )) empty-sequence( ) It is a dynamic error if a constructor or replace expression would result in a processing instruction node whose content includes the string " ?> It is a dynamic error if the name assigned to a processing node by a constructor or rename expression cannot be cast to the type xs:NCName It is a dynamic error if a constructor or replace expression would result in a comment node whose content ends with a hyphen or contains two adjacent hyphens. It is a dynamic error if the value of the name expression in a computed element constructor, computed attribute constructor, or rename expression cannot be converted to an expanded QName (for example, because it contains a namespace prefix not found in the statically known namespaces.) [XQueryX 1.0] [XQuery 1.0] [XQuery Update Facility 1.0 Requirements] [A EBNF for XQuery 1.0 Grammar with Update extensions] The XML Schema specified in this appendix accomplishes its integration by importing the XML Schema defined for XQueryX in [XQueryX 1.0] 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 --> <!-- Reconfirmed correctness for CR 2008-02-27: 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 complex type --> <xsd:complexType name="functionDecl"> <xsd:complexContent> <xsd:extension base="functionDecl"> <xsd:attribute name="updatingFunction" type="xsd:boolean" default="false"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>

</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] <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 --> <!-- Surround updating exprs w/parens 2007-09-13: Jim Melton -->

<xsl:import href="http://www.w3.org/2005/XQueryX/xqueryx.xsl"/>

<!-- revalidationDecl --> <xsl:template match="xqxuf:revalidationDecl"> <xsl:text>declare revalidation </xsl:text> <xsl:apply-templates/> </xsl:template>

<!-- insertExpr --> <xsl:template match="xqxuf:insertExpr"> <xsl:value-of select="$LPAREN"/> <xsl:text>insert nodes </xsl:text> <xsl:value-of select="$NEWLINE"/> <xsl:apply-templates select="xqxuf:sourceExpr"/> <xsl:value-of select="$NEWLINE"/> <xsl:apply-templates select="xqxuf:insertInto | xqxuf:insertBefore | xqxuf:insertAfter"/> <xsl:value-of select="$NEWLINE"/> <xsl:apply-templates select="xqxuf:targetExpr"/> <xsl:value-of select="$RPAREN"/> </xsl:template>

<!-- sourceExpr --> <xsl:template match="xqxuf:sourceExpr"> <xsl:apply-templates/> </xsl:template>

<!-- insertInto --> <xsl:template match="xqxuf:insertInto"> <xsl:if test="child::node()"> <xsl:text>as </xsl:text> </xsl:if> <xsl:apply-templates/> <xsl:text>into </xsl:text> </xsl:template>

<!-- insertAsFirst --> <xsl:template match="xqxuf:insertAsFirst"> <xsl:text>first </xsl:text> </xsl:template>

<!-- insertAsLast --> <xsl:template match="xqxuf:insertAsLast"> <xsl:text>last </xsl:text> </xsl:template>

<!-- insertAfter --> <xsl:template match="xqxuf:insertAfter"> <xsl:text>after </xsl:text> </xsl:template>

<!-- insertBefore --> <xsl:template match="xqxuf:insertBefore"> <xsl:text>before </xsl:text> </xsl:template>

<!-- targetExpr --> <xsl:template match="xqxuf:targetExpr"> <xsl:apply-templates/> </xsl:template>

<!-- deleteExpr --> <xsl:template match="xqxuf:deleteExpr"> <xsl:value-of select="$LPAREN"/> <xsl:text>delete nodes </xsl:text> <xsl:apply-templates/> <xsl:value-of select="$RPAREN"/> </xsl:template>

<!-- replaceExpr --> <xsl:template match="xqxuf:replaceExpr"> <xsl:value-of select="$LPAREN"/> <xsl:text>replace </xsl:text> <xsl:if test="xqxuf:replaceValue"> <xsl:text>value of </xsl:text> </xsl:if> <xsl:text>node </xsl:text> <xsl:apply-templates select="xqxuf:targetExpr"/> <xsl:text> with </xsl:text> <xsl:apply-templates select="xqxuf:replacementExpr"/> <xsl:value-of select="$RPAREN"/> </xsl:template>

<!-- replacementExpr --> <xsl:template match="xqxuf:replacementExpr"> <xsl:apply-templates/> </xsl:template>

<!-- renameExpr --> <xsl:template match="xqxuf:renameExpr"> <xsl:value-of select="$LPAREN"/> <xsl:text>rename node </xsl:text> <xsl:apply-templates select="xqxuf:targetExpr"/> <xsl:text> as </xsl:text> <xsl:apply-templates select="xqxuf:newNameExpr"/> <xsl:value-of select="$RPAREN"/> </xsl:template>

<!-- newNameExpr --> <xsl:template match="xqxuf:newNameExpr"> <xsl:apply-templates/> </xsl:template>

<!-- transformExpr --> <xsl:template match="xqxuf:transformExpr"> <xsl:value-of select="$LPAREN"/> <xsl:text>copy </xsl:text> <xsl:apply-templates select="xqxuf:transformCopies"/> <xsl:value-of select="$NEWLINE"/> <xsl:text> modify </xsl:text> <xsl:apply-templates select="xqxuf:modifyExpr"/> <xsl:value-of select="$NEWLINE"/> <xsl:text> return </xsl:text> <xsl:apply-templates select="xqxuf:returnExpr"/> <xsl:value-of select="$RPAREN"/> </xsl:template>

<!-- Part of transformExpr --> <xsl:template match="xqxuf:transformCopies"> <xsl:call-template name="commaSeparatedList"/> </xsl:template>

<!-- Part of transformExpr --> <xsl:template match="xqxuf:transformCopy"> <xsl:apply-templates select="xqx:varRef"/> <xsl:text> := </xsl:text> <xsl:apply-templates select="xqxuf:copySource"/> </xsl:template>

<!-- Part of transformExpr --> <xsl:template match="xqxuf:copySource"> <xsl:apply-templates/> </xsl:template>

<!-- Part of transformExpr --> <xsl:template match="xqxuf:modifyExpr"> <xsl:apply-templates/> </xsl:template>

<!-- Part of transformExpr --> <xsl:template match="xqxuf:returnExpr"> <xsl:apply-templates/> </xsl:template>

<!-- Over-ride the template for functionDecl in XQueryX.xsd --> <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] [XQuery Update Facility 1.0 Use Cases] [E.2 Stylesheet] a 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] 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] 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] xquery version "1.0";

( for $keyword at $i in ("car", "skateboard", "canoe"), $parent in fn:doc("part-tree.xml")/descendant-or-self::part [(attribute::name = $keyword)] let $descendants:=$parent/descendant-or-self::part for $p in ($parent, $descendants) return replace value of node $p/attribute::partid with (($i*1000)+$p/attribute::partid) ) The term XDM instance data model Within this document, the term XQuery [XQuery 1.0] A basic updating expression updating function Two namespace bindings are said to conflict The term data model [XQuery 1.0 and XPath 2.0 Data Model] The implied namespace binding To mark MAY MUST The term node identity XDM instance Section 2.3 Node Identity DM A pending update list update primitives A revalidation declaration revalidation mode Revalidation mode strict lax skip upd:revalidate SHOULD A simple expression updating expression A snapshot XDM instance The Update Facility Static Typing Feature [4 Static Typing Feature] The first argument of an update primitive, called its target node Update operations [3 Update Operations] Update primitives pending update lists update primitive Update routines pending update lists An updating expression basic updating expression updating expression Functions whose declarations contain the keyword updating fn:put updating functions Certain expressions are defined in this specification to be vacuous expressions In [3.2.2 upd:applyUpdates] update primitives pending update list insertAttribute replaceValue rename put insertInto insertIntoAsFirst/Last insertBefore/After insertBefore/After replaceNode insertIntoAsFirst/Last replaceElementContent replaceElementContent replaceNode replaceElementContent replaceNode delete put The following substantive changes have been made to this document since the Candidate Recommendation of 9 June 2009. Minor editorial changes are not included in this log. Fixed a bug involving namespace propagation and default namespaces. Resolves Bug 9432 Added missing parameter to upd:applyUpdates(). Resolves Bug 9262 Added missing text governing namespace binding conflicts when the namespace prefix for an attribute is absent. Resolves Bug 9257 Fixed two errors governing namespace bindings created by upd:replaceNode(). The erroneous text said that the namespace binding was created on the attribute itself, rather than the parent element. Resolves Bug 9256 Added a note indicating that some examples are rejected by implementations that support static typing. See Bug 8006 The following substantive changes have been made to this document since the Candidate Recommendation of 14 March 2008. Added a rule: the expression on the right-hand-side of a variable declaration the initializing expression) must be a simple expression. Resolves Bug 5699. Section affected: [2.2.2 Variable Declaration] When a rename expression operates on an attribute node, err:XUDY0023 can be raised only if the new name of the attribute is in a namespace. Renaming an attribute to a QName that has neither a namespace prefix nor a namespace URI is not an error, even if the parent element has a default namespace. Partial resolution of Bug 5629. Section affected: [2.4.4 Rename] When a upd:rename $newname [3.1.11 upd:rename] Optional error err:XUDY0020 (deletion of a node that has no parent) is made part of the semantics of the delete expression (formerly it was described under the upd:delete [2.4.2 Delete] [3.1.7 upd:delete] Error err:XUDY0024 (updates introducing conflicting namespace bindings) is made part of the semantics of the insert and replace expressions. Also, consistency constraints on Pending Update Lists, raising err:XUDY0024 if multiple primitives on a PUL have conflicting namespace bindings, have been added to the semantics of upd:mergeUpdates upd:applyUpdates upd:insertAttributes upd:replaceNode upd:rename [2.4.1 Insert] [2.4.3 Replace] [3.1.6 upd:insertAttributes] [3.1.8 upd:replaceNode] [3.1.11 upd:rename] [3.2.1 upd:mergeUpdates] [3.2.2 upd:applyUpdates] The following changes were made to the semantics of fn:put fn:put upd:put [2.6.1 fn:put] [3.1.12 upd:put] It is an error to invoke fn:put [2.4.6 Compatibility of Updating Expressions] [3.2.1 upd:mergeUpdates] [3.2.2 upd:applyUpdates] [D.1 New Error Codes] fn:put [2.2.3 Function Declaration] Moved the subsection on Function Declarations inside the section on Extensions to the Prolog. Resolves Bug 5701. Section affected: [2.2.3 Function Declaration] In the Static Typing Feature for XQuery Update Facility, err:XPST0005 applies only to simple expressions (not to updating expressions.) Resolves Bug 5700. Sections affected: [4.2 Change to Static Typing Rules of XQuery 1.0] [D.2 Amendments to Existing Error Codes] In the Static Type Analysis for TransformExpr, the static type of each copy-variable used to be the type inferred from its source expression; now it's just node(). No substantive changes have been made to this document since the Proposed Recommendation of 25 January 2011.

Related documents

Record · ID 153183 · SHA-256 a04c0945332849e3
Conceptio Open Knowledge Archive — every document is proof-bundled with source, license, and retrieval metadata.