<spec xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" id="spec-top" w3c-doctype="cr">
<header>
<title>XQuery Update Facility 1.0</title>
<w3c-designation>CR-xquery-update-10</w3c-designation>
<w3c-doctype>W3C Candidate Recommendation</w3c-doctype>
<pubdate>
 <day>1</day>
 <month>August</month>
 <year>2008</year>
</pubdate>

<publoc>
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2008/CR-xquery-update-10-20080801/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/2008/CR-xquery-update-10-20080801/</loc>
</publoc>

<altlocs>
   <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2008/CR-xquery-update-10-20080801/xquery-update-10.xml" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML</loc>
</altlocs>

<latestloc>
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/xquery-update-10/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/xquery-update-10/</loc>
</latestloc>

<prevlocs>
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2008/CR-xquery-update-10-20080314/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/>,
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2007/WD-xquery-update-10-20070828/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/>,
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2006/WD-xqupdate-20060711/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/>
<!--
<loc href="http://www.w3.org/TR/2006/WD-xqupdate-20060508/"/>
<loc href="http://www.w3.org/TR/2006/WD-xqupdate-20060127/"/>
<loc href="http://www.w3.org/TR/2006/WD-xqupdate-20060127/"/>
<loc href="http://www.w3.org/TR/2005/WD-xqupdate-20050404/"/>
<loc href="http://www.w3.org/TR/2004/WD-xqupdate-20040709/"/>
-->
</prevlocs>

<!-- 20080727: Jim removed Don Chamberlin's "blatant web site URI" per request from Phillippe Le Hageret -->
<authlist>
  <author>
    <name><phrase><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.almaden.ibm.com/cs/people/chamberlin/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Don Chamberlin</loc></phrase></name>
    <affiliation>IBM Almaden Research Center</affiliation>
  </author>
  <author>
    <name>Daniela Florescu</name>
    <affiliation>Oracle</affiliation>
    <email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:dana.florescu@oracle.com" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">dana.florescu@oracle.com</email>
  </author>
  <author>
    <name>Jim Melton</name>
    <affiliation>Oracle</affiliation>
    <email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:jim.melton@oracle.com" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">jim.melton@oracle.com</email>
  </author>
  <author>
    <name>Jonathan Robie</name>
    <affiliation>Red Hat</affiliation>
    <email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:jonathan.robie@redhat.com" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">jonathan.robie@redhat.com</email>
  </author>
  <author>
    <name>Jérôme Siméon</name>
    <affiliation>IBM T.J. Watson Research Center</affiliation>
    <email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:simeon@us.ibm.com" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">simeon@us.ibm.com</email>
  </author>
</authlist>

<abstract>
<p>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.</p>
</abstract>

<!--
<status>
<p>
<emph>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 <loc href="http://www.w3.org/TR/">W3C technical reports index</loc> at 
http://www.w3.org/TR/.</emph>
</p>

<p>
This is a
<loc href="http://www.w3.org/2005/10/Process-20051014/tr.html#last-call" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Last Call Working Draft</loc>
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 
<loc href="http://www.w3.org/XML/Query/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML Query Working Group</loc>
(part of the 
<loc href="http://www.w3.org/XML/Activity.html" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML Activity</loc>).
It is designed to be read in conjunction with the following documents:
<bibref ref="xquery"/>, <bibref ref="update-req"/>, and <bibref ref="update-use-cases"/>. 
</p>

<p>
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.
</p>

<p>
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
<loc href="http://www.w3.org/TR/xquery/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XQuery 1.0</loc>. 
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. 
</p>

<p>
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 <specref ref="id-revision-log"/>.</p>


<p>Of the XQuery Update Facility documents, only this document,
&language;, is a Last Call document. 
The XQuery Update Facility Requirements <bibref ref="update-req"/>,
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 <bibref ref="update-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. 
</p>

<p>
Public Last Call comments on this document and its open issues are invited.
Comments on this document are due by &doc.last-call-comments-due;.
Comments on this document should be made in W3C's
<loc href="http://www.w3.org/Bugs/Public/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public Bugzilla system</loc>
for this specification (instructions can be found at
<loc href="http://www.w3.org/XML/2005/04/qt-bugzilla" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/XML/2005/04/qt-bugzilla</loc>). 
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,
<loc href="mailto:public-qt-comments@w3.org" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public-qt-comments@w3.org</loc>.
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
<loc href="http://lists.w3.org/Archives/Public/public-qt-comments/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://lists.w3.org/Archives/Public/public-qt-comments/</loc>.
</p>

<p>
This document was produced by a group operating under the
<loc href="http://www.w3.org/Consortium/Patent-Policy-20040205/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">5 February 2004
W3C Patent Policy</loc>.
W3C maintains a 
<loc href="http://www.w3.org/2004/01/pp-impl/18797/status#disclosures" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public list of any 
patent disclosures</loc>
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
<loc href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Essential 
Claim(s)</loc>
must disclose the information in accordance with
<loc href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">section 6 of the W3C 
Patent Policy</loc>. 
</p>

</status>

-->

<!--* Common status section for QT specs.
    * Use is currently not required, but it simplifies things.
    * 
    * Revisions:
    * 2007-01-15 : CMSMcQ : made file, to simplify publication of Rec.
    * 2008-02-15 : JimMelton : cloned from MSM's REC-only material
                     to generalize for all stages
    *-->

    <status id="status">

<!-- ************************************************************************** -->
<!-- * All Status sections must start with the standard boilerplate paragraph * -->
<!-- *   This entity is defined in status-entities.dtd                        * -->
<!-- ************************************************************************** -->
      <p><emph>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
         <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">W3C technical reports index</loc>
         at http://www.w3.org/TR/.</emph></p>

<!-- ************************************************************************** -->
<!-- * QT publishes suites of documents, which must be described in the       * -->
<!--     Status section of each document within such a suite.                 * -->
<!-- *   This entity is defined in the host document.                         * -->
<!-- ************************************************************************** -->
      

<!-- ************************************************************************** -->
<!-- * There is a lot of detailed customization based on the document stage   * -->
<!-- *   This entity is defined in the host document.                         * -->
<!-- ************************************************************************** -->
      <p>W3C publishes a <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/02/Process-20040205/tr.html#RecsCR" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Candidate Recommendation</loc>, as described in the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/02/Process-20040205/tr.html" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Process Document</loc>,
to indicate that the document is believed to be stable and to encourage implementation
by the developer community.
The publication of this document constitutes a
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/02/Process-20040205/tr.html#cfi" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">call for implementations</loc>
of this specification. </p>
<p>This document has been developed by the W3C <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/XML/Query/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML Query Working Group</loc>,
which is part of the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/XML/Activity" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML Activity</loc>.
It will remain a Candidate Recommendation until at least 20 June 2008.
The Working Group expects to advance this specification to <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/02/Process-20040205/tr.html#RecsW3C" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Recommendation</loc> Status.</p>
<p>The <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/XML/Query/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML Query Working Group</loc> intends to submit
this document for consideration as a W3C
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/02/Process-20040205/tr.html#RecsPR" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Proposed Recommendation</loc>
as soon as the following conditions are met:
</p>
<olist>
<item><p>A test suite is available that tests each identified XQuery Update Facility feature,
both required and optional.</p></item>
<item><p>Minimal Conformance to this specification, as defined in
      <specref ref="id-minimal-conformance"/>, has been demonstrated by at least 
      two distinct implementations, at least one of which uses the XQuery human-readable 
      syntax defined in this specification.</p></item>
<item><p>The Working Group has responded formally to all issues raised during
      the CR period against this document.</p></item>
</olist>
<p>Once the entrance criteria for Proposed Recommendation have been achieved,
the Director will be requested to advance this document to <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/02/Process-20040205/tr.html#RecsPR" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Proposed Recommendation</loc> status. 
Working closely with the developer community, we expect to show evidence of implementations
by approximately 31 August 2008. </p>

<!-- ************************************************************************** -->
<!-- * CR documents must cite features at risk                                * -->
<!-- *   This entity is defined in the host document.                         * -->
<!-- ************************************************************************** -->
      <p>The following
features are considered to be at risk:</p>
<ulist>
<item><p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#dt-revalidation-mode" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Revalidation modes other than "skip"</loc></p></item>
<item><p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#id-update-facility-static-typing-feature" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">the Update Facility Static Typing Feature</loc></p></item>
<item><p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#id-xqueryx-update-conformance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XQueryX Conformance</loc></p></item>
</ulist>
<p>They may be removed if implementations of them do not exist
at the end of the Candidate Recommendation period.</p>

<!-- ************************************************************************** -->
<!-- * Every Status section must have a customized paragraph                  * -->
<!-- *   This entity is defined completely in the host document.              * -->
<!-- ************************************************************************** -->
      <p>The XML Query WG
is republishing this document on 1 August 2008,
to reflect changes made in response to comments received so far
during the Candidate Recommendation period. </p>
<p>The WG still solicits comment on a key design principle of this specification: 
As indicated in <specref ref="id-processing-model"/>, expressions may return <emph>either</emph>
a value <emph>or</emph> a pending update list, but not both. 
We specifically solicit feedback on that decision. </p>

<!-- ************************************************************************** -->
<!-- * CR docs should, and PR docs must, have a pointer to an implementation  * -->
<!-- *   report.  We also want to point to the test suite.                    * -->
<!-- *   This entity is defined in the host document.                         * -->
<!-- ************************************************************************** -->
      <p>A Test Suite for this document is under development.
Implementors are encouraged to run this test suite and report their results.
The Test Suite can be found at <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://dev.w3.org/2007/xquery-update-10-test-suite/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://dev.w3.org/2007/xquery-update-10-test-suite/</loc>. 
In addition, a preliminary implementation report is available at
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://dev.w3.org/2007/xquery-update-10-test-suite/results/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://dev.w3.org/2007/xquery-update-10-test-suite/results/</loc>.</p>

<!-- ************************************************************************** -->
<!-- * The Status section should point to a changelog                         * -->
<!-- *   This entity is defined in the host document.                         * -->
<!-- ************************************************************************** -->
      <p>This document incorporates changes made against the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/02/Process-20040205/tr.html#RecsCR" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Candidate Recommendation</loc> of 14 March 2008.
  Changes to this document since the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/02/Process-20040205/tr.html#RecsCR" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Candidate Recommendation</loc> are detailed in
  <specref ref="id-revision-log"/>.</p>

<!-- ************************************************************************** -->
<!-- * The Status section must tell readers where to send comments            * -->
<!-- *   This entity is defined in status-entities.dtd                        * -->
<!-- ************************************************************************** -->
      <p>Please report errors in this document using W3C's
         <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Bugs/Public/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public Bugzilla system</loc>
         (instructions can be found at
         <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/XML/2005/04/qt-bugzilla" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/XML/2005/04/qt-bugzilla</loc>).
         If access to that system is not feasible, you may send your comments
         to the W3C XSLT/XPath/XQuery public comments mailing list,
         <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:public-qt-comments@w3.org" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public-qt-comments@w3.org</loc>.
         It will be very helpful if you include the string 
         “[UPD]”
         in the subject line of your report, whether made in Bugzilla or in email.
         Please use multiple Bugzilla entries (or, if necessary, multiple email messages)
         if you have more than one comment to make.
         Archives of the comments and responses are available at
         <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://lists.w3.org/Archives/Public/public-qt-comments/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://lists.w3.org/Archives/Public/public-qt-comments/</loc>. </p>

<!-- ************************************************************************** -->
<!-- Status sections must state the stability (not stable, or REC) of the document -->
<!-- *   This entity is defined in the host document.                         * -->
<!-- ************************************************************************** -->
      <p>Publication as a Candidate Recommendation
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.</p>

<!-- ************************************************************************** -->
<!-- * Finally, all Status sections must end with the appropriate IPR para    * -->
<!-- *   This entity is defined in status-entities.dtd                        * -->
<!-- ************************************************************************** -->
      
<p>This document was produced by a group operating under the
  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Consortium/Patent-Policy-20040205/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">5 February 2004
  W3C Patent Policy</loc>.
  W3C maintains a 
  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2004/01/pp-impl/18797/status#disclosures" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public list of any patent disclosures</loc>
  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
  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Essential Claim(s)</loc>
  must disclose the information in accordance with
  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
  section 6 of the W3C Patent Policy</loc>. </p>


    </status>


<langusage>
  <language id="EN">English</language>
  <language id="ebnf">EBNF</language>
</langusage>

<revisiondesc>
  <p>September 2005: First internal draft</p>
  <p>November 2005: Second internal draft</p>
  <p>27 January 2006: First public working draft</p>
  <p>8 May 2006: Second public working draft</p>
  <p>11 July 2006: Third public working draft</p>
  <p>28 August 2007: Last Call working draft</p>
  <p>14 March 2008: Candidate Recommendation</p>
  <p>1 August 2008: Revised Candidate Recommendation</p>
</revisiondesc>
</header>
<body>

<div1 id="introduction">
  <head>Introduction</head>

<p>
This document defines the syntax and semantics of an extension 
to <bibref ref="xquery"/> called the XQuery Update Facility 1.0.
This language extension is designed to meet the
requirements for updating instances of the  <bibref ref="datamodel"/>, as defined in <bibref ref="update-req"/>.</p>

<p>
The XQuery Update Facility 1.0 provides facilities to perform any or all
of the following operations on an
<termref def="dt-xdm-instance">XDM instance</termref>:
</p>
<ulist>
<item><p>Insertion of a node.</p></item>
<item><p>Deletion of a node.</p></item>
<item><p>Modification of a node by changing
some of its properties while preserving its <termref def="dt-node-identity">node identity</termref>.</p></item>
<item><p>Creation of a modified copy of a node with a new <termref def="dt-node-identity">node identity</termref>.</p></item>
</ulist>

<p>
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
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsd" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsd</loc>,
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx-redef.xsd" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx-redef.xsd</loc>,
and <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsl" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsl</loc>,
respectively. 
</p>

  
<div2 id="id-terminology">
<head>Terminology</head>
<p>
<termdef term="XQuery" id="dt-xquery">Within this document,
the term <term>XQuery</term> refers to the language specified by <bibref ref="xquery"/>.</termdef>
<termdef term="data model" id="dt-data-model">The term <term>data model</term> refers to
the data model specified by <bibref ref="datamodel"/>.</termdef>
<termdef term="XDM instance" id="dt-xdm-instance">The term <term>XDM instance</term>
denotes an unconstrained sequence of zero or more nodes and/or atomic values
as defined by the <termref def="dt-data-model">data model</termref>.</termdef>
<termdef term="node identity" id="dt-node-identity">The term <term>node identity</term>
denotes the unique identity that is a property of every node in an
<termref def="dt-xdm-instance">XDM instance</termref>
(see <xspecref spec="DM" ref="node-identity"/>.)</termdef>
</p>
<p>
As described in <xspecref spec="DM" ref="qnames-and-notations"/>,
names in XQuery are qualified names (QNames) that consist of an
optional namespace prefix, a local name, and an optional namespace URI. 
<termdef term="implied namespace binding" id="dt-implied-namespace-binding">The
<term>implied namespace binding</term> of a QName is the association of its namespace prefix
(or absence thereof) with its namespace URI (or absence thereof).</termdef>
<termdef term="conflict" id="dt-conflict">Two namespace bindings are said to
<term>conflict</term> if their namespace prefixes (or absence thereof) are
the same but their namespace URI's (or absence thereof) are different.</termdef>
Update operations that result in conflicting namespace bindings generally raise errors,
as described in this document.
</p>
</div2>
</div1>


<div1 id="id-extensions">
<head>Extensions to XQuery 1.0</head>

<p>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 
<termref def="dt-xdm-instance">XDM instances</termref> as input and returns an <termref def="dt-xdm-instance">XDM instance</termref> 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 <termref def="dt-node-identity">node identities</termref>.</p>

<p>XQuery Update Facility 1.0 introduces a new category of expression called an <termref def="dt-updating-expression">updating expression</termref>, which can potentially modify the state of an existing node.</p>

<p>The extensions to XQuery 1.0 provided by XQuery Update Facility 1.0 may be characterized 
as follows:</p>

<olist>
<item><p>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.</p></item><item><p>XQuery Update Facility 1.0 classifies XQuery expressions into the following categories:<olist><item><p><termdef term="basic updating expression" id="dt-basic-updating-expression">A <term>basic updating expression</term> is an insert, delete, replace, or rename expression, or a call to an <termref def="dt-updating-function">updating function</termref>.</termdef></p></item><item><p><termdef term="updating expression" id="dt-updating-expression">An <term>updating expression</term> is a <termref def="dt-basic-updating-expression">basic updating expression</termref> or any
expression (other than a transform expression) that directly
contains an <termref def="dt-updating-expression">updating expression</termref>.</termdef></p><note><p>The definition of an <termref def="dt-updating-expression">updating expression</termref> is recursive.</p></note></item><item><p><termdef term="simple expression" id="dt-simple-expression">A <term>simple expression</term> is any XQuery expression that is not an <termref def="dt-updating-expression">updating expression</termref>.</termdef></p></item><item><p><termdef term="vacuous expression" id="dt-vacuous-expression">A <term>vacuous expression</term> is a <termref def="dt-simple-expression">simple expression</termref> that can only return an empty sequence or raise an error.</termdef></p></item></olist></p> </item>

<item><p>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.</p></item>



</olist><p>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.</p>

<div2 id="id-processing-model">
<head>Extensions to the Processing Model</head><p>XQuery Update Facility 1.0 defines the following extensions to the XQuery processing model:</p><olist><item><p>In XQuery 1.0, the result of each expression is an <termref def="dt-xdm-instance">XDM instance</termref>. XQuery Update Facility 1.0 extends the XQuery processing model so that the
result of an expression consists of both an <termref def="dt-xdm-instance">XDM instance</termref> and a <termref def="dt-pending-update-list">pending update list</termref> (either or both of which may be empty). <termdef id="dt-pending-update-list" term="pending update list">A <term>pending update list</term> is an unordered collection of <termref def="dt-update-primitive">update primitives</termref>, which represent node state changes that have not yet been applied.</termdef> The term "result" used in <xspecref spec="XQ" ref="id-errors-and-opt"/> includes both the  <termref def="dt-xdm-instance">XDM instance</termref> and the <termref def="dt-pending-update-list">pending update list</termref> returned by an expression.</p><note><p>In XQuery Update Facility 1.0, no expression returns both a non-empty <termref def="dt-xdm-instance">XDM instance</termref> and a non-empty <termref def="dt-pending-update-list">pending update list</termref>.</p></note></item><item><p>XQuery Update Facility 1.0 also defines a set of <termref def="dt-update-operation">update operations</termref>. <termdef term="update operation" id="dt-update-operation"><term>Update operations</term> are used in defining the semantics of XQuery updates, but are not directly available to users. Update operations are defined in <specref ref="id-update-operations"/>.</termdef> Update operations fall into the following categories:</p><olist><item><p> <termdef term="update primitive" id="dt-update-primitive"><term>Update primitives</term> are the components of <termref def="dt-pending-update-list">pending update lists</termref>. Each <term>update primitive</term> represents a node state change that has not yet been applied.</termdef> <termdef term="target node" id="dt-target-node">The first argument of an update primitive, called its <term>target node</term>, is the principal node to be affected by the update primitive.</termdef> Update primitives are held on <termref def="dt-pending-update-list">pending update lists</termref> until they are made effective by a <code>upd:applyUpdates</code> operation.</p></item><item><p><termdef term="update routine" id="dt-update-routine"><term>Update routines</term> are sequences of actions that are used in the definition of XQuery semantics but do not appear on <termref def="dt-pending-update-list">pending update lists</termref>.</termdef> <code>upd:applyUpdates</code> is an example of an update routine.</p></item></olist></item><item><p>If the outermost expression in a query returns a <termref def="dt-pending-update-list">pending update list</termref>, <code>upd:applyUpdates</code> is implicitly invoked, supplying as arguments (a) the pending update list, and (b) the value of the revalidation
mode in the static context of the main query module. This invocation of <code>upd:applyUpdates</code> may raise an error (see <specref ref="id-upd-apply-updates"/> for possible error codes.)</p></item></olist><p><termdef id="dt-snapshot" term="snapshot">A <term>snapshot</term> is a scope within which expressions are evaluated
with respect to a fixed <termref def="dt-xdm-instance">XDM instance</termref> and updates are held pending.</termdef> A snapshot
is terminated by invocation of the <code>upd:applyUpdates</code> operation. XQuery Update Facility 1.0 defines an entire query as one snapshot.</p><p>This specification defines the semantics of updates to an <termref def="dt-xdm-instance">XDM instance</termref>.
Propagation of these updates to an underlying persistent store (if any)
is beyond the scope of this specification.</p></div2>

<div2 id="id-prolog-extensions"><head>Extensions to the Prolog</head><div3 id="id-revalidation-declaration"><head>Revalidation Declaration</head><scrap headstyle="show"> 
<head/> 
<prod num="7" id="doc-xquery-Setter"><lhs>Setter</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-BoundarySpaceDecl" xlink:type="simple">BoundarySpaceDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DefaultCollationDecl" xlink:type="simple">DefaultCollationDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-BaseURIDecl" xlink:type="simple">BaseURIDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ConstructionDecl" xlink:type="simple">ConstructionDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-OrderingModeDecl" xlink:type="simple">OrderingModeDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-EmptyOrderDecl" xlink:type="simple">EmptyOrderDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-RevalidationDecl" xlink:type="simple">RevalidationDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CopyNamespacesDecl" xlink:type="simple">CopyNamespacesDecl</nt></rhs></prod> 
<prod num="141" id="doc-xquery-RevalidationDecl"><lhs>RevalidationDecl</lhs><rhs>"declare"  "revalidation"  ("strict"  |  "lax"  |  "skip")</rhs></prod>
</scrap><p>The Prolog is extended by adding a new kind of <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-Setter" xlink:type="simple">Setter</nt>
called a revalidation declaration. 
<termdef term="revalidation declaration" id="dt-revalidation-decl">A <term>revalidation declaration</term>
sets the <termref def="dt-revalidation-mode">revalidation mode</termref> in the static context,
overriding any implementation-defined default.</termdef>
If a Prolog contains more than one revalidation declaration,
a static error is raised <errorref code="0003" class="ST"/>. 
<termref def="dt-revalidation-mode">Revalidation mode</termref> controls the process by which type information
is recovered for an updated document, as described in <specref ref="id-upd-revalidate"/></p>

<p>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 <errorref code="0026" class="ST"/>.</p></div3><div3 id="id-variable-declaration"><head>Variable Declaration</head><p>The following rule is added: If the expression on the right-hand-side of a variable declaration (the initializing expression) is not a <termref def="dt-simple-expression">simple expression</termref>, a static error is raised <errorref code="0001" class="ST"/>.</p></div3><div3 id="id-function-declaration"><head>Function Declaration</head><scrap headstyle="show"><head/>
<prod num="26" id="doc-xquery-FunctionDecl"><lhs>FunctionDecl</lhs><rhs>"declare"  "updating"?  "function"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  "("  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ParamList" xlink:type="simple">ParamList</nt>?  ")"  ("as"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SequenceType" xlink:type="simple">SequenceType</nt>)?  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-EnclosedExpr" xlink:type="simple">EnclosedExpr</nt>  |  "external")</rhs></prod>
</scrap>

<p>The syntax of a function declaration is extended to include an optional keyword: <code>updating</code>. <termdef term="updating function" id="dt-updating-function">Functions whose declarations contain the keyword <code>updating</code>, and certain built-in functions including <code>fn:put</code>, are called <term>updating functions</term>.</termdef> The semantics of a function declaration, described in Section 4.15 of <bibref ref="xquery"/>,  are extended as follows:</p><olist><item><p>If <code>updating</code> is not specified:</p><olist><item><p>If <code>external</code> is not specified, the EnclosedExpr in the function declaration must be a <termref def="dt-simple-expression">simple expression</termref>; otherwise a static error is raised <errorref code="0001" class="ST"/>.</p></item><item><p>If <code>external</code> is specified, the external function  must not return a non-empty <termref def="dt-pending-update-list">pending update list</termref>; otherwise a dynamic error is raised <errorref code="0018" class="DY"/>.</p></item></olist></item><item><p>If <code>updating</code> is specified:</p><olist><item><p>A return type must not  be specified <errorref code="0028" class="ST"/>.</p></item><item><p>If <code>external</code> is not specified, the EnclosedExpr in the function declaration must be an <termref def="dt-updating-expression">updating expression</termref> or a <termref def="dt-vacuous-expression">vacuous expression</termref>; otherwise a static error is raised <errorref code="0002" class="ST"/>.</p></item><item><p>If <code>external</code> is specified, the external function may return a non-empty <termref def="dt-pending-update-list">pending update list</termref> but it must not return a non-empty <termref def="dt-xdm-instance">XDM instance</termref>; otherwise a dynamic error is raised <errorref code="0019" class="DY"/>.</p></item></olist></item></olist><p>The means by which an external function returns an <termref def="dt-xdm-instance">XDM instance</termref> or a <termref def="dt-pending-update-list">pending update list</termref> is implementation-defined.</p><p>The following example illustrates a declaration of an updating function.</p><ulist><item><p>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.</p><eg xml:space="preserve">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
   }</eg></item></ulist></div3></div2>

<div2 id="id-static-context-extensions"><head>Extensions to the Static Context</head>

<olist>

<item><p>The following definition is added to the XQuery static context
(documented in <xspecref ref="static_context" spec="XQ"/>):</p>

<p><termdef term="revalidation mode" id="dt-revalidation-mode"><term>Revalidation mode</term>,
which may be <code>strict</code>, <code>lax</code>, or <code>skip</code>,
is a component of the static context that controls the behavior of the
<code>upd:revalidate</code> operation.</termdef></p>
</item>

<item>
<p>The following entry is added to the table of static context components
(documented in <xspecref ref="id-xq-static-context-components" spec="XQ"/>):</p>

<ulist>

<item>
<p>Component: Revalidation mode</p>
</item>

<item>
<p>Default initial value: <code>lax</code>.</p>
</item>

<item>
<p>Can be overwritten by an implementation: Yes (implementation defined.)</p>
</item>

<item>
<p>Can be overwritten by a query: Yes, overwritable by declaration in query prolog.</p>
</item>

<item>
<p>Scope: Module.</p>
</item>

<item>
<p>Consistency rules: Must be <code>strict</code>, <code>lax</code>, or <code>skip</code>.</p>
</item>

</ulist>

</item>

</olist>

</div2>

<div2 id="id-new-expressions"><head>New Kinds of Expressions</head>
<scrap headstyle="show"> 
<head/> 
<prod num="32" id="doc-xquery-ExprSingle"><lhs>ExprSingle</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-FLWORExpr" xlink:type="simple">FLWORExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QuantifiedExpr" xlink:type="simple">QuantifiedExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TypeswitchExpr" xlink:type="simple">TypeswitchExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-IfExpr" xlink:type="simple">IfExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-InsertExpr" xlink:type="simple">InsertExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-DeleteExpr" xlink:type="simple">DeleteExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-RenameExpr" xlink:type="simple">RenameExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ReplaceExpr" xlink:type="simple">ReplaceExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-TransformExpr" xlink:type="simple">TransformExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-OrExpr" xlink:type="simple">OrExpr</nt></rhs></prod> 

</scrap>



<p>XQuery Update Facility 1.0 extends the syntax of <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt> 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.</p>

<note><p>In general, <termref def="dt-updating-expression">updating expressions</termref> 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 <termref def="dt-snapshot">snapshot</termref>. For more details on type loss and recovery, see the <termref def="dt-update-primitive">update primitives</termref> associated with each updating expression; see also <specref ref="id-upd-remove-type"/> and <specref ref="id-upd-revalidate"/>.</p></note><div3 id="id-insert"><head>Insert</head><scrap headstyle="show"><head/>
<prod num="143" id="doc-xquery-InsertExpr"><lhs>InsertExpr</lhs><rhs>"insert"  ("node"  |  "nodes")  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-SourceExpr" xlink:type="simple">SourceExpr</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-InsertExprTargetChoice" xlink:type="simple">InsertExprTargetChoice</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-TargetExpr" xlink:type="simple">TargetExpr</nt></rhs></prod>
<prod num="142" id="doc-xquery-InsertExprTargetChoice"><lhs>InsertExprTargetChoice</lhs><rhs>(("as"  ("first"  |  "last"))?  "into")<br/>|  "after"<br/>|  "before"</rhs></prod>
<prod num="147" id="doc-xquery-SourceExpr"><lhs>SourceExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod><prod num="148" id="doc-xquery-TargetExpr"><lhs>TargetExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod></scrap>



<p>An insert expression is an <termref def="dt-updating-expression">updating expression</termref> that inserts copies of zero or more nodes into a 
designated position with respect to a target node. The keywords <code>node</code> and <code>nodes</code> may be used interchangeably, regardless of how many nodes are actually inserted. The position of the inserted nodes is determined as follows:</p><ulist><item><p>If <code>before</code> (or <code>after</code>) is specified:</p><ulist><item><p>The inserted nodes become the preceding (or following) siblings of the 
target node.</p></item><item><p>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.</p></item><item><p>If multiple groups of nodes are inserted by multiple insert expressions 
in the same <termref def="dt-snapshot">snapshot</termref>, adjacency and ordering of nodes within each group is 
preserved but ordering among the groups is implementation-dependent.
</p></item></ulist></item><item><p>If <code>as first into</code> (or <code>as last into</code>) is specified:</p><ulist><item><p>The inserted nodes become the first (or last) children of the target 
node.</p></item><item><p>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.</p></item><item><p>If multiple groups of nodes are inserted by multiple insert expressions 
in the same <termref def="dt-snapshot">snapshot</termref>, adjacency and ordering of nodes within each group is 
preserved but ordering among the groups is implementation-dependent.</p></item></ulist></item><item><p>If <code>into</code> is specified without <code>as first</code> or <code>as last</code>:</p><ulist><item><p>The inserted nodes become children of the target node.</p></item><item><p>If multiple nodes are inserted by a single insert expression, their 
order preserves the node ordering of the source expression.</p></item><item><p>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 <code>before</code>, <code>after</code>, 
<code>as first into</code>, or <code>as last into</code>. 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".</p></item><item><p>Subject to the above constraints, the positions of the inserted nodes 
among the children of the target node are implementation-dependent.</p></item></ulist></item></ulist><p>Examples:</p><ulist><item><p>Insert a <code>year</code> element after the publisher of the first book.</p><eg xml:space="preserve">insert node &lt;year&gt;2005&lt;/year&gt;
    after fn:doc("bib.xml")/books/book[1]/publisher</eg></item><item><p>Navigating by means of several bound variables, insert a new police report into the list of police reports for a particular accident.</p><eg xml:space="preserve">insert node $new-police-report
   as last into fn:doc("insurance.xml")/policies
      /policy[id = $pid]
      /driver[license = $license]
      /accident[date = $accdate]
      /police-reports</eg></item></ulist><p>The semantics of an insert 
expression are as follows:</p>

<olist>
<item><p><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-SourceExpr" xlink:type="simple">SourceExpr</nt> must be a <termref def="dt-simple-expression">simple expression</termref>; otherwise a static error is raised <errorref code="0001" class="ST"/>. <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-SourceExpr" xlink:type="simple">SourceExpr</nt> is evaluated as though it were an enclosed 
expression in an element constructor (see Rule 1e in <xspecref spec="XQ" ref="id-content"/>). The result of this step is either an error or a 
sequence of nodes to be inserted, called the <term>insertion sequence</term>. 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 <errorref code="0004" class="TY"/>. Let <code>$alist</code> be the sequence of attribute nodes in the insertion sequence. Let <code>$clist</code> be the remainder of the insertion sequence, in its original order.</p><note><p>Either <code>$alist</code> or <code>$clist</code> or both may be empty.</p></note></item>

<item><p>The target expression must be a <termref def="dt-simple-expression">simple expression</termref>; otherwise a static error is raised <errorref code="0001" class="ST"/>. The target expression is evaluated and checked as follows:</p><olist><item><p>If the result is an empty sequence, <errorref code="0027" class="DY"/> is raised.</p></item><item><p>If any form of <code>into</code> is specified, 
the result must be a single element or document node; any other non-empty result raises a type error <errorref code="0005" class="TY"/>.</p></item><item><p>If <code>before</code> or <code>after</code> 
is specified, the result must be a single element, text, comment, or processing instruction node; any other non-empty result raises a type error  <errorref code="0006" class="TY"/>.</p></item><item><p>If <code>before</code> or <code>after</code> 
is specified, the node returned by the target expression must have a non-empty <code>parent</code> property <errorref code="0029" class="DY"/>.</p></item></olist><p>  Let 
<code>$target</code> be the  node returned by the target expression.</p></item><item><p>If <code>$alist</code> is not empty and any form of <code>into</code> is specified, the following checks are performed:</p><olist><item><p><code>$target</code> must be an element node <errorref code="0022" class="TY"/>.</p></item><item><p>No attribute node in <code>$alist</code> may have a QName whose <termref def="dt-implied-namespace-binding">implied namespace binding</termref> <termref def="dt-conflict">conflicts</termref> with a namespace binding in the "namespaces" property of <code>$target</code> <errorref code="0023" class="DY"/>.</p></item><item><p>Multiple attribute nodes in <code>$alist</code> may not have QNames whose <termref def="dt-implied-namespace-binding">implied namespace bindings</termref> <termref def="dt-conflict">conflict</termref> with each other <errorref code="0024" class="DY"/>.</p></item></olist></item>

<item><p>If <code>$alist</code> is not empty and <code>before</code> or <code>after</code> is specified, the following checks are performed:</p><olist><item><p> <code>parent($target)</code> must be an element node <errorref code="0030" class="DY"/>.</p></item><item><p>No attribute node in <code>$alist</code> may have a QName whose <termref def="dt-implied-namespace-binding">implied namespace binding</termref> <termref def="dt-conflict">conflicts</termref> with a namespace binding in the "namespaces" property of <code>parent($target)</code> <errorref code="0023" class="DY"/>.</p></item><item><p>Multiple attribute nodes in <code>$alist</code> may not have QNames whose <termref def="dt-implied-namespace-binding">implied namespace bindings</termref> <termref def="dt-conflict">conflict</termref> with each other <errorref code="0024" class="DY"/>.</p></item></olist></item><item><p>The result of the insert expression is an empty <termref def="dt-xdm-instance">XDM instance</termref> and a <termref def="dt-pending-update-list">pending update list</termref> 
constructed as follows:</p>

<olist>
<item><p>If <code>as first into</code> is specified, the <termref def="dt-pending-update-list">pending update list</termref> consists of the following <termref def="dt-update-primitive">update primitives</termref>:</p><olist><item><p>If <code>$alist</code> is not empty, <code>upd:insertAttributes($target, $alist)</code></p></item><item><p>If <code>$clist</code> is not empty, <code>upd:insertIntoAsFirst($target, $clist)</code></p></item></olist></item>

<item><p>If <code>as last into</code> is specified, the <termref def="dt-pending-update-list">pending update list</termref> consists of the following <termref def="dt-update-primitive">update primitives</termref>:</p><olist><item><p>If <code>$alist</code> is not empty, <code>upd:insertAttributes($target, $alist)</code></p></item><item><p>If <code>$clist</code> is not empty, <code>upd:insertIntoAsLast($target, $clist)</code></p></item></olist></item>

<item><p>If <code>into</code> is specified with neither <code>as first</code> nor <code>as last</code>, the <termref def="dt-pending-update-list">pending update list</termref> consists of the following <termref def="dt-update-primitive">update primitives</termref>:</p><olist><item><p>If <code>$alist</code> is not empty, <code>upd:insertAttributes($target, $alist)</code></p></item><item><p>If <code>$clist</code> is not empty, <code>upd:insertInto($target, $clist)</code></p></item></olist></item>



<item><p>If <code>before</code> is specified, let <code>$parent</code> be the parent node of <code>$target</code>. The <termref def="dt-pending-update-list">pending update list</termref> consists of the following <termref def="dt-update-primitive">update primitives</termref>:</p><olist><item><p>If <code>$alist</code> is not empty, <code>upd:insertAttributes($parent, $alist)</code></p></item><item><p>If <code>$clist</code> is not empty, <code>upd:insertBefore($target, $clist)</code></p></item></olist></item>

<item><p>If <code>after</code> is specified, let <code>$parent</code> be the parent node of <code>$target</code>. The <termref def="dt-pending-update-list">pending update list</termref> consists of the following <termref def="dt-update-primitive">update primitives</termref>:</p><olist><item><p>If <code>$alist</code> is not empty, <code>upd:insertAttributes($parent, $alist)</code></p></item><item><p>If <code>$clist</code> is not empty, <code>upd:insertAfter($target, $clist)</code></p></item></olist></item>

</olist>
</item>
</olist></div3><div3 id="id-delete"><head>Delete</head><scrap headstyle="show"><head/>
<prod num="144" id="doc-xquery-DeleteExpr"><lhs>DeleteExpr</lhs><rhs>"delete"  ("node"  |  "nodes")  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-TargetExpr" xlink:type="simple">TargetExpr</nt></rhs></prod>
<prod num="148" id="noid_N107B7.doc-xquery-TargetExpr"><lhs>TargetExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod></scrap>



<p>A delete expression deletes zero or more nodes from an <termref def="dt-xdm-instance">XDM instance</termref>. 
The keywords <code>node</code> and <code>nodes</code> may be used interchangeably, regardless of how many nodes are actually deleted. A delete expression is an <termref def="dt-updating-expression">updating expression</termref>.</p><p>Examples:</p><ulist><item><p>Delete the last author of the first book in a given bibliography.</p><eg xml:space="preserve">delete node fn:doc("bib.xml")/books/book[1]/author[last()]</eg></item><item><p>Delete all email messages that are more than 365 days old.</p><eg xml:space="preserve">delete nodes /email/message
     [fn:currentDate() - date &gt; xs:dayTimeDuration("P365D")]</eg></item></ulist><p>The semantics of a delete expression are as follows:
</p>

<olist>
<item><p>The target expression must be a <termref def="dt-simple-expression">simple expression</termref>; otherwise a static error is raised <errorref code="0001" class="ST"/>. The target expression is evaluated. The result must be a 
sequence of zero or more nodes; otherwise a type error is raised <errorref code="0007" class="TY"/>. 
Let <code>$tlist</code> be the list of nodes returned by 
the target expression.</p></item><item><p>If any node in <code>$tlist</code> has no parent, an implementation may (but is not required to) raise a dynamic error <errorref code="0020" class="DY"/>.</p></item>

<item><p>A new <termref def="dt-pending-update-list">pending update list</termref> is created. For each node 
<code>$tnode</code> in <code>$tlist</code>, the following <termref def="dt-update-primitive">update primitive</termref> is appended  to the pending update list: <code>upd:delete($tnode)</code>. The resulting 
pending update list (together with an empty <termref def="dt-xdm-instance">XDM instance</termref>)  is the result of the delete expression.</p></item>

</olist><notes><ulist><item><p>Since node deletions do not become effective until the end of a <termref def="dt-snapshot">snapshot</termref>, they have no effect on variable bindings or on the set of available documents or collections within the current query.</p></item><item><p>The semantics of a delete expression are defined in terms of their effect on an  <termref def="dt-xdm-instance">XDM instance</termref>: the deleted nodes are detached from their parents after completion of the current query. The effects of a delete expression on persistent storage are beyond the scope of this specification.</p></item></ulist></notes></div3><div3 id="id-replace"><head>Replace</head><scrap headstyle="show"><head/>
<prod num="145" id="doc-xquery-ReplaceExpr"><lhs>ReplaceExpr</lhs><rhs>"replace"  ("value"  "of")?  "node"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-TargetExpr" xlink:type="simple">TargetExpr</nt>  "with"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod>
<prod num="148" id="noid_N10830.doc-xquery-TargetExpr"><lhs>TargetExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod></scrap>



<p>A replace expression is an <termref def="dt-updating-expression">updating expression</termref>. A replace expression has two forms, depending on whether <code>value of</code> 
is specified.</p>

<div4 id="id-replacing-node"><head>Replacing a Node</head><p>If <code>value of</code> 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:</p><ulist><item><p>Replace the publisher of the first book with the publisher of the second book.</p><eg xml:space="preserve">replace node fn:doc("bib.xml")/books/book[1]/publisher
with fn:doc("bib.xml")/books/book[2]/publisher</eg></item></ulist><p> The semantics of this form of replace expression are as follows:
</p>

<olist><item><p>The expression following the keyword <code>with</code> must be a <termref def="dt-simple-expression">simple expression</termref>; otherwise a static error is raised <errorref code="0001" class="ST"/>. This expression is evaluated as though it were an enclosed 
expression in an element constructor (see Rule 1e in <xspecref spec="XQ" ref="id-content"/>). Let <code>$rlist</code> be the node sequence that results from this evaluation. If <code>$rlist</code> contains a document node, the document node is replaced in <code>$rlist</code> by its children.</p></item>



<item><p>The target expression must be a <termref def="dt-simple-expression">simple expression</termref>; otherwise a static error is raised <errorref code="0001" class="ST"/>. The target expression is evaluated and checked as follows:</p><olist><item><p>If the result is an empty sequence, <errorref code="0027" class="DY"/> is raised.</p></item><item><p>If the result is non-empty and does not consist of a single element, attribute, text, comment, or processing instruction node, <errorref code="0008" class="TY"/> is raised.</p></item><item><p>If the result consists of a node whose parent property is empty, <errorref code="0009" class="DY"/> is raised.</p></item></olist><p>  Let 
<code>$target</code> be the  node returned by the target expression, and let <code>$parent</code> be its parent node.</p></item><item><p>If <code>$target</code> is an element, text, comment, or processing 
instruction node, then <code>$rlist</code> must consist exclusively of zero or more element, text, comment, or processing instruction nodes <errorref code="0010" class="TY"/>.</p>

   
</item><item><p>If <code>$target</code> is an attribute node, then:</p><olist><item><p> <code>$rlist</code> must consist exclusively of zero or more attribute nodes <errorref code="0011" class="TY"/>.</p></item><item><p>No attribute node in <code>$rlist</code> may have a QName whose <termref def="dt-implied-namespace-binding">implied namespace binding</termref> <termref def="dt-conflict">conflicts</termref> with a namespace binding in the "namespaces" property of <code>$parent</code> <errorref code="0023" class="DY"/>.</p></item><item><p>Multiple attribute nodes in <code>$rlist</code> may not have QNames whose <termref def="dt-implied-namespace-binding">implied namespace bindings</termref> <termref def="dt-conflict">conflict</termref> with each other <errorref code="0024" class="DY"/>.</p></item></olist></item><item><p>The result of the replace expression is an empty <termref def="dt-xdm-instance">XDM instance</termref> and a <termref def="dt-pending-update-list">pending update list</termref> consisting of the following <termref def="dt-update-primitive">update primitive</termref>:
<code>upd:replaceNode($target, $rlist)</code></p></item>

</olist></div4><div4 id="id-replacing-node-value"><head>Replacing the Value of a Node</head><p>If <code>value of</code> is specified, 
a replace expression is used to modify the value of a node while preserving 
its <termref def="dt-node-identity">node identity</termref>. Example:</p><ulist><item><p>Increase the price of the first book by ten percent.</p><eg xml:space="preserve">replace value of node fn:doc("bib.xml")/books/book[1]/price
with fn:doc("bib.xml")/books/book[1]/price * 1.1</eg></item></ulist><p>The semantics of this form of replace expression are as 
follows:
</p>

<olist><item><p>The expression following the keyword <code>with</code> must be a <termref def="dt-simple-expression">simple expression</termref>; otherwise a static error is raised <errorref code="0001" class="ST"/>. This expression is evaluated as though it were the content 
expression of a text node constructor (see  Section 3.7.3.4 of 
<bibref ref="xquery"/>.) The result of this step, in the absence of errors, is 
either a single text node or an empty sequence. Let <code>$text</code> be the result of this step. 
</p></item>

<item><p>The target expression must be a <termref def="dt-simple-expression">simple expression</termref>; otherwise a static error is raised <errorref code="0001" class="ST"/>. The target expression is evaluated and checked as follows:</p><olist><item><p>If the result is an empty sequence, <errorref code="0027" class="DY"/> is raised.</p></item><item><p>If the result is non-empty and does not consist of a single element, attribute, text, comment, or processing instruction node, <errorref code="0008" class="TY"/> is raised.</p></item></olist><p>  Let 
<code>$target</code> be the  node returned by the target expression.</p></item><item><p>If <code>$target</code> is an element node, the result of the replace 
expression is an empty <termref def="dt-xdm-instance">XDM instance</termref> and a <termref def="dt-pending-update-list">pending update list</termref> consisting of the following <termref def="dt-update-primitive">update primitive</termref>: <code>upd:replaceElementContent($target, $text)</code></p></item>



<item><p>If <code>$target</code> is an attribute, text, comment, or processing 
instruction node, let <code>$string</code> be the string value of the text node 
constructed in Step 1. If Step 1 did not construct 
a text node, let <code>$string</code> be a zero-length string.

Then:</p><olist><item><p>If <code>$target</code> is a comment node, and <code>$string</code> contains two adjacent hyphens or ends with a hyphen, a dynamic error is raised <errorref code="0072" class="DY"/>.</p></item><item><p>If <code>$target</code> is a processing instruction node, and <code>$string</code> contains the substring "<code>?&gt;</code>", a dynamic error is raised <errorref code="0026" class="DY"/>.</p></item><item><p>In the absence of errors, the result of a replace expression is an empty <termref def="dt-xdm-instance">XDM instance</termref> and a <termref def="dt-pending-update-list">pending update list</termref> containing the following <termref def="dt-update-primitive">update primitive</termref>: 
<code>upd:replaceValue($target, $string)</code>.</p></item></olist></item>

</olist></div4></div3><div3 id="id-rename"><head>Rename</head><scrap headstyle="show"><head/>
<prod num="146" id="doc-xquery-RenameExpr"><lhs>RenameExpr</lhs><rhs>"rename"  "node"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-TargetExpr" xlink:type="simple">TargetExpr</nt>  "as"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-NewNameExpr" xlink:type="simple">NewNameExpr</nt></rhs></prod>
<prod num="148" id="noid_N10998.doc-xquery-TargetExpr"><lhs>TargetExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod><prod num="149" id="doc-xquery-NewNameExpr"><lhs>NewNameExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod></scrap>



<p>A rename expression replaces the <code>name</code> property of a <termref def="dt-data-model">data model</termref> node with a 
new QName. A rename expression is an <termref def="dt-updating-expression">updating expression</termref>.</p><p>Examples:</p><ulist><item><p>Rename the first <code>author</code> element of the first book to <code>principal-author</code>.</p><eg xml:space="preserve">rename node fn:doc("bib.xml")/books/book[1]/author[1]
as "principal-author"</eg></item><item><p>Rename the first <code>author</code> element of the first book to the QName that is the value of the variable <code>$newname</code>.</p><eg xml:space="preserve">rename node fn:doc("bib.xml")/books/book[1]/author[1]
as $newname</eg></item></ulist><p>The semantics of a rename expression are as follows:</p>

<olist>

<item><p>The target expression must be a <termref def="dt-simple-expression">simple expression</termref>; otherwise a static error is raised <errorref code="0001" class="ST"/>. The target expression is evaluated and checked as follows:</p><olist><item><p>If the result is an empty sequence, <errorref code="0027" class="DY"/> is raised.</p></item><item><p>If the result is non-empty and does not consist of a single element, attribute, or processing instruction node, <errorref code="0012" class="TY"/> is raised.</p></item></olist><p>  Let 
<code>$target</code> be the  node returned by the target expression.</p></item><item><p><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-NewNameExpr" xlink:type="simple">NewNameExpr</nt> must be a <termref def="dt-simple-expression">simple expression</termref>; otherwise a static error is raised <errorref code="0001" class="ST"/>. <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-NewNameExpr" xlink:type="simple">NewNameExpr</nt> is 
processed as follows:</p><olist><item><p>If <code>$target</code> is an element node, let <code>$QName</code> be the result of evaluating
<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-NewNameExpr" xlink:type="simple">NewNameExpr</nt> as though it were the name expression of a computed element
constructor  (see <xspecref spec="XQ" ref="id-computedElements"/>). If the namespace binding of <code>$QName</code>
conflicts with any namespace binding in the <code>namespaces</code> property of <code>$target</code>, a
dynamic error is raised <errorref code="0023" class="DY"/>.</p></item><item><p>If <code>$target</code> is an attribute node, let <code>$QName</code> be the result of evaluating
<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-NewNameExpr" xlink:type="simple">NewNameExpr</nt> as though it were the name expression of a computed attribute
constructor (see <xspecref spec="XQ" ref="id-computedAttributes"/>). If <code>$QName</code> has a non-absent namespace URI, and if the namespace binding of <code>$QName</code>
conflicts with any namespace binding in the <code>namespaces</code> property of the parent
(if any) of <code>$target</code>, a dynamic error is raised <errorref code="0023" class="DY"/>.</p></item><item><p>If <code>$target</code> is a processing instruction node, let <code>$NCName</code> be the result of
evaluating <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-NewNameExpr" xlink:type="simple">NewNameExpr</nt> as though it were the name expression of a computed
processing instruction constructor (see <xspecref spec="XQ" ref="id-computed-pis"/>), and let <code>$QName</code> be
defined as <code>fn:QName((), $NCName)</code>.</p></item></olist></item>

<item><p>The result of the rename expression is an empty <termref def="dt-xdm-instance">XDM instance</termref> and a <termref def="dt-pending-update-list">pending update list</termref> 
containing the following <termref def="dt-update-primitive">update primitive</termref>: 
<code>upd:rename($target, $QName)</code>.</p></item>

</olist><note><p>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 <code>$root</code> and all its attributes and descendants, changing all QNames with the prefix <code>abc</code> to have a new prefix <code>xyz</code> and a new namespace URI <code>http://xyz/ns</code>.<eg xml:space="preserve">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)
)</eg></p></note></div3><div3 id="id-transform"><head>Transform</head><scrap headstyle="show"><head/>
<prod num="150" id="doc-xquery-TransformExpr"><lhs>TransformExpr</lhs><rhs>"copy"  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt>  ":="  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>  (","  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt>  ":="  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>)*  "modify"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>  "return"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod>
</scrap>



<p>A transform expression can be used to create modified copies of existing nodes in an <termref def="dt-xdm-instance">XDM instance</termref>. Each node created by a transform expression has a new <termref def="dt-node-identity">node identity</termref>. The result of a transform expression is an <termref def="dt-xdm-instance">XDM instance</termref> that may include both nodes that were created by the transform expression and other, previously existing nodes. A transform expression is a <termref def="dt-simple-expression">simple expression</termref> because it does not modify the value of any existing nodes.</p><p>Examples:</p><ulist><item><p>Return a sequence consisting of all <code>employee</code> elements that have Java as a skill, excluding their <code>salary</code> child-elements:</p><eg xml:space="preserve">for $e in //employee[skill = "Java"]
return 
   copy $je := $e
   modify delete node $je/salary
   return $je</eg></item><item><p>The following example copies a node, modifies the copy, and returns both the original node and the modified copy:</p><eg xml:space="preserve">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)
</eg><note><p>No persistent changes to the underlying data result from this example.</p></note></item></ulist><p>A transform expression consists of three clauses, denoted by the keywords <code>copy</code>, <code>modify</code>, and <code>return</code>. The semantics of a transform expression are as follows:</p><olist><item><p>The <code>copy</code> clause contains one or more variable bindings, each of which consists of a variable name and an expression called the <term>source expression</term>. Each variable binding is processed as follows:</p><olist><item><p>The source expression must be a <termref def="dt-simple-expression">simple expression</termref>; otherwise a static error is raised <errorref code="0001" class="ST"/>.</p></item><item><p>The result of evaluating the source expression must be a single node <errorref code="0013" class="TY"/>. Let <code>$node</code> be this single node.</p></item><item><p>A new copy is made of <code>$node</code> and all nodes that have <code>$node</code> as an ancestor,
collectively referred to as <term>copied nodes</term>. Each copied node receives a new node
identity. The <code>parent</code>, <code>children</code>, and <code>attributes</code> properties of the copied nodes
are set so as to preserve their inter-node relationships. Other properties of
the copied nodes are determined as follows:</p><olist><item><p>For a copied element node, the <code>type-name</code> property is set to <code>xs:untyped</code>,
and the <code>nilled</code>, <code>is-id</code>, and <code>is-idrefs</code> properties are set to <code>false</code>.</p></item><item><p>For a copied attribute node, the <code>type-name</code> property is set to
<code>xs:untypedAtomic</code> and the <code>is-idrefs</code> property is set to <code>false</code>. The <code>is-id</code> property
is set to <code>true</code> if the qualified name of the attribute node is <code>xml:id</code>; otherwise
it is set to <code>false</code>.</p></item><item><p>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 <code>xs:untypedAtomic</code>.</p><note><p>Implementations that store only the typed value of a
node are required at this point to convert the typed value to a string form.</p></note></item><item><p>If <code>copy-namespaces mode</code> in the static context specifies <code>preserve</code>, all in-scope-namespaces of the original element are
retained in the new copy. If <code>copy-namespaces</code> mode specifies <code>no-preserve</code>, the new copy retains only those in-scope namespaces of the original element that are used in the names of the element and its
     attributes.</p></item><item><p>All other properties of the copied nodes are preserved.</p></item></olist></item><item><p>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.</p></item></olist></item><item><p>The <code>modify</code> clause must contain either an <termref def="dt-updating-expression">updating expression</termref>, an empty expression <code>( )</code>, or a call to the <code>fn:error</code> function; otherwise a static error is raised <errorref code="0002" class="ST"/>. The  expression in the <code>modify</code> clause is evaluated, resulting in a <termref def="dt-pending-update-list">pending update list</termref>. If the <termref def="dt-target-node">target node</termref> of any <termref def="dt-update-primitive">update primitive</termref> on this pending update list is a node that was not newly created in Step 1, a dynamic error is raised <errorref code="0014" class="DY"/>. Let <code>$pul</code> be the pending update list generated by this step.</p></item><item><p>Let <code>$revalidation-mode</code> be the value of
the revalidation mode in the static context of the transform expression. The following <termref def="dt-update-operation">update operation</termref> is invoked: <code>upd:applyUpdates($pul, $revalidation-mode)</code>. The effect of this operation is to make the updates specified in the <code>modify</code> clause effective on the copied nodes.</p><note><p>In the event of incompatible updates, the <code>upd:applyUpdates</code> operation may raise an error, as described in <specref ref="id-upd-apply-updates"/>.</p></note></item><item><p>The <code>return</code> clause must contain a <termref def="dt-simple-expression">simple expression</termref>; otherwise a static error is raised <errorref code="0001" class="ST"/>. The <code>return</code> clause is evaluated, and its result is the result of the transform expression. During evaluation of the <code>return</code> clause, changes applied to copied nodes by the preceding step are visible.</p></item></olist></div3><div3 id="id-compatibility"><head>Compatibility of Updating Expressions</head><p>The rules defining compatibility of <termref def="dt-updating-expression">updating expressions</termref> within a <termref def="dt-snapshot">snapshot</termref> are defined in <specref ref="id-upd-apply-updates"/>.</p><note><p>The effect of these rules is as follows:</p><olist><item><p>If any node is affected by more than one <code>rename</code> expression within a  <termref def="dt-snapshot">snapshot</termref>, a dynamic error is raised <errorref code="0015" class="DY"/>.</p></item><item><p>If any node is affected by more than one <code>replace</code> expression (without <code>value of</code> being specified) within a  <termref def="dt-snapshot">snapshot</termref>, a dynamic error is raised <errorref code="0016" class="DY"/>.</p></item><item><p>If any node is affected by more than one <code>replace value of</code> expression within a  <termref def="dt-snapshot">snapshot</termref>, a dynamic error is raised <errorref code="0017" class="DY"/>.</p></item><item><p>If multiple calls to <code>fn:put</code> operate on the same URI in the same <termref def="dt-snapshot">snapshot</termref>, a dynamic error is raised <errorref code="0031" class="DY"/>.</p></item><item><p>Within a given <termref def="dt-snapshot">snapshot</termref>, if an element node <code>E</code> is the target of a <code>replace value of</code> expression, and the children of <code>E</code> are also modified by other expressions, the final children of <code>E</code> are determined by the <code>replace value of</code> expression. For example:</p><ulist><item><p>Suppose that <code>$A</code> is bound to an element node that has a child element named <code>B</code>. Suppose that the following expressions are evaluated in the same <termref def="dt-snapshot">snapshot</termref>:</p><eg xml:space="preserve">replace node $A/B with &lt;C&gt;Hello&lt;/C&gt;,
replace value of node $A with &lt;D&gt;Goodbye&lt;/D&gt;</eg> <p>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 <termref def="dt-snapshot">snapshot</termref>, the children of <code>$A</code> will consist of a single text node with the content <code>"Goodbye"</code>.</p></item></ulist></item></olist></note></div3></div2>
<div2 id="id-extensions-to-existing"><head>Extensions to Existing Expressions</head><p>XQuery Update Facility 1.0 provides extensions to the semantics of several existing kinds of XQuery expressions, as specified in this section.</p><div3 id="id-flwor-expr"><head>FLWOR Expression</head>

<p>The syntax of the FLWOR expression is not changed. Its semantics are extended as follows:</p>

<olist>

<item><p>If a <code>for</code>,
<code>let</code>, <code>where</code>, or <code>order by</code>
clause contains an <termref def="dt-updating-expression">updating expression</termref>, a static error is raised <errorref code="0001" class="ST"/>.</p></item><item><p>The <code>return</code> clause may contain any category of expression. The category of the FLWOR expression is the same as the category of the expression in its <code>return</code> clause (simple, vacuous, or updating.)</p></item><item><p>If the <code>return</code> clause contains a <termref def="dt-simple-expression">simple expression</termref>, the semantics of the FLWOR expression  are as specified in <xspecref spec="XQ" ref="id-flwor-expressions"/>.</p></item><item><p>If the <code>return</code> clause contains an <termref def="dt-updating-expression">updating expression</termref>, the semantics of the FLWOR expression are as follows:</p><olist>

<item><p>The semantics of the <code>for</code>,
<code>let</code>, <code>where</code>, and <code>order by</code>
clauses are as specified in <xspecref spec="XQ" ref="id-flwor-expressions"/>. These clauses generate a stream of tuples of bound
variables.</p></item>

<item><p>For each tuple
generated by the previous step, the updating expression in the
<code>return</code> clause is evaluated, resulting in a <termref def="dt-pending-update-list">pending update list</termref>.</p></item>

<item><p>All the <termref def="dt-pending-update-list">pending update lists</termref> generated by the
previous step are merged by successive invocations of the <code>upd:mergeUpdates</code>
operation. The resulting merged pending update list is the
result of the FLWOR expression.</p><note><p>In the event of incompatible updates, the <code>upd:mergeUpdates</code> operation may raise an error, as described in <specref ref="id-upd-merge-updates"/>.</p></note></item>
</olist></item>

</olist><p>The following example illustrates the use of an updating expression in a FLWOR expression:</p><ulist><item><p>Update an inventory of parts according to a set of changes provided in the bound variable <code>$changes</code>. Both <code>/inventory</code> and <code>$changes</code> contain a set of <code>part</code> elements, each with a <code>partno</code> and a <code>quantity</code>.</p><eg xml:space="preserve">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</eg></item></ulist></div3><div3 id="id-typeswitch-expr"><head>Typeswitch Expression</head>

<p>The syntax of the typeswitch expression is not changed. Its semantics are extended as
follows. Let the expressions in the  <code>case</code>  and <code>default</code> clauses be called <term>branches</term>. Then:
</p>

<olist>

<item><p>If the operand expression of a typeswitch is an <termref def="dt-updating-expression">updating expression</termref>, a static error is raised <errorref code="0001" class="ST"/>.</p></item><item><p>If any branch is an <termref def="dt-updating-expression">updating expression</termref>, then all branches must be <termref def="dt-updating-expression">updating</termref> or <termref def="dt-vacuous-expression">vacuous expressions</termref> <errorref code="0001" class="ST"/>.  In this case, the typeswitch expression is an <termref def="dt-updating-expression">updating expression</termref>.</p></item><item><p>If all branches are <termref def="dt-vacuous-expression">vacuous expressions</termref>, the typeswitch expression is a <termref def="dt-vacuous-expression">vacuous expression</termref>.</p></item><item><p>Otherwise, the typeswitch expression is a <termref def="dt-simple-expression">simple expression</termref>.</p></item><item><p>If the typeswitch expression is a <termref def="dt-simple-expression">simple</termref> (including <termref def="dt-vacuous-expression">vacuous</termref>) expression, its semantics are as specified in <xspecref spec="XQ" ref="id-typeswitch"/>.</p></item><item><p>If the typeswitch expression is an <termref def="dt-updating-expression">updating expression</termref>, then  selection of the effective case and
binding of variables are performed as specified in <xspecref spec="XQ" ref="id-typeswitch"/>. The  expression in the <code>return</code>
clause of the effective case (or default) is then evaluated, resulting
in a <termref def="dt-pending-update-list">pending update list</termref>, which serves as the result of
the typeswitch expression.</p></item>



</olist></div3><div3 id="id-conditional-expr"><head>Conditional Expression</head><p>The semantics of
conditional expressions are extended as follows.
Let the expressions in the  <code>then</code>  and <code>else</code> clauses be called <term>branches</term>. Then:
</p><olist>

<item><p>If the if-clause contains an <termref def="dt-updating-expression">updating expression</termref>, a static error is raised <errorref code="0001" class="ST"/>.</p></item><item><p>If either branch is an <termref def="dt-updating-expression">updating expression</termref>, then both branches must be <termref def="dt-updating-expression">updating</termref> or <termref def="dt-vacuous-expression">vacuous expressions</termref> <errorref code="0001" class="ST"/>.  In this case, the conditional expression is an <termref def="dt-updating-expression">updating expression</termref>.</p></item><item><p>If both branches are <termref def="dt-vacuous-expression">vacuous expressions</termref>, the conditional expression is a <termref def="dt-vacuous-expression">vacuous expression</termref>.</p></item><item><p>Otherwise, the conditional expression is a <termref def="dt-simple-expression">simple expression</termref>.</p></item><item><p>If the conditional expression is a <termref def="dt-simple-expression">simple</termref> (including <termref def="dt-vacuous-expression">vacuous</termref>) expression, its semantics are as specified in <xspecref spec="XQ" ref="id-conditionals"/>.</p></item><item><p>If the conditional expression is an <termref def="dt-updating-expression">updating expression</termref>, then  selection of the effective branch performed as specified in <xspecref spec="XQ" ref="id-conditionals"/>. The result of the conditional expression is
the <termref def="dt-pending-update-list">pending update list</termref> returned by the
selected branch.</p></item>



</olist>

<p>The following example illustrates the use of updating expressions in a conditional expression:</p><ulist><item><p>If the element bound to variable <code>$e</code> has a <code>last-updated</code> attribute, update its value to the current date; otherwise insert such an attribute.</p><eg xml:space="preserve">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</eg></item></ulist></div3><div3 id="id-comma-expr"><head>Comma Expression</head><p>The semantics of
comma expressions (composed of one or more expressions concatenated by the comma operator, as described in <xspecref spec="XQ" ref="construct_seq"/>) are extended as follows:
</p><olist>

<item><p>If any operand is an <termref def="dt-updating-expression">updating expression</termref>, then all operands must be <termref def="dt-updating-expression">updating</termref> or <termref def="dt-vacuous-expression">vacuous expressions</termref> <errorref code="0001" class="ST"/>.  In this case, the comma expression is an <termref def="dt-updating-expression">updating expression</termref>.</p></item><item><p>If all operands are <termref def="dt-vacuous-expression">vacuous expressions</termref>, the comma expression is a <termref def="dt-vacuous-expression">vacuous expression</termref>.</p></item><item><p>Otherwise, the comma expression is a <termref def="dt-simple-expression">simple expression</termref>.</p></item><item><p>If the comma expression is a <termref def="dt-simple-expression">simple</termref> (including <termref def="dt-vacuous-expression">vacuous</termref>) expression, its semantics are as specified in <xspecref spec="XQ" ref="construct_seq"/>.</p></item><item><p>If the comma expression is an <termref def="dt-updating-expression">updating expression</termref>, its operand expressions are evaluated (in any order), and the <termref def="dt-pending-update-list">pending update lists</termref>
returned by the operand expressions are merged by the <code>upd:mergeUpdates</code>
operation. The resulting merged <termref def="dt-pending-update-list">pending update list</termref> is the result of the comma expression.</p></item>



</olist>

<p>The following example illustrates the use of an updating comma expression:</p><ulist><item><p>This example makes the value of an element empty and gives the element an <code>xsi:nil="true"</code> attribute. Both of these operations may be necessary in order to preserve the validity of the element.</p><eg xml:space="preserve">let $q := /inventory/item[serialno = "123456"]/quantity
return
   ( replace value of node $q with ( ),
     insert node attribute xsi:nil {"true"} into $q )</eg></item></ulist></div3><div3 id="id-parenthesized-expr"><head>Parenthesized Expression</head><p>The semantics of a parenthesized expression (any XQuery expression enclosed in parentheses) are extended as follows:</p><p>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. </p><p>An empty parenthesized expression <code>( )</code> is a <termref def="dt-vacuous-expression">vacuous expression</termref>. Its result is an empty sequence and an empty <termref def="dt-pending-update-list">pending update list</termref>.</p></div3><div3 id="id-function-call"><head>Function Call</head><p>The semantics of a function call are extended as follows:</p><p>The function call is evaluated as specified in Section 3.1.5 of <bibref ref="xquery"/>. If any input parameter of the function  call is an <termref def="dt-updating-expression">updating expression</termref>, a static error is raised <errorref code="0001" class="ST"/>.</p><p>The expression category of a function call is as follows:</p><ulist><item><p>A call to the built-in function <code>fn:error</code> is a <termref def="dt-vacuous-expression">vacuous expression</termref>.</p></item><item><p>A call to an <termref def="dt-updating-function">updating function</termref> is an <termref def="dt-updating-expression">updating expression</termref>.</p></item><item><p>A call to any other function is a <termref def="dt-simple-expression">simple expression</termref>.</p><note><p>This includes calls to built-in functions other than <code>fn:error</code> and calls to user-defined functions that were not declared to be <code>updating</code>.</p></note></item></ulist></div3><div3 id="id-other-expr"><head>Other Expressions</head><p>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:</p><p>If any operand of this expression is an <termref def="dt-updating-expression">updating expression</termref>, a static error is raised <errorref code="0001" class="ST"/>.</p><p>In addition, the initializing expression of a variable declaration in a Prolog may not be an <termref def="dt-updating-expression">updating expression</termref> <errorref code="0001" class="ST"/>.</p></div3></div2>

<div2 id="id-new-functions">
  <head>Extensions to Built-in Function Library</head>
  
  <p>XQuery Update Facility 1.0 provides extensions to XQuery built-in function library, as specified in this
  section.</p> 

  <div3 id="id-func-put">
    <head>fn:put</head>
      



<proto name="put" isSchema="no" isDatatype="no" isSpecial="no" isOp="no" return-type="empty-sequence()" isStd="yes" returnEmptyOk="no" returnSeq="no" returnVaries="no">
<arg name="node" type="node()" emptyOk="no"/>
<arg name="uri" type="xs:string" emptyOk="no"/>
</proto>

<p><term>Summary:</term> Stores  a document or element to the location specified by <code>$uri</code>.
This function is normally invoked to create
a resource on an external storage system such as a file system or a
database.</p>



<p>The external effects of <code>fn:put</code> are implementation-defined,
since they occur outside the domain of XQuery. The intent is that, if <code>fn:put</code> is invoked on a document node and no error is raised, a
subsequent query can access the stored document by invoking
<code>fn:doc</code> with the same URI.</p><p><term>Semantics:</term></p><olist><item><p><code>fn:put</code> is an updating function.</p></item><item><p>If <code>$node</code> is not a document node or an element node, and the implementation does not support <code>fn:put</code> on the given node kind, a dynamic error is
raised <errorref code="0001" class="UP"/>.</p></item><item><p>If
<code>$uri</code> is not a valid lexical representation of the <code>xs:anyURI</code> type, a dynamic error is
raised <errorref code="0002" class="UP"/>. If <code>$uri</code> is a relative URI reference, it is resolved
relative to the value of the base URI property in the static
context.</p></item><item><p>The result of a call to <code>fn:put</code> is an empty <termref def="dt-xdm-instance">XDM instance</termref> and a <termref def="dt-pending-update-list">pending update list</termref> 
containing the following <termref def="dt-update-primitive">update primitive</termref>: 
<code>upd:put($node, $uri)</code>.</p></item></olist>

<notes><ulist><item><p>The results of <code>fn:put</code> do not become effective until after completion of the current <termref def="dt-snapshot">snapshot</termref>. The <code>fn:put</code> function has no effect on the set of available documents or collections seen by the current <termref def="dt-snapshot">snapshot</termref>.</p></item><item><p>If a node that is an operand of <code>fn:put</code> is affected by updating expressions in the current <termref def="dt-snapshot">snapshot</termref>, the <code>fn:put</code> function operates on the node after these updating expressions are made effective. As a result, after completion of the current <termref def="dt-snapshot">snapshot</termref>, the effects of updates to <code>$node</code> can be seen via <code>$uri</code>. (For details on application of updates, see <specref ref="id-upd-apply-updates"/>.)</p></item><item><p>If multiple calls to <code>fn:put</code> in the same <termref def="dt-snapshot">snapshot</termref> operate on the same URI (after any necessary resolution of relative URIs), a dynamic error <errorref code="0031" class="DY"/> is raised. The dynamic error is raised by an expression at some level of the query that contains more than one call to <code>fn:put</code>. For a normative description of this error, see <specref ref="id-upd-merge-updates"/> and <specref ref="id-upd-apply-updates"/>.</p></item></ulist></notes>










  </div3>

</div2>



</div1>


<div1 id="id-update-operations">
<head>Update Operations</head>
<p>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.</p><p>Update operations consist of <termref def="dt-update-primitive">update primitives</termref>, which are the components of <termref def="dt-pending-update-list">pending update lists</termref>, and <termref def="dt-update-routine">update routines</termref>, which are used in defining XQuery semantics but do not appear on <termref def="dt-pending-update-list">pending update lists</termref>.</p>
<div2 id="id-update-primitives"><head>Update Primitives</head><p>The update primitives described in this section may be held on <termref def="dt-pending-update-list">pending update lists</termref>. When an update primitive is held on a pending update list, its node operands are represented by their <termref def="dt-node-identity">node identities</termref>. The semantics of an update primitive do not become effective until their pending update list is processed by the  <code>upd:applyUpdates</code> routine.</p><div3 id="id-upd-insert-before"><head>upd:insertBefore</head>
					<glist>
						<gitem><label>Parameters</label><def><eg xml:space="preserve">upd:insertBefore(
   $target as node(),
   $content as node()+)</eg></def></gitem><gitem>
							<label>Summary</label>
							<def>
								<p>Inserts <code>$content</code> immediately before <code>$target</code>.</p>
							</def>
						</gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p><code>$target</code> must be an element, text, processing
									instruction, or comment node with a non-empty <code>parent</code> property. <code>$content</code> must be a sequence containing only element, text, processing instruction,
									and comment nodes.</p>
							</def>
						</gitem><gitem><label>Semantics</label><def><olist><item><p>Effects on nodes in <code>$content</code>:</p><olist><item><p>For each node in <code>$content</code>, the <code>parent</code> property is set to <code>parent($target)</code>.</p></item><item><p>If the <code>type-name</code> property of <code>parent($target)</code> is <code>xs:untyped</code>, then <code>upd:setToUntyped()</code> is invoked on each element or attribute node in <code>$content</code>.</p></item></olist></item><item><p>Effects on <code>parent($target)</code>:</p><olist><item><p>The <code>children</code> property of <code>parent($target)</code> is modified to add the nodes in <code>$content</code> just before <code>$target</code>, preserving their order.</p></item><item><p>If at least one of the nodes in <code>$content</code> is an element or text node, <code>upd:removeType(parent($target))</code> is invoked.</p></item></olist></item></olist></def></gitem>
						
						
					</glist></div3><div3 id="id-upd-insert-after"><head>upd:insertAfter</head><glist>
						<gitem><label>Parameters</label><def><eg xml:space="preserve">upd:insertAfter(
   $target as node(),
   $content as node()+)</eg></def></gitem><gitem>
							<label>Summary</label>
							<def>
								<p>Inserts <code>$content</code> immediately after <code>$target</code>.</p>
							</def>
						</gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p><code>$target</code> must be an element, text, processing
									instruction, or comment node with a non-empty <code>parent</code> property. <code>$content</code> must be a sequence containing only element, text, processing instruction,
									and comment nodes.</p>
							</def>
						</gitem><gitem><label>Semantics</label><def><p>The semantics of <code>upd:insertAfter</code> are identical to the semantics of <code>upd:insertBefore</code>, except that Rule 2a is changed as follows:</p><ulist><item><p>The <code>children</code> property of <code>parent($target)</code> is modified to add the nodes in <code>$content</code> just after <code>$target</code>, preserving their order.</p></item></ulist></def></gitem>
						
						
					</glist></div3><div3 id="id-upd-insert-into"><head>upd:insertInto</head><glist>
						<gitem><label>Parameters</label><def><eg xml:space="preserve">upd:insertInto(
   $target as node(),
   $content as node()+)</eg></def></gitem><gitem>
							<label>Summary</label>
							<def>
								<p>Inserts <code>$content</code> as the children of <code>$target</code>, in an implementation-dependent position.</p>
							</def>
						</gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p><code>$target</code> must be an element or document node. <code>$content</code> must be a sequence containing only element, text, processing instruction,
									and comment nodes.</p>
							</def>
						</gitem><gitem><label>Semantics</label><def><p>The semantics of <code>upd:insertInto</code> are identical to the semantics of <code>upd:insertBefore</code>, except that <code>$target</code> is substituted everywhere for <code>parent($target)</code>, and Rule 2a is changed as follows:</p><ulist><item><p>The <code>children</code> property of <code>$target</code> is changed to include the nodes in <code>$content</code> in implementation-dependent positions, preserving their relative order.</p></item></ulist></def></gitem>
						
						
					</glist></div3><div3 id="id-upd-insert-into-as-first"><head>upd:insertIntoAsFirst</head><glist>
						<gitem><label>Parameters</label><def><eg xml:space="preserve">upd:insertIntoAsFirst(
   $target as node(),
   $content as node()+)</eg></def></gitem><gitem>
							<label>Summary</label>
							<def>
								<p>Inserts <code>$content</code> as the first children of <code>$target</code>.</p>
							</def>
						</gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p><code>$target</code> must be an element or document node. <code>$content</code> must be a sequence containing only element, text, processing instruction,
									and comment nodes.</p>
							</def>
						</gitem><gitem><label>Semantics</label><def><p>The semantics of <code>upd:insertIntoAsFirst</code> are identical to the semantics of <code>upd:insertBefore</code>, except that <code>$target</code> is substituted everywhere for <code>parent($target)</code>, and Rule 2a is changed as follows:</p><ulist><item><p>The <code>children</code> property of <code>$target</code> is changed to include the nodes in <code>$content</code> as the first children, preserving their order.</p></item></ulist></def></gitem>
						
						
					</glist></div3><div3 id="id-upd-insert-into-as-last"><head>upd:insertIntoAsLast</head><glist>
						<gitem><label>Parameters</label><def><eg xml:space="preserve">upd:insertIntoAsLast(
   $target as node(),
   $content as node()+)</eg></def></gitem><gitem>
							<label>Summary</label>
							<def>
								<p>Inserts <code>$content</code> as the last children of <code>$target</code>.</p>
							</def>
						</gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p><code>$target</code> must be an element or document node. <code>$content</code> must be a sequence containing only element, text, processing instruction,
									and comment nodes.</p>
							</def>
						</gitem><gitem><label>Semantics</label><def><p>The semantics of <code>upd:insertIntoAsLast</code> are identical to the semantics of <code>upd:insertBefore</code>, except that <code>$target</code> is substituted everywhere for <code>parent($target)</code>, and Rule 2a is changed as follows:</p><ulist><item><p>The <code>children</code> property of <code>$target</code> is changed to include the nodes in <code>$content</code> as the last children, preserving their order.</p></item></ulist></def></gitem>
						
						
					</glist></div3><div3 id="id-upd-insert-attributes"><head>upd:insertAttributes</head><glist>
						<gitem><label>Parameters</label><def><eg xml:space="preserve">upd:insertAttributes(
   $target as element(),
   $content as attribute()+)</eg></def></gitem><gitem>
							<label>Summary</label>
							<def>
								<p>Inserts <code>$content</code> as attributes of <code>$target</code>.</p>
							</def>
						</gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p>None</p>
							</def>
						</gitem><gitem><label>Semantics</label><def><olist><item><p>For each node <code>$A</code> in <code>$content</code>:</p><olist><item><p>The <code>parent</code> property of <code>$A</code> is set to <code>$target</code>.</p></item><item><p>If the <code>type-name</code> property of <code>$target</code> is <code>xs:untyped</code>, then <code>upd:setToUntyped($A)</code> is invoked.</p></item></olist></item><item><p>The following properties of <code>$target</code> are changed:</p><olist><item><p><code>attributes</code>: Modified to include the nodes in <code>$content</code>.</p></item><item><p><code>namespaces:</code> Modified to include namespace bindings for any attribute namespace prefixes in <code>$content</code> that did not already have bindings.</p></item><item><p><code>upd:removeType($target)</code> is invoked.</p></item></olist></item></olist></def></gitem>
						
						
					</glist></div3><div3 id="id-upd-delete"><head id="id-dm-delete">upd:delete</head><glist>
						<gitem><label>Parameters</label><def><eg xml:space="preserve">upd:delete(
   $target as node())</eg></def></gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p>None</p>
							</def>
						</gitem><gitem><label>Semantics</label><def><olist><item><p>If <code>$target</code> has a parent node <code>$P</code>, then:</p><olist><item><p>The <code>parent</code> property of <code>$target</code> is set to empty.</p></item><item><p>If <code>$target</code> is an attribute node, the <code>attributes</code> property of <code>$P</code> is modified to remove <code>$target</code>.</p></item><item><p>If <code>$target</code> is a non-attribute node, the <code>children</code> property of <code>$P</code> is modified to remove <code>$target</code>.</p></item><item><p>If <code>$target</code> is an element, attribute, or text node, and <code>$P</code> is an element node, then <code>upd:removeType($P)</code>  is invoked.</p></item></olist></item><item><p>If <code>$target</code> has no parent, the <termref def="dt-xdm-instance">XDM instance</termref> is unchanged.</p></item></olist><note><p>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.</p></note><note><p>Multiple <code>upd:delete</code> operations may be applied to the same node during execution of a query; this is not an error.</p></note></def></gitem>
						
						
					</glist></div3><div3 id="id-upd-replacenode"><head>upd:replaceNode</head><glist>
						<gitem><label>Parameters</label><def><eg xml:space="preserve">upd:replaceNode(
   $target as node(),
   $replacement as node()*)</eg></def></gitem><gitem>
							<label>Summary</label>
							<def>
								<p>Replaces <code>$target</code> with <code>$replacement</code>.</p>
							</def>
						</gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p><code>$target</code> must be a node that has a parent. If <code>$target</code> is an attribute node, <code>$replacement</code> must consist of zero or more attribute nodes. If <code>$target</code> is an element, text, comment, or processing instruction node, <code>$replacement</code> must be consist of zero or more element, text, comment, or processing instruction nodes.</p>
							</def>
						</gitem><gitem><label>Semantics</label><def><olist><item><p>Effects on nodes in <code>$replacement</code>:</p><olist><item><p>For each node in <code>$replacement</code>, the <code>parent</code> property is set to <code>parent($target)</code>.</p></item><item><p>If the <code>type-name</code> property of <code>parent($target)</code> is <code>xs:untyped</code>, then <code>upd:setToUntyped()</code> is invoked on each element node in <code>$replacement</code>.</p></item></olist></item><item><p>Effect on <code>$target</code>:</p><olist><item><p>The <code>parent</code> property of <code>$target</code> is set to empty.</p></item></olist></item><item><p>Effects on <code>parent($target)</code>:</p><olist><item><p>If <code>$target</code> is an attribute node, the <code>attributes</code> property of <code>parent($target)</code> is modified by removing <code>$target</code> and adding the nodes in <code>$replacement</code> (if any).</p></item><item><p>If <code>$target</code> is an attribute node, the <code>namespaces</code> property of <code>parent($target)</code> is modified to include namespace bindings for any attribute namespace prefixes in <code>$replacement</code> that did not already have bindings.</p></item><item><p>If <code>$target</code> is an element, text, comment, or processing instruction node, the <code>children</code> property of <code>parent($target)</code> is modified by removing <code>$target</code> and adding the nodes in <code>$replacement</code> (if any) in the former position of <code>$target</code>, preserving their order.</p></item><item><p>If <code>$target</code> or any node in <code>$replacement</code> is an element, attribute, or text
node,  <code>upd:removeType(parent($target))</code> is invoked.</p></item></olist></item></olist></def></gitem>
						
						
					</glist></div3><div3 id="id-upd-replace-value"><head>upd:replaceValue</head><glist>
						<gitem><label>Parameters</label><def><eg xml:space="preserve">upd:replaceValue(
   $target as node(),
   $string-value as xs:string)</eg></def></gitem><gitem>
							<label>Summary</label>
							<def>
								<p>Replaces the string value of <code>$target</code> with <code>$string-value</code>.</p>
							</def>
						</gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p><code>$target</code> must be an attribute, text, comment, or processing instruction node.</p>
							</def>
						</gitem><gitem><label>Semantics</label><def><olist><item><p>If <code>$target</code> is an attribute node:</p><olist><item><p><code>string-value</code> of <code>$target</code> is set to <code>$string-value</code>.</p></item><item><p><code>upd:removeType($target)</code> is invoked.</p></item></olist></item><item><p>If <code>$target</code> is a text, comment, or processing instruction node: <code>content</code> of <code>$target</code> is set to <code>$string-value</code>.</p></item><item><p>If  <code>$target</code> is a text node that has a parent, <code>upd:removeType(parent($target))</code> is invoked.</p></item></olist></def></gitem>
						
						
					</glist></div3><div3 id="id-upd-replace-element-content"><head>upd:replaceElementContent</head><glist>
						<gitem><label>Parameters</label><def><eg xml:space="preserve">upd:replaceElementContent(
   $target as element(),
   $text as text()?)</eg></def></gitem><gitem>
							<label>Summary</label>
							<def>
								<p>Replaces the existing children of the element node <code>$target</code> by the optional text node <code>$text</code>. The attributes of <code>$target</code> are not affected.</p>
							</def>
						</gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p>None.</p>
							</def>
						</gitem><gitem><label>Semantics</label><def><olist><item><p>For each node <code>$C</code> that is a child of <code>$target</code>, the <code>parent</code> property of <code>$C</code> is set to empty.</p></item><item><p>The <code>parent</code> property of <code>$text</code> is set to <code>$target</code>.</p></item><item><p>Effects on <code>$target</code>:</p><olist><item><p><code>children</code> is set to consist exclusively of <code>$text</code>. If <code>$text</code> is an empty sequence, then <code>$target</code> has no children.</p></item><item><p><code>typed-value</code> and <code>string-value</code> are set to the <code>content</code> property of <code>$text</code>. If <code>$text</code> is an empty sequence, then <code>typed-value</code> is an empty sequence and <code>string-value</code> is an empty string.</p></item><item><p><code>upd:removeType($target)</code> is invoked.</p></item></olist></item></olist></def></gitem>
						
						
					</glist></div3><div3 id="id-upd-rename"><head>upd:rename</head><glist>
						<gitem><label>Parameters</label><def><eg xml:space="preserve">upd:rename(
   $target as node(),
   $newName as xs:QName)</eg></def></gitem><gitem>
							<label>Summary</label>
							<def>
								<p>Changes the node-name of <code>$target</code> to <code>$newName</code>.</p>
							</def>
						</gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p><code>$target</code> must be an element, attribute, or processing instruction node.</p>
							</def>
						</gitem><gitem><label>Semantics</label><def><olist><item><p>If <code>$target</code> is an element node:</p><olist><item><p><code>node-name</code> of <code>$target</code> is set to <code>$newName</code>.</p></item><item><p><code>upd:removeType($target)</code> is invoked.</p> </item><item><p>If <code>$newname</code> has no prefix and no namespace URI, 
the <code>namespaces</code> property of <code>$target</code> is modified by removing the binding (if any) 
for the empty prefix.</p></item><item><p>The <code>namespaces</code> property of <code>$target</code> is modified to include a namespace binding derived from <code>$newName</code>, if this binding did not already exist.</p></item></olist></item><item><p>If <code>$target</code> is an attribute node:</p><olist><item><p><code>node-name</code> of <code>$target</code> is set to <code>$newName</code>.</p></item><item><p><code>upd:removeType($target)</code> is invoked.</p> </item><item><p>If <code>$newName</code> is <code>xml:id</code>, the <code>is-id</code> property of <code>$target</code> is set to <code>true</code>.</p></item><item><p>If <code>$target</code> has a parent, the <code>namespaces</code> property of <code>parent($target)</code> is modified to include a namespace binding derived from <code>$newName</code>, if this binding did not already exist.</p></item></olist></item><item><p>If <code>$target</code> is a processing instruction node, its <code>target</code> property is set to the local part of  <code>$newName</code>.</p></item></olist><note><p>At the end of a <termref def="dt-snapshot">snapshot</termref>, if multiple attribute nodes with the same parent have the same qualified name, an error will be raised by <code>upd:applyUpdates</code>.</p></note></def></gitem>
						
						
					</glist></div3><div3 id="id-upd-put"><head>upd:put</head><glist>
						<gitem><label>Parameters</label><def><eg xml:space="preserve">upd:put(
   $node as node(),
   $uri as xs:string)</eg></def></gitem><gitem>
							<label>Summary</label>
							<def>
								
							<p> The XDM node tree rooted at <code>$node</code> is stored to the location specified by <code>$uri</code>.</p>



</def>
						</gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p><code>$uri</code> must be a valid absolute URI.</p>
							</def>
						</gitem><gitem><label>Semantics</label><def><p>The external effects of <code>upd:put</code> are implementation-defined,
since they occur outside the domain of XQuery. The intent is that, if <code>upd:put</code> is invoked on a document node and no error is raised, a
subsequent query can access the stored document by invoking
<code>fn:doc</code> with the same URI.</p></def></gitem>
						
						
					</glist></div3></div2><div2 id="id-update-routines"><head>Update Routines</head><div3 id="id-upd-merge-updates"><head>upd:mergeUpdates</head><glist><gitem><label>Parameters</label>
<def><eg xml:space="preserve">upd:mergeUpdates(
   $pul1 as pending-update-list,
   $pul2 as pending-update-list)</eg>  
</def>
						</gitem>
						<gitem>
							<label>Summary</label>
							<def>
								<p>Merges two <termref def="dt-pending-update-list">pending update lists</termref>.</p>
							</def>
						</gitem><gitem>
							<label>Constraints</label>
							<def>
								<p>None.</p>
							</def>
						</gitem><gitem>
							<label>Semantics</label>
							<def>
								<olist><item><p>The two <termref def="dt-pending-update-list">pending update lists</termref> are merged and a single pending update list containing all the update primitives from both lists is returned.</p></item><item><p>Optionally, <code>upd:mergeUpdates</code> may raise a dynamic error if any of the following conditions are detected:</p><olist><item><p>Two or more <code>upd:rename</code> primitives on the merged list have the same target node <errorref code="0015" class="DY"/>.</p></item><item><p>Two or more <code>upd:replaceNode</code> primitives on the merged list have the same target node <errorref code="0016" class="DY"/>.</p></item><item><p>Two or more <code>upd:replaceValue</code> primitives on the merged list have the same target node <errorref code="0017" class="DY"/>.</p></item><item><p>Two or more <code>upd:replaceElementContent</code> primitives on the merged list have the same target node <errorref code="0017" class="DY"/>.</p></item><item><p>Two or more <code>upd:put</code> primitives on the merged list have the same <code>$uri</code> operand <errorref code="0031" class="DY"/>.</p></item><item><p>Two or more primitives on the merged list create  <termref def="dt-conflict">conflicting</termref> namespace bindings for the same element node <errorref code="0024" class="DY"/>. The following kinds of primitives create namespace bindings:</p><olist><item><p><code>upd:insertAttributes</code> creates one namespace binding on the <code>$target</code> element
corresponding to the <termref def="dt-implied-namespace-binding">implied namespace binding</termref> of the name of each attribute node in
<code>$content</code>.</p></item><item><p><code>upd:replaceNode</code> creates one namespace binding on the <code>$target</code> element
corresponding to the <termref def="dt-implied-namespace-binding">implied namespace binding</termref> of the name of each attribute node in
<code>$replacement</code>.</p></item><item><p><code>upd:rename</code> creates a namespace binding on <code>$target</code>, or on the parent (if any) of
<code>$target</code> if <code>$target</code> is an attribute node, corresponding to the <termref def="dt-implied-namespace-binding">implied namespace binding</termref> of <code>$newName</code>.</p></item></olist></item></olist></item></olist>



	



							</def>
						</gitem></glist></div3><div3 id="id-upd-apply-updates"><head>upd:applyUpdates</head><glist><gitem><label>Parameters</label><def><eg xml:space="preserve">upd:applyUpdates(
   $pul as pending-update-list,
   $revalidation-mode as xs:string)</eg></def></gitem>
						<gitem>
							<label>Summary</label>
							<def>
								<p>This routine ends a <termref def="dt-snapshot">snapshot</termref> by making effective  the semantics of all the update primitives on a <termref def="dt-pending-update-list">pending update list</termref> and by revalidating the resulting <termref def="dt-xdm-instance">XDM instance</termref>.</p>
							</def>
						</gitem><gitem>
							<label>Constraints</label>
							<def>
								<p><code>$revalidation-mode</code> must be <code>"strict"</code>, <code>"lax"</code>, or <code>"skip"</code></p>
							</def>
						</gitem><gitem>
							<label>Semantics</label>
							<def>
								
							<olist><item><p>Checks the update primitives on <code>$pul</code> for compatibility. Raises a dynamic error if any of the following conditions are detected:</p><olist><item><p>Two or more <code>upd:rename</code> primitives on <code>$pul</code> have the same target node <errorref code="0015" class="DY"/>.</p></item><item><p>Two or more <code>upd:replaceNode</code> primitives on <code>$pul</code> have the same target node <errorref code="0016" class="DY"/>.</p></item><item><p>Two or more <code>upd:replaceValue</code> primitives on <code>$pul</code> have the same target node <errorref code="0017" class="DY"/>.</p></item><item><p>Two or more <code>upd:replaceElementContent</code> primitives on <code>$pul</code> have the same target node <errorref code="0017" class="DY"/>.</p></item><item><p>Two or more <code>upd:put</code> primitives on the merged list have the same <code>$uri</code> operand <errorref code="0031" class="DY"/>.</p></item><item><p>Two or more primitives on <code>$pul</code> create  <termref def="dt-conflict">conflicting</termref> namespace bindings for the same element node <errorref code="0024" class="DY"/>. The following kinds of primitives create namespace bindings:</p><olist><item><p><code>upd:insertAttributes</code> creates one namespace binding on the <code>$target</code> element
corresponding to the <termref def="dt-implied-namespace-binding">implied namespace binding</termref> of the name of each attribute node in
<code>$content</code>.</p></item><item><p><code>upd:replaceNode</code> creates one namespace binding on the <code>$target</code> element
corresponding to the <termref def="dt-implied-namespace-binding">implied namespace binding</termref> of the name of each attribute node in
<code>$replacement</code>.</p></item><item><p><code>upd:rename</code> creates a namespace binding on <code>$target</code>, or on the parent (if any) of
<code>$target</code> if <code>$target</code> is an attribute node, corresponding to the <termref def="dt-implied-namespace-binding">implied namespace binding</termref> of <code>$newName</code>.</p></item></olist></item></olist></item><item><p>The semantics of all  <termref def="dt-update-primitive">update primitives</termref> on <code>$pul</code>, other than <code>upd:put</code> primitives, are made effective in the following order:</p><olist><item><p>First, all <code>upd:insertInto</code>, <code>upd:insertAttributes</code>, <code>upd:replaceValue</code>, and <code>upd:rename</code>  primitives are applied.</p></item><item><p>Next, all <code>upd:insertBefore</code>, <code>upd:insertAfter</code>, <code>upd:insertIntoAsFirst</code>, and <code>upd:insertIntoAsLast</code> primitives are applied.</p></item><item><p>Next, all <code>upd:replaceNode</code> primitives are applied.</p></item><item><p>Next, all <code>upd:replaceElementContent</code> primitives are applied.</p></item><item><p>Next, all <code>upd:delete</code> primitives are applied.</p></item></olist></item><item><p>If, as a net result of the above steps, the <code>children</code> 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 <termref def="dt-node-identity">node identity</termref> of the resulting text node is implementation-dependent.</p></item><item><p>If, as a net result of the above steps, the <code>children</code> property of some node contains an empty text node, that empty text node is deleted from the <code>children</code> property.</p></item><item><p>If the resulting <termref def="dt-xdm-instance">XDM instance</termref> violates any constraint specified in <bibref ref="datamodel"/>, a dynamic error is raised <errorref code="0021" class="DY"/>.</p><note><p>For example, a data model constraint violation might occur if multiple attributes with the same parent have the same qualified name (see <xspecref spec="DM" ref="ElementNodeOverview"/>.)</p></note><note><p>During processing of a <termref def="dt-pending-update-list">pending update list</termref>, an <termref def="dt-xdm-instance">XDM instance</termref> may temporarily violate a data model constraint. An error is raised only if a constraint remains unsatisfied after all update primitives other than <code>upd:put</code> have been applied.</p></note></item><item><p>For each document or element node <code>$top</code> that was <termref def="dt-mark">marked for revalidation</termref> by one of the earlier steps, <code>upd:revalidate($top, $revalidation-mode)</code> is invoked.</p></item><item><p>As the final step, all <code>upd:put</code> primitives on <code>$pul</code> are applied.</p></item><item><p>The  <code>upd:applyUpdates</code> operation is atomic with respect to the data model. In other words, if <code>upd:applyUpdates</code> terminates normally, the resulting <termref def="dt-xdm-instance">XDM instance</termref> reflects the result of all update primitives; but if <code>upd:applyUpdates</code> raises an error, the resulting <termref def="dt-xdm-instance">XDM instance</termref>  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.</p><note><p>The results of implementation-dependent error conditions such as exceeding 
resource limits are beyond the scope of this specification.</p></note></item><item><p>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.</p></item></olist></def>
						</gitem></glist></div3><div3 id="id-upd-revalidate"><head>upd:revalidate</head><glist><gitem><label>Parameters</label><def><eg xml:space="preserve">upd:revalidate(
   $top as node(),
   $revalidation-mode as xs:string)</eg></def></gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p><code>$top</code> must be a document node or an element node.</p><p><code>$revalidation-mode</code> must be <code>"strict"</code>, <code>"lax"</code>, or <code>"skip"</code>.</p>
							</def>
						</gitem><gitem>
							<label>Summary</label>
							<def>
								<p>Schema validation is applied to the subtree rooted at <code>$top</code> in order to recover the types of updated nodes while preserving their <termref def="dt-node-identity">node identities</termref>.</p>
							</def>
						</gitem><gitem>
							<label>Semantics</label>
							<def>
								
							<p>If <code>$revalidation-mode</code> is <code>skip</code>, <code>upd:revalidate</code> performs no action. Otherwise:</p><olist><item><p>If <code>$revalidation-mode</code> is <code>lax</code>, define <code>$topV</code> as the result of the XQuery expression <code>validate lax {$top}</code>. If <code>$revalidation-mode</code> is <code>strict</code>, define <code>$topV</code> as the result of the XQuery expression <code>validate strict {$top}</code>. During computation of <code>$topV</code>, it is necessary to maintain a mapping between each node in <code>$topV</code> and the corresponding node (if any) in the subtree rooted at <code>$top</code> (this mapping is maintained in an implementation-dependent way.)</p><note><ulist><item><p>This step may raise an error <xerrorref spec="XQ" code="0027" class="DY"/> if <code>$top</code> is found to be invalid.</p></item><item><p>Some of the nodes in <code>$topV</code> (for example, default attributes generated by the validation process) may have no corresponding nodes in <code>$top</code>.</p></item></ulist></note></item><item><p>For each node <code>$nV</code> in <code>$topV</code> that has a corresponding node <code>$n</code> in <code>$top</code>, replace the following properties of <code>$n</code> with the corresponding properties of <code>$nV</code>: <code>type-name</code>, <code>typed-value</code>, <code>string-value</code>, <code>is-id</code>, <code>is-idrefs</code>, <code>namespace-bindings</code>, <code>nilled</code>.</p></item><item><p>For each node <code>$nV</code> in <code>$topV</code> that does not have a corresponding node in <code>$top</code>, insert the node <code>$nV</code> into the subtree rooted at <code>$top</code> as a child or attribute of the node corresponding to the parent of <code>$nV</code>.</p></item><item><p>The result of <code>upd:revalidate</code> is to modify the properties of the nodes rooted at <code>$top</code> and possibly to add some new nodes to this subtree. When the revalidation process is complete, <code>$topV</code> can be discarded.</p></item></olist><note><p>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.</p></note></def>
						</gitem></glist></div3><div3 id="id-upd-remove-type"><head>upd:removeType</head><glist><gitem><label>Parameters</label><def><eg xml:space="preserve">upd:removeType(
   $N as node())</eg></def></gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p><code>$N</code> must be an element or attribute node</p>
							</def>
						</gitem><gitem>
							<label>Summary</label>
							<def>
								<p> 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.</p>
							</def>
						</gitem><gitem>
							<label>Semantics</label>
							<def>
								
							<olist><item><p>If <code>$N</code> is an element node, its properties are changed as follows:</p><olist><item><p> If <code>type-name</code> is not equal to <code>xs:untyped</code>, then</p><p><olist><item><p><code>type-name</code> is set to <code>xs:anyType</code></p></item><item><p>If the parent of <code>N</code> is an element node, then <code>upd:removeType(parent($N))</code> is invoked.</p></item></olist> </p></item><item><p><code>string-value</code> is set equal to the concatenated contents of the text node descendants, in document order.</p></item><item><p><code>typed-value</code> is set equal to the <code>string-value</code> property, as an instance of <code>xs:untypedAtomic</code>.</p><note><p>The <termref def="dt-data-model">data model</termref> allows some flexibility to implementations regarding whether <code>string-value</code> and/or <code>typed-value</code> are stored or computed dynamically.</p></note></item><item><p><code>nilled</code>, <code>is-id</code>, and <code>is-idrefs</code> are set to <code>false</code>.</p></item></olist></item><item><p>If <code>$N</code> is an attribute node, its properties are changed as follows:</p><olist><item><p><code>type-name</code> is set to <code>xs:untypedAtomic</code>.</p> </item><item><p><code>typed-value</code> is set equal to the <code>string-value</code> property, as an instance of <code>xs:untypedAtomic</code>.</p></item><item><p> <code>is-id</code> and <code>is-idrefs</code> are set to <code>false</code>.</p></item><item><p>If <code>$N</code> has a parent, <code>upd:removeType(parent($N))</code> is invoked.</p></item></olist></item><item><p>The topmost ancestor of <code>$N</code> is <termref def="dt-mark">marked</termref> for revalidation.</p><p><termdef term="mark" id="dt-mark">To <term>mark</term> a node means to identify the node as participating in a later operation.</termdef> Marking of nodes is accomplished in an implementation-dependent way--for example, an implementation might maintain a list of marked nodes.</p></item></olist></def>
						</gitem></glist></div3><div3 id="id-upd-set-to-untyped"><head>upd:setToUntyped</head><glist><gitem><label>Parameters</label><def><eg xml:space="preserve">upd:setToUntyped(
   $N as node())</eg></def></gitem>
						<gitem>
							<label>Constraints</label>
							<def>
								<p><code>$N</code> must be an element or attribute node</p>
							</def>
						</gitem><gitem>
							<label>Summary</label>
							<def>
								<p> 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.</p>
							</def>
						</gitem><gitem>
							<label>Semantics</label>
							<def>
								
							<olist><item><p>If <code>$N</code> is an element node, its properties are changed as follows:</p><olist><item><p><code>type-name</code> is set to <code>xs:untyped</code>.</p></item><item><p><code>typed-value</code> is set equal to the <code>string-value</code> property, as an instance of <code>xs:untypedAtomic</code>.</p><note><p>The <termref def="dt-data-model">data model</termref> allows some flexibility to implementations regarding whether <code>string-value</code> and/or <code>typed-value</code> are stored or computed dynamically.</p></note></item><item><p><code>nilled</code>, <code>is-id</code>, and <code>is-idrefs</code> are set to <code>false</code>.</p></item><item><p><code>upd:setToUntyped()</code> is invoked on the attributes and child element nodes of <code>$N</code>.</p></item></olist></item><item><p>If <code>$N</code> is an attribute node, its properties are changed as follows:</p><olist><item><p><code>type-name</code> is set to <code>xs:untypedAtomic</code>.</p> </item><item><p><code>typed-value</code> is set equal to the <code>string-value</code> property, as an instance of <code>xs:untypedAtomic</code>.</p></item><item><p> <code>is-id</code> and <code>is-idrefs</code> are set to <code>false</code>.</p></item></olist></item></olist></def>
						</gitem></glist></div3></div2></div1>


<div1 id="id-update-static">
<head>Static Typing Feature</head>

<p>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
<bibref ref="XQueryFormalSemantics"/>.</p>

<div2 id="id-update-overview"><head>Overview and notations</head>

<p>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 <bibref ref="XQueryFormalSemantics"/> for a more detailed introduction.</p>

<p>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 <emph>Core</emph>, 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.</p>

    <smnotation>
      <p id="jd_map_expr">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.</p>

      	<mapping>
      	  <xquery>
      	    <expression>
      	      <map><emph>Expr</emph></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>
      	    </expression>
      	  </xquery>
      	  <core>
      	    <expression>
      	      <emph>CoreExpr</emph>
      	    </expression>
      	  </core>
      	</mapping>
    </smnotation>

    <smnotation>
      <p>The static semantics is specified through a
      <term>judgment</term> which gives for each expression its
      corresponding static type. The meaning of that judgment is
      defined through <term>inference rules</term> as in <bibref ref="XQueryFormalSemantics"/>.</p>

      <p id="jd_has_type">The judgment</p>

      <display>
      <clause>
        <environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
        <expression><emph>Expr</emph> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a></expression>
      </clause>
      </display>

      <p>holds when, in the static environment <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a>, the
      expression <emph>Expr</emph> has type <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a>.</p>
    </smnotation>

    <smnotation>
      <p> The static environment is the same as the one defined in
      <bibref ref="XQueryFormalSemantics"/>, extended with an entry
      corresponding to the revalidation mode, as follows.</p>

      <table summary="" role="figure" cellpadding="5">
      <col width="10%" span="1"/><!-- empty column forces left indentation -->
      <col width="15%" span="1"/>
      <col width="65%" align="justify" span="1"/>
      <col width="10%" span="1"/><!-- empty column forces right indentation -->
      <tbody>
      <tr><td rowspan="1" colspan="1"/>
          <td id="xq_revalidation_mode_env" valign="top" rowspan="1" colspan="1"><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a>.<a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_revalidation_mode_env" class="env">revalidationMode</a></td>
          <td rowspan="1" colspan="1">
            <table>
              <tbody>
                <tr><td rowspan="1" colspan="1">The <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a>.<a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_revalidation_mode_env" class="env">revalidationMode</a> environment
                component designates the <term>revalidation mode</term> in
                the XQuery Update Facility 1.0 static context.</td></tr>

                <tr><td rowspan="1" colspan="1">The <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a>.<a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_revalidation_mode_env" class="env">revalidationMode</a> environment
                component is one of <term>strict</term>,
                <term>lax</term>, or <term>skip</term>.</td></tr>
                </tbody>
            </table>
          </td>
          <td rowspan="1" colspan="1"/>
      </tr>

      </tbody>
      </table>
   </smnotation>
</div2>

<div2 id="id-static-typing-changes"><head>Change to Static Typing Rules of XQuery 1.0</head><p>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 <code>( )</code> or <code>data(( ))</code> is <code>empty-sequence( )</code>. XQuery Update Facility 1.0 modifies this rule so that it applies only to <termref def="dt-simple-expression">simple expressions</termref> (i.e., it does not apply to <termref def="dt-updating-expression">updating expressions</termref>.)</p></div2><div2 id="id-update-core"><head>Core Grammar</head><p>We extend the
XQuery Core defined in <bibref ref="XQueryFormalSemantics"/> with five
expressions needed to support the XQuery Update Facility 1.0: insert, delete, rename,
replace, and transform.</p>

<scrap headstyle="show"> 
<head/> 
<prod num="23 (Core)" id="doc-core-ExprSingle"><lhs>ExprSingle</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-core-FLWORExpr" xlink:type="simple">FLWORExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-core-QuantifiedExpr" xlink:type="simple">QuantifiedExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-core-TypeswitchExpr" xlink:type="simple">TypeswitchExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-core-IfExpr" xlink:type="simple">IfExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-InsertExpr" xlink:type="simple">InsertExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-DeleteExpr" xlink:type="simple">DeleteExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-RenameExpr" xlink:type="simple">RenameExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-ReplaceExpr" xlink:type="simple">ReplaceExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-TransformExpr" xlink:type="simple">TransformExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-core-OrExpr" xlink:type="simple">OrExpr</nt></rhs></prod> 
<prod num="99 (Core)" id="doc-core-InsertExpr"><lhs>InsertExpr</lhs><rhs>"insert"  "nodes"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-SourceExpr" xlink:type="simple">SourceExpr</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-InsertExprTargetChoice" xlink:type="simple">InsertExprTargetChoice</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-TargetExpr" xlink:type="simple">TargetExpr</nt></rhs></prod> 
<prod num="98 (Core)" id="doc-core-InsertExprTargetChoice"><lhs>InsertExprTargetChoice</lhs><rhs>(("as"  ("first"  |  "last"))?  "into")<br/>|  "after"<br/>|  "before"</rhs></prod> 
<prod num="103 (Core)" id="doc-core-SourceExpr"><lhs>SourceExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod> 
<prod num="104 (Core)" id="doc-core-TargetExpr"><lhs>TargetExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod> 
<prod num="100 (Core)" id="doc-core-DeleteExpr"><lhs>DeleteExpr</lhs><rhs>"delete"  "nodes"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-TargetExpr" xlink:type="simple">TargetExpr</nt></rhs></prod> 
<prod num="101 (Core)" id="doc-core-ReplaceExpr"><lhs>ReplaceExpr</lhs><rhs>"replace"  ("value"  "of")?  "node"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-TargetExpr" xlink:type="simple">TargetExpr</nt>  "with"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod> 
<prod num="102 (Core)" id="doc-core-RenameExpr"><lhs>RenameExpr</lhs><rhs>"rename"  "node"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-TargetExpr" xlink:type="simple">TargetExpr</nt>  "as"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-NewNameExpr" xlink:type="simple">NewNameExpr</nt></rhs></prod> 
<prod num="105 (Core)" id="doc-core-NewNameExpr"><lhs>NewNameExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod> 
<prod num="106 (Core)" id="doc-core-TransformExpr"><lhs>TransformExpr</lhs><rhs>"copy"  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-core-VarName" xlink:type="simple">VarName</nt>  ":="  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-ExprSingle" xlink:type="simple">ExprSingle</nt>  (","  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-core-VarName" xlink:type="simple">VarName</nt>  ":="  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-ExprSingle" xlink:type="simple">ExprSingle</nt>)*  "modify"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-ExprSingle" xlink:type="simple">ExprSingle</nt>  "return"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="doc-core-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod> 
</scrap>

<ulist>
  <item><p id="prod-core-IfExpr">The core grammar production for <code>IfExpr</code> can be found in <bibref ref="XQueryFormalSemantics"/></p></item>
  <item><p id="prod-core-OrExpr">The core grammar production for <code>OrExpr</code> can be found in <bibref ref="XQueryFormalSemantics"/></p></item>
  <item><p id="prod-core-FLWORExpr">The core grammar production for <code>FLWORExpr</code> can be found in <bibref ref="XQueryFormalSemantics"/></p></item>
  <item><p id="prod-core-QuantifiedExpr">The core grammar production for <code>QuantifiedExpr</code> can be found in <bibref ref="XQueryFormalSemantics"/></p></item>
  <item><p id="prod-core-TypeswitchExpr">The core grammar production for <code>TypeswitchExpr</code> can be found in <bibref ref="XQueryFormalSemantics"/></p></item>
  <item><p id="prod-core-VarName">The core grammar production for <code>VarName</code> can be found in <bibref ref="XQueryFormalSemantics"/></p></item>
</ulist>
</div2>


<div2 id="id-update-norm-prolog">
  <head>XQuery Update Facility 1.0 Prolog</head>

  <p>In addition to the normalization rules defined in <bibref ref="XQueryFormalSemantics"/> for the XQuery 1.0 prolog, the
  following normalization rules apply to the revalidation mode
  setter.</p>

  <smnorm>
    <p>Revalidation declarations are left unchanged through
    normalization.</p>

    <mapping>
     <xquery>
      <expression>
       <map><emph>RevalidationDecl</emph></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_prolog" class="judgment"><subscript>PrologDecl</subscript></a>
      </expression>
     </xquery>
     <core>
      <expression>
        <emph>RevalidationDecl</emph>
      </expression>
     </core>
    </mapping>
  </smnorm>

  <smcontext>
    <p>The revalidation declaration modifies the revalidation mode
    in the static context.</p>

    <infergr>
	<infer>
	  <prejudge>
	      <clause>
              <expression>
                <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a><subscript>1</subscript> =
                  <update>
                    <environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a>.<a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_revalidation_mode_env" class="env">revalidationMode</a></environment>
                    <expression>
                    <emph>RevalidationMode</emph></expression>
                  </update>
              </expression>
	      </clause>
	  </prejudge>
	  <postjudge>
	    <multiclause>
	      <clause>
              <environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
              <expression>declare revalidation <emph>RevalidationMode</emph>
              <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_yields_context" class="judgment"><term>=&gt;</term><subscript>stat</subscript></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a><subscript>1</subscript></expression> 
	      </clause>
	    </multiclause>
	  </postjudge>
	</infer>
    </infergr>
  </smcontext>
</div2>

<div2 id="id-update-norm-expr">
  <head>XQuery Update Facility 1.0 Expressions</head>

    <p>In addition to the normalization and static typing rules
    defined in <bibref ref="XQueryFormalSemantics"/> 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.</p>

    <div3 id="id-update-typing-insert">
     <head>Insert</head>

    <smnorm>
      <p>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.</p>

      <mapping>
       <xquery>
      	<expression>
         <map>insert (node|nodes) <emph>Expr</emph><subscript>1</subscript> <emph>InsertExprTargetChoice</emph> <emph>Expr</emph><subscript>2</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>
        </expression>
       </xquery>
       <core>
        <expression>
         insert nodes <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#sec_items_to_nodes"><emph>fs:</emph><code>item-sequence-to-node-sequence</code></a>(<map><emph>Expr</emph><subscript>1</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>)
      	 <emph>InsertExprTargetChoice</emph>
         <map><emph>Expr</emph><subscript>2</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>
        </expression>
       </core>
      </mapping>

      <p>Where <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#sec_items_to_nodes"><emph>fs:</emph><code>item-sequence-to-node-sequence</code></a> is the special function used
      for computing element content and is defined in <bibref ref="XQueryFormalSemantics"/>.</p>

    </smnorm>

    <smtype>
      <p>The static typing rule for insert depends on whether it is an
      insert <code>into</code>, or an insert <code>before</code> or
      <code>after</code>.</p>

      <p>In the case of an insert <code>into</code>, 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.</p>

        <infergr>
          <infer>
            <prejudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript></expression>
                </clause>
              </multiclause>
	      <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a>
                (attribute *)*, (element * | text | comment | processing-instruction *)*</expression>
	        </clause>
	      </multiclause>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript></expression>
                </clause>
              </multiclause>
	      <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> (element *)?</expression>
	        </clause>
	      </multiclause>
            </prejudge>
            <postjudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                        <expression>insert nodes <emph>Expr</emph><subscript>1</subscript> ((as (first | last))? into) <emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <code>empty</code></expression>
                </clause>
              </multiclause>
            </postjudge>
          </infer>
        </infergr>

        <infergr>
          <infer>
            <prejudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript></expression>
                </clause>
              </multiclause>
	      <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a>
                (element * | text | comment | processing-instruction *)*</expression>
	        </clause>
	      </multiclause>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript></expression>
                </clause>
              </multiclause>
	      <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> <map>document-node()?</map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_sequencetype" class="judgment"><subscript>sequencetype</subscript></a></expression>
	        </clause>
	      </multiclause>
            </prejudge>
            <postjudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                        <expression>insert nodes <emph>Expr</emph><subscript>1</subscript> ((as (first | last))?
    	 into) <emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <code>empty</code></expression>
                </clause>
              </multiclause>
            </postjudge>
          </infer>
        </infergr>

        <p>In the case of an insert <code>before</code> or
        <code>after</code>, the type of the target node must be either
        an element, text, comment or processing-instruction node. This
        is expressed by the following rule.</p>

        <infergr>
          <infer>
            <prejudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript></expression>
                </clause>
              </multiclause>
	      <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a>
                (attribute *)*, (element * | text | comment | processing-instruction *)*</expression>
	        </clause>
	      </multiclause>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript></expression>
                </clause>
              </multiclause>
	      <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> (element * | text | comment | processing-instruction *)?</expression>
	        </clause>
	      </multiclause>
            </prejudge>
            <postjudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                        <expression>insert nodes <emph>Expr</emph><subscript>1</subscript> (after | before) <emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <code>empty</code></expression>
                </clause>
              </multiclause>
            </postjudge>
          </infer>
        </infergr>
      </smtype>

    </div3>

    <div3 id="id-update-typing-delete">
     <head>Delete</head>

     <smnorm>
      <p>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.</p>

    <mapping>
     <xquery>
    	<expression>
       <map>delete (node|nodes) <emph>Expr</emph><subscript>1</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>
      </expression>
     </xquery>
     <core>
      <expression>
       delete nodes <map><emph>Expr</emph><subscript>1</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>
      </expression>
     </core>
    </mapping>
     </smnorm>

    <smtype>
    <p>The static typing rule for delete is as follows.</p>

        <infergr>
          <infer>
            <prejudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a></expression>
                </clause>
              </multiclause>
	      <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> <map>node()*</map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_sequencetype" class="judgment"><subscript>sequencetype</subscript></a></expression>
	        </clause>
	      </multiclause>
            </prejudge>
            <postjudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                        <expression>delete (node|nodes) <emph>Expr</emph> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <code>empty</code></expression>
                </clause>
              </multiclause>
            </postjudge>
          </infer>
        </infergr>
    </smtype>

    </div3>

    <div3 id="id-update-typing-replace">
     <head>Replace</head>

    <smnorm>
      <p>The following normalization rules applies to replace
      expressions.</p>

    <mapping>
     <xquery>
    	<expression>
       <map>replace node <emph>Expr</emph><subscript>1</subscript> with <emph>Expr</emph><subscript>2</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>
      </expression>
     </xquery>
     <core>
      <expression>
       replace node <map><emph>Expr</emph><subscript>1</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a> with <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#sec_items_to_nodes"><emph>fs:</emph><code>item-sequence-to-node-sequence</code></a>(<map><emph>Expr</emph><subscript>2</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>)
      </expression>
     </core>
    </mapping>

    <p>Normalization of replace value of expressions.</p>

    <mapping>
     <xquery>
    	<expression>
       <map>replace value of node <emph>Expr</emph><subscript>1</subscript> with <emph>Expr</emph><subscript>2</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>
      </expression>
     </xquery>
     <core>
      <expression>
       replace value of node <map><emph>Expr</emph><subscript>1</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a> with
      <map>text { <emph>Expr</emph><subscript>2</subscript> }</map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>
      </expression>
     </core>
    </mapping>
    </smnorm>

    <smtype>
    <p>If the <code>value of</code> modifier is not specified, a
    replace expression replaces one node with a new sequence of zero
    or more nodes.</p>

    <p>An attribute node can be replaced only by zero or more
    attribute nodes.</p>

        <infergr>
          <infer>
            <prejudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript></expression>
                </clause>
	      </multiclause>
              <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> (attribute *)?</expression>
	        </clause>
	      </multiclause>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript></expression>
                </clause>
	      </multiclause>
              <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> (attribute *)*</expression>
	        </clause>
	      </multiclause>
            </prejudge>
            <postjudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                        <expression>replace node <emph>Expr</emph><subscript>1</subscript> with <emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <code>empty</code></expression>
                </clause>
              </multiclause>
            </postjudge>
          </infer>
        </infergr>

    <p>An element, text, comment, or processing instruction node can
    be replaced only by zero or more element, text, comment, or
    processing instruction nodes.</p>

        <infergr>
          <infer>
            <prejudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript></expression>
                </clause>
	      </multiclause>
              <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> (element * | text | comment | processing-instruction *)?</expression>
	        </clause>
	      </multiclause>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript></expression>
                </clause>
	      </multiclause>
              <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> (element * | text | comment | processing-instruction *)*</expression>
	        </clause>
	      </multiclause>
            </prejudge>
            <postjudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                        <expression>replace node <emph>Expr</emph><subscript>1</subscript> with <emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <code>empty</code></expression>
                </clause>
              </multiclause>
            </postjudge>
          </infer>
        </infergr>

    	<p>If the <code>value of</code> 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.</p>

        <infergr>
          <infer>
            <prejudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript></expression>
                </clause>
	      </multiclause>
              <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> (attribute *| element * | text | comment | processing-instruction *)?</expression>
	        </clause>
	      </multiclause>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript></expression>
                </clause>
	      </multiclause>
              <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> text?</expression>
	        </clause>
	      </multiclause>
            </prejudge>
            <postjudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                        <expression>replace value of node <emph>Expr</emph><subscript>1</subscript> with <emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <code>empty</code></expression>
                </clause>
              </multiclause>
            </postjudge>
          </infer>
        </infergr>
    </smtype>

    </div3>

    <div3 id="id-update-typing-rename">
     <head>Rename</head>

    <smnorm>
      <p>The following normalization rule applies to rename
      expressions.</p>

    <mapping>
     <xquery>
    	<expression>
       <map>rename node <emph>Expr</emph><subscript>1</subscript> as <emph>Expr</emph><subscript>2</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>
      </expression>
     </xquery>
     <core>
      <expression>
       rename node <map><emph>Expr</emph><subscript>1</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a> as <code>fn:data</code>(<map><emph>Expr</emph><subscript>2</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>)
      </expression>
     </core>
    </mapping>
    </smnorm>

    <smtype>
    	<p>The target of a rename expression must be either an
    	element, attribute or processing-instruction, and its new name
    	must be either of type <code>xs:QName</code>, <code>xs:string</code>, or
    	<a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#dt-xs_untypedAtomic"><code>xs:untypedAtomic</code></a>.</p>
   
        <infergr>
          <infer>
            <prejudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript></expression>
                </clause>
	      </multiclause>
              <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> (attribute *| element * | processing-instruction *)?</expression>
	        </clause>
	      </multiclause>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript></expression>
                </clause>
	      </multiclause>
              <multiclause>
	        <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                <expression><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> (<code>xs:QName</code> | <code>xs:string</code> | <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#dt-xs_untypedAtomic"><code>xs:untypedAtomic</code></a>)</expression>
	        </clause>
	      </multiclause>
            </prejudge>
            <postjudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                        <expression>rename node <emph>Expr</emph><subscript>1</subscript> as <emph>Expr</emph><subscript>2</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <code>empty</code></expression>
                </clause>
              </multiclause>
            </postjudge>
          </infer>
        </infergr>
    </smtype>

    </div3>

    <div3 id="id-update-typing-transform">
     <head>Transform</head>

    <smnorm>
      <p>The following normalization rule applies to transform
      expressions.</p>

    <mapping>
     <xquery>
      <expression>
       <map>
        <table><tbody>
         <tr><td rowspan="1" colspan="1">copy</td></tr>
         <tr><td rowspan="1" colspan="1">  <emph>VarName</emph><subscript>1</subscript> := <emph>Expr</emph><subscript>1</subscript></td></tr>
         <tr><td rowspan="1" colspan="1">    ...</td></tr>
         <tr><td rowspan="1" colspan="1">  <emph>VarName</emph><subscript>n</subscript> := <emph>Expr</emph><subscript>n</subscript></td></tr>
         <tr><td rowspan="1" colspan="1">  modify <emph>Expr</emph><subscript>0</subscript> return <emph>Expr</emph><subscript>r</subscript></td></tr>
        </tbody></table>
       </map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>
      </expression>
     </xquery>
     <core>
      <expression>
        <table><tbody>
         <tr><td rowspan="1" colspan="1">copy</td></tr>
         <tr><td rowspan="1" colspan="1">  <emph>VarName</emph><subscript>1</subscript> := <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#sec_items_to_nodes"><emph>fs:</emph><code>item-sequence-to-node-sequence</code></a>(<map><emph>Expr</emph><subscript>1</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>)</td></tr>
         <tr><td rowspan="1" colspan="1">    ...</td></tr>
         <tr><td rowspan="1" colspan="1">  <emph>VarName</emph><subscript>n</subscript> := <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#sec_items_to_nodes"><emph>fs:</emph><code>item-sequence-to-node-sequence</code></a>(<map><emph>Expr</emph><subscript>n</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a>)</td></tr>
         <tr><td rowspan="1" colspan="1">  modify <map><emph>Expr</emph><subscript>0</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a> return <map><emph>Expr</emph><subscript>r</subscript></map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_expr" class="judgment"><subscript>Expr</subscript></a></td></tr>
        </tbody></table>
      </expression>
     </core>
    </mapping>
    </smnorm>

    <smtype>
      <p>The transform expression is type checked using the following
      inference rule.</p>

        <infergr>
          <infer>
            <prejudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
                  <expression><emph>Expr</emph><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript></expression>
                </clause>
	      </multiclause>
              <multiclause>
                <clause>
                  <environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
                  <expression> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> <map>node()</map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_sequencetype" class="judgment"><subscript>sequencetype</subscript></a></expression>
                </clause>
              </multiclause>
 	      <multiclause>
 	        <clause>
                <environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
 	        <expression><emph>VarName</emph><subscript>1</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_var_qname_expands_to" class="judgment"><term>of var expands to</term></a> <emph>Variable</emph><subscript>1</subscript>
 	        </expression>
 	        </clause>
 	      </multiclause>
              <multiclause>
                <clause>
                  <expression>
                    <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a><subscript>1</subscript> =
                    <update>
                      <environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a>.<a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_type_env" class="env">varType</a></environment>
                      <expression><emph>Variable</emph><subscript>1</subscript> =&gt; <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>1</subscript></expression>
                    </update>
                  </expression>
                </clause>
              </multiclause>
<!--
              <multiclause>
                <clause>
                  <environment>&xq_stat_env1;</environment>
                  <expression> &gr_Expr2; &jd_has_type; &gr_Type2; </expression>
                </clause>
              </multiclause>
-->
              <multiclause>
	        <clause>
                <expression>...</expression>
	        </clause>
	      </multiclause>
              <multiclause>
                <clause>
                  <environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a><subscript>n-1</subscript></environment>
                  <expression> <emph>Expr</emph><subscript>n</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>n</subscript> </expression>
                </clause>
              </multiclause>
              <multiclause>
                <clause>
                  <environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a><subscript>n-1</subscript></environment>
                  <expression> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>n</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_subtype_of" class="judgment"><term>&lt;:</term></a> <map>node()</map><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_map_sequencetype" class="judgment"><subscript>sequencetype</subscript></a></expression>
                </clause>
              </multiclause>
 	      <multiclause>
 	        <clause>
                <environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a></environment>
 	        <expression><emph>VarName</emph><subscript>n</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_var_qname_expands_to" class="judgment"><term>of var expands to</term></a> <emph>Variable</emph><subscript>n</subscript>
 	        </expression>
 	        </clause>
 	      </multiclause>
              <multiclause>
                <clause>
                  <expression>
                    <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a><subscript>n</subscript> =
                    <update>
                      <environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a><subscript>n-1</subscript>.<a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_type_env" class="env">varType</a></environment>
                      <expression><emph>Variable</emph><subscript>n</subscript> =&gt; <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>n</subscript></expression>
                    </update>
                  </expression>
                </clause>
              </multiclause>
              <multiclause>
                <clause>
                  <environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a><subscript>n</subscript></environment>
                  <expression> <emph>Expr</emph><subscript>0</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>0</subscript> </expression>
                </clause>
              </multiclause>
              <multiclause>
                <clause>
                  <environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a><subscript>n</subscript></environment>
                  <expression> <emph>Expr</emph><subscript>r</subscript> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>r</subscript> </expression>
                </clause>
              </multiclause>
            </prejudge>
            <postjudge>
              <multiclause>
                <clause><environment><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#xq_stat_env_def" class="env">statEnv</a> </environment>
       <expression>
        <table><tbody>
         <tr><td rowspan="1" colspan="1">copy</td></tr>
         <tr><td rowspan="1" colspan="1">  <emph>VarName</emph><subscript>1</subscript> := <emph>Expr</emph><subscript>1</subscript></td></tr>
         <tr><td rowspan="1" colspan="1">    ...</td></tr>
         <tr><td rowspan="1" colspan="1">  <emph>VarName</emph><subscript>n</subscript> := <emph>Expr</emph><subscript>n</subscript></td></tr>
         <tr><td rowspan="1" colspan="1">  modify <emph>Expr</emph><subscript>0</subscript> return <emph>Expr</emph><subscript>r</subscript></td></tr>
         <tr><td rowspan="1" colspan="1"><a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#jd_has_type" class="judgment"><term>:</term></a> <a href="http://www.w3.org/TR/2007/REC-xquery-semantics-20070123/#doc-fs-Type"><emph>Type</emph></a><subscript>r</subscript></td></tr>
        </tbody></table>
      </expression>
               </clause>
              </multiclause>
            </postjudge>
          </infer>
        </infergr>
    </smtype>

    </div3>

    <div3 id="id-update-typing-examples">
     <head>Examples</head>

    <smexamples>
       <p>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.</p>

<ulist><item><p><code>insert node &lt;x/&gt; into &lt;a/&gt;</code></p><p>Passes static typing</p></item><item><p><code>insert node 1 into &lt;a/&gt;</code></p><p>Passes static typing</p></item><item><p><code>insert node 1 into (&lt;a/&gt;,&lt;a/&gt;)</code></p><p>Fails static typing because the target expression does
  not return a single node</p></item><item><p><code>insert node (element a {()}, attribute b {()}) into &lt;doc/&gt;</code></p><p>Fails static typing because the attribute node is not
  at the head of the insertion list</p></item><item><p><code>insert node &lt;x/&gt; into //a</code></p><p>Fails static typing because the target expression may not
  return a single node (assuming the schema allows <code>//a</code>
  to return multiple <code>a</code> elements)</p></item><item><p><code>rename node &lt;a/&gt; as "b"</code></p><p>Passes static typing</p></item><item><p><code>rename node &lt;a/&gt; as 1</code></p><p>Fails static typing because the new name does not have
  one of the permissible types</p></item></ulist>

    </smexamples>

    </div3>

</div2>


</div1>


<div1 id="id-xquery-update-conformance">
    <head>Conformance</head>
    <p>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
        <bibref ref="RFC2119"/>. <termdef id="must" term="must">
            <term>MUST</term> means that the item is an absolute requirement of the specification.</termdef>
        <termdef id="may" term="may">
            <term>MAY</term> means that an item is truly optional.</termdef>
        <termdef id="should" term="should">
            <term>SHOULD</term> means that there may exist valid reasons in particular circumstances
            to ignore a particular item, but the full implications must be understood and carefully
            weighed before choosing a different course.</termdef>
    </p>
   
    <p>An XQuery processor that claims to conform to this specification
        <termref def="must">MUST</termref> include a claim of Minimal Conformance as defined in
        <specref ref="id-minimal-conformance"/>. In addition to a claim of Minimal Conformance, it
        <termref def="may">MAY</termref> claim conformance to one or more optional features
        defined in <specref ref="id-conform-optional-features"/>.</p>

    <div2 id="id-minimal-conformance">
        <head>Minimal Conformance</head>
        <p>Minimal Conformance to this specification <termref def="must">MUST</termref> include all
            of the following items:</p>
        <olist>
            <item>
                <p>Minimal Conformance to <bibref ref="xquery"/>.</p>
            </item>
            <item>
                <p>Support for everything specified in this document
                except those features specified in <specref ref="id-conform-optional-features"/> to be optional
                and <specref ref="id-xquf-xqueryx"/>. If an
                implementation does not provide a given optional
                feature, it <termref def="must">MUST</termref>
                implement any requirements specified in <specref ref="id-conform-optional-features"/> for
                implementations that do not provide that feature.</p>
	    </item>
	    <item>
	      <p>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 <specref ref="id-impl-defs"/>.</p>
                <note>
                    <p>Implementations are not required to define
                    items specified to be implementation-dependent.</p>
                </note>
            </item>
        </olist>
    </div2>
    <div2 id="id-conform-optional-features">
        <head>Optional Features</head>
	    <p>An implementation of XQuery that includes the Update
	    Facility   <termref def="may">MAY</termref> also support the Optional Features of <bibref ref="xquery"/>. These are Schema Import Feature, Schema
	    Validation Feature, Static Typing Feature, Full Axis
	    Feature, Module Feature, and Serialization Feature.</p>

	    <p>If an implementation claims support of the Static
	    Typing Feature, then it   <termref def="may">MAY</termref> also claim support of the
	    Update Facility Static Typing Feature.</p>


        <div3 id="id-update-facility-static-typing-feature">
            <head>Update Facility Static Typing Feature</head> 

                <p>
                <termdef id="upd-static-typing-feature" term="static typing feature">The <term>Update
                Facility Static Typing Feature</term> provides support
                for the static semantics defined in <specref ref="id-update-static"/>,
                and requires implementations to detect and report type errors
                during the static analysis phase.</termdef>
                </p>


            <p>If an implementation does not support the <termref def="upd-static-typing-feature">Update Static Typing
            Feature</termref>, but can nevertheless determine during
            the static analysis phase that an expression, if
            evaluated, will necessarily raise a type error at run
            time, the implementation <termref def="may">MAY</termref>
            raise that error during the static analysis phase. The
            choice of whether to raise such an error at analysis time
            is implementation-dependent.</p>

            <note>
                <p>An implementation that does not support the
                <termref def="upd-static-typing-feature">Update Static Typing
                Feature</termref> is not required to raise type errors
                during the static analysis phase; however, it <termref def="must">MUST</termref> detect and raise
                non-type-related static errors during the static
                analysis phase.</p>
            </note>
	
        </div3>
    </div2>

</div1>

<div1 id="id-xqueryx-update-conformance">
<head>XQueryX Conformance</head>

<p>This section defines the conformance criteria for an XQueryX processor 
that includes the Update Facility.</p>

<p>In this section, the terms <termref def="must">MUST</termref>, <termref def="may">MAY</termref>, and <termref def="should">SHOULD</termref> are used as
defined in <specref ref="id-xquery-update-conformance"/>.</p>

<p>An XQueryX processor that claims to conform to this specification
<termref def="must">MUST</termref> implement the XQueryX syntax as defined
in <specref ref="id-xquf-xqueryx"/> and include a claim of Minimal
Conformance as defined in <specref ref="id-xquery-update-conformance"/>.  In addition to a claim of
Minimal Conformance, it <termref def="may">MAY</termref> claim conformance to one or more optional
features defined in <specref ref="id-conform-optional-features"/>.</p>
</div1>
</body>
<back id="id-appendices">

<div1 id="id-grammar">
		<head>EBNF for XQuery 1.0 Grammar with Update extensions</head>

<p>The EBNF in this document and in this section is aligned with
the current XML Query 1.0 grammar (see <bibref ref="xquery"/>).</p>

		<scrap role="non-terminal-structure-expand" headstyle="show"><head/>
<prod num="1" id="prod-xquery-Module"><lhs>Module</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VersionDecl" xlink:type="simple">VersionDecl</nt>?  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-LibraryModule" xlink:type="simple">LibraryModule</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-MainModule" xlink:type="simple">MainModule</nt>)</rhs></prod><prod num="2" id="prod-xquery-VersionDecl"><lhs>VersionDecl</lhs><rhs>"xquery"  "version"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-StringLiteral" xlink:type="simple">StringLiteral</nt>  ("encoding"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-StringLiteral" xlink:type="simple">StringLiteral</nt>)?  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Separator" xlink:type="simple">Separator</nt></rhs></prod><prod num="3" id="prod-xquery-MainModule"><lhs>MainModule</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Prolog" xlink:type="simple">Prolog</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QueryBody" xlink:type="simple">QueryBody</nt></rhs></prod><prod num="4" id="prod-xquery-LibraryModule"><lhs>LibraryModule</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ModuleDecl" xlink:type="simple">ModuleDecl</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Prolog" xlink:type="simple">Prolog</nt></rhs></prod><prod num="5" id="prod-xquery-ModuleDecl"><lhs>ModuleDecl</lhs><rhs>"module"  "namespace"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NCName" xlink:type="simple">NCName</nt>  "="  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-URILiteral" xlink:type="simple">URILiteral</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Separator" xlink:type="simple">Separator</nt></rhs></prod><prod num="6" id="prod-xquery-Prolog"><lhs>Prolog</lhs><rhs>((<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DefaultNamespaceDecl" xlink:type="simple">DefaultNamespaceDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Setter" xlink:type="simple">Setter</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NamespaceDecl" xlink:type="simple">NamespaceDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Import" xlink:type="simple">Import</nt>)  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Separator" xlink:type="simple">Separator</nt>)*  ((<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarDecl" xlink:type="simple">VarDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-FunctionDecl" xlink:type="simple">FunctionDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-OptionDecl" xlink:type="simple">OptionDecl</nt>)  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Separator" xlink:type="simple">Separator</nt>)*</rhs></prod><prod num="7" id="prod-xquery-Setter"><lhs>Setter</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-BoundarySpaceDecl" xlink:type="simple">BoundarySpaceDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DefaultCollationDecl" xlink:type="simple">DefaultCollationDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-BaseURIDecl" xlink:type="simple">BaseURIDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ConstructionDecl" xlink:type="simple">ConstructionDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-OrderingModeDecl" xlink:type="simple">OrderingModeDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-EmptyOrderDecl" xlink:type="simple">EmptyOrderDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-RevalidationDecl" xlink:type="simple">RevalidationDecl</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CopyNamespacesDecl" xlink:type="simple">CopyNamespacesDecl</nt></rhs></prod><prod num="8" id="prod-xquery-Import"><lhs>Import</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SchemaImport" xlink:type="simple">SchemaImport</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ModuleImport" xlink:type="simple">ModuleImport</nt></rhs></prod><prod num="9" id="prod-xquery-Separator"><lhs>Separator</lhs><rhs>";"</rhs></prod><prod num="10" id="prod-xquery-NamespaceDecl"><lhs>NamespaceDecl</lhs><rhs>"declare"  "namespace"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NCName" xlink:type="simple">NCName</nt>  "="  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-URILiteral" xlink:type="simple">URILiteral</nt></rhs></prod><prod num="11" id="prod-xquery-BoundarySpaceDecl"><lhs>BoundarySpaceDecl</lhs><rhs>"declare"  "boundary-space"  ("preserve"  |  "strip")</rhs></prod><prod num="12" id="prod-xquery-DefaultNamespaceDecl"><lhs>DefaultNamespaceDecl</lhs><rhs>"declare"  "default"  ("element"  |  "function")  "namespace"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-URILiteral" xlink:type="simple">URILiteral</nt></rhs></prod><prod num="13" id="prod-xquery-OptionDecl"><lhs>OptionDecl</lhs><rhs>"declare"  "option"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-StringLiteral" xlink:type="simple">StringLiteral</nt></rhs></prod><prod num="14" id="prod-xquery-OrderingModeDecl"><lhs>OrderingModeDecl</lhs><rhs>"declare"  "ordering"  ("ordered"  |  "unordered")</rhs></prod><prod num="15" id="prod-xquery-EmptyOrderDecl"><lhs>EmptyOrderDecl</lhs><rhs>"declare"  "default"  "order"  "empty"  ("greatest"  |  "least")</rhs></prod><prod num="16" id="prod-xquery-CopyNamespacesDecl"><lhs>CopyNamespacesDecl</lhs><rhs>"declare"  "copy-namespaces"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PreserveMode" xlink:type="simple">PreserveMode</nt>  ","  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-InheritMode" xlink:type="simple">InheritMode</nt></rhs></prod><prod num="17" id="prod-xquery-PreserveMode"><lhs>PreserveMode</lhs><rhs>"preserve"  |  "no-preserve"</rhs></prod><prod num="18" id="prod-xquery-InheritMode"><lhs>InheritMode</lhs><rhs>"inherit"  |  "no-inherit"</rhs></prod><prod num="19" id="prod-xquery-DefaultCollationDecl"><lhs>DefaultCollationDecl</lhs><rhs>"declare"  "default"  "collation"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-URILiteral" xlink:type="simple">URILiteral</nt></rhs></prod><prod num="20" id="prod-xquery-BaseURIDecl"><lhs>BaseURIDecl</lhs><rhs>"declare"  "base-uri"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-URILiteral" xlink:type="simple">URILiteral</nt></rhs></prod><prod num="21" id="prod-xquery-SchemaImport"><lhs>SchemaImport</lhs><rhs>"import"  "schema"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SchemaPrefix" xlink:type="simple">SchemaPrefix</nt>?  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-URILiteral" xlink:type="simple">URILiteral</nt>  ("at"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-URILiteral" xlink:type="simple">URILiteral</nt>  (","  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-URILiteral" xlink:type="simple">URILiteral</nt>)*)?</rhs></prod><prod num="22" id="prod-xquery-SchemaPrefix"><lhs>SchemaPrefix</lhs><rhs>("namespace"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NCName" xlink:type="simple">NCName</nt>  "=")  |  ("default"  "element"  "namespace")</rhs></prod><prod num="23" id="prod-xquery-ModuleImport"><lhs>ModuleImport</lhs><rhs>"import"  "module"  ("namespace"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NCName" xlink:type="simple">NCName</nt>  "=")?  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-URILiteral" xlink:type="simple">URILiteral</nt>  ("at"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-URILiteral" xlink:type="simple">URILiteral</nt>  (","  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-URILiteral" xlink:type="simple">URILiteral</nt>)*)?</rhs></prod><prod num="24" id="prod-xquery-VarDecl"><lhs>VarDecl</lhs><rhs>"declare"  "variable"  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TypeDeclaration" xlink:type="simple">TypeDeclaration</nt>?  ((":="  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>)  |  "external")</rhs></prod><prod num="25" id="prod-xquery-ConstructionDecl"><lhs>ConstructionDecl</lhs><rhs>"declare"  "construction"  ("strip"  |  "preserve")</rhs></prod><prod num="26" id="prod-xquery-FunctionDecl"><lhs>FunctionDecl</lhs><rhs>"declare"  "updating"?  "function"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  "("  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ParamList" xlink:type="simple">ParamList</nt>?  ")"  ("as"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SequenceType" xlink:type="simple">SequenceType</nt>)?  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-EnclosedExpr" xlink:type="simple">EnclosedExpr</nt>  |  "external")</rhs></prod><prod num="27" id="prod-xquery-ParamList"><lhs>ParamList</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Param" xlink:type="simple">Param</nt>  (","  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Param" xlink:type="simple">Param</nt>)*</rhs></prod><prod num="28" id="prod-xquery-Param"><lhs>Param</lhs><rhs>"$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TypeDeclaration" xlink:type="simple">TypeDeclaration</nt>?</rhs></prod><prod num="29" id="prod-xquery-EnclosedExpr"><lhs>EnclosedExpr</lhs><rhs>"{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  "}"</rhs></prod><prod num="30" id="prod-xquery-QueryBody"><lhs>QueryBody</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt></rhs></prod><prod num="31" id="prod-xquery-Expr"><lhs>Expr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>  (","  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>)*</rhs></prod><prod num="32" id="prod-xquery-ExprSingle"><lhs>ExprSingle</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-FLWORExpr" xlink:type="simple">FLWORExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QuantifiedExpr" xlink:type="simple">QuantifiedExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TypeswitchExpr" xlink:type="simple">TypeswitchExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-IfExpr" xlink:type="simple">IfExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-InsertExpr" xlink:type="simple">InsertExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DeleteExpr" xlink:type="simple">DeleteExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-RenameExpr" xlink:type="simple">RenameExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ReplaceExpr" xlink:type="simple">ReplaceExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TransformExpr" xlink:type="simple">TransformExpr</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-OrExpr" xlink:type="simple">OrExpr</nt></rhs></prod><prod num="33" id="prod-xquery-FLWORExpr"><lhs>FLWORExpr</lhs><rhs>(<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ForClause" xlink:type="simple">ForClause</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-LetClause" xlink:type="simple">LetClause</nt>)+  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-WhereClause" xlink:type="simple">WhereClause</nt>?  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-OrderByClause" xlink:type="simple">OrderByClause</nt>?  "return"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod><prod num="34" id="prod-xquery-ForClause"><lhs>ForClause</lhs><rhs>"for"  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TypeDeclaration" xlink:type="simple">TypeDeclaration</nt>?  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PositionalVar" xlink:type="simple">PositionalVar</nt>?  "in"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>  (","  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TypeDeclaration" xlink:type="simple">TypeDeclaration</nt>?  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PositionalVar" xlink:type="simple">PositionalVar</nt>?  "in"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>)*</rhs></prod><prod num="35" id="prod-xquery-PositionalVar"><lhs>PositionalVar</lhs><rhs>"at"  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt></rhs></prod><prod num="36" id="prod-xquery-LetClause"><lhs>LetClause</lhs><rhs>"let"  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TypeDeclaration" xlink:type="simple">TypeDeclaration</nt>?  ":="  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>  (","  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TypeDeclaration" xlink:type="simple">TypeDeclaration</nt>?  ":="  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>)*</rhs></prod><prod num="37" id="prod-xquery-WhereClause"><lhs>WhereClause</lhs><rhs>"where"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod><prod num="38" id="prod-xquery-OrderByClause"><lhs>OrderByClause</lhs><rhs>(("order"  "by")  |  ("stable"  "order"  "by"))  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-OrderSpecList" xlink:type="simple">OrderSpecList</nt></rhs></prod><prod num="39" id="prod-xquery-OrderSpecList"><lhs>OrderSpecList</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-OrderSpec" xlink:type="simple">OrderSpec</nt>  (","  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-OrderSpec" xlink:type="simple">OrderSpec</nt>)*</rhs></prod><prod num="40" id="prod-xquery-OrderSpec"><lhs>OrderSpec</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-OrderModifier" xlink:type="simple">OrderModifier</nt></rhs></prod><prod num="41" id="prod-xquery-OrderModifier"><lhs>OrderModifier</lhs><rhs>("ascending"  |  "descending")?  ("empty"  ("greatest"  |  "least"))?  ("collation"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-URILiteral" xlink:type="simple">URILiteral</nt>)?</rhs></prod><prod num="42" id="prod-xquery-QuantifiedExpr"><lhs>QuantifiedExpr</lhs><rhs>("some"  |  "every")  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TypeDeclaration" xlink:type="simple">TypeDeclaration</nt>?  "in"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>  (","  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TypeDeclaration" xlink:type="simple">TypeDeclaration</nt>?  "in"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>)*  "satisfies"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod><prod num="43" id="prod-xquery-TypeswitchExpr"><lhs>TypeswitchExpr</lhs><rhs>"typeswitch"  "("  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  ")"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CaseClause" xlink:type="simple">CaseClause</nt>+  "default"  ("$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt>)?  "return"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod><prod num="44" id="prod-xquery-CaseClause"><lhs>CaseClause</lhs><rhs>"case"  ("$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt>  "as")?  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SequenceType" xlink:type="simple">SequenceType</nt>  "return"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod><prod num="45" id="prod-xquery-IfExpr"><lhs>IfExpr</lhs><rhs>"if"  "("  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  ")"  "then"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>  "else"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod><prod num="46" id="prod-xquery-OrExpr"><lhs>OrExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AndExpr" xlink:type="simple">AndExpr</nt> ( "or"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AndExpr" xlink:type="simple">AndExpr</nt> )*</rhs></prod><prod num="47" id="prod-xquery-AndExpr"><lhs>AndExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ComparisonExpr" xlink:type="simple">ComparisonExpr</nt> ( "and"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ComparisonExpr" xlink:type="simple">ComparisonExpr</nt> )*</rhs></prod><prod num="48" id="prod-xquery-ComparisonExpr"><lhs>ComparisonExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-RangeExpr" xlink:type="simple">RangeExpr</nt> ( (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ValueComp" xlink:type="simple">ValueComp</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-GeneralComp" xlink:type="simple">GeneralComp</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NodeComp" xlink:type="simple">NodeComp</nt>)  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-RangeExpr" xlink:type="simple">RangeExpr</nt> )?</rhs></prod><prod num="49" id="prod-xquery-RangeExpr"><lhs>RangeExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AdditiveExpr" xlink:type="simple">AdditiveExpr</nt> ( "to"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AdditiveExpr" xlink:type="simple">AdditiveExpr</nt> )?</rhs></prod><prod num="50" id="prod-xquery-AdditiveExpr"><lhs>AdditiveExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-MultiplicativeExpr" xlink:type="simple">MultiplicativeExpr</nt> ( ("+"  |  "-")  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-MultiplicativeExpr" xlink:type="simple">MultiplicativeExpr</nt> )*</rhs></prod><prod num="51" id="prod-xquery-MultiplicativeExpr"><lhs>MultiplicativeExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-UnionExpr" xlink:type="simple">UnionExpr</nt> ( ("*"  |  "div"  |  "idiv"  |  "mod")  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-UnionExpr" xlink:type="simple">UnionExpr</nt> )*</rhs></prod><prod num="52" id="prod-xquery-UnionExpr"><lhs>UnionExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-IntersectExceptExpr" xlink:type="simple">IntersectExceptExpr</nt> ( ("union"  |  "|")  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-IntersectExceptExpr" xlink:type="simple">IntersectExceptExpr</nt> )*</rhs></prod><prod num="53" id="prod-xquery-IntersectExceptExpr"><lhs>IntersectExceptExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-InstanceofExpr" xlink:type="simple">InstanceofExpr</nt> ( ("intersect"  |  "except")  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-InstanceofExpr" xlink:type="simple">InstanceofExpr</nt> )*</rhs></prod><prod num="54" id="prod-xquery-InstanceofExpr"><lhs>InstanceofExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TreatExpr" xlink:type="simple">TreatExpr</nt> ( "instance"  "of"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SequenceType" xlink:type="simple">SequenceType</nt> )?</rhs></prod><prod num="55" id="prod-xquery-TreatExpr"><lhs>TreatExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CastableExpr" xlink:type="simple">CastableExpr</nt> ( "treat"  "as"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SequenceType" xlink:type="simple">SequenceType</nt> )?</rhs></prod><prod num="56" id="prod-xquery-CastableExpr"><lhs>CastableExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CastExpr" xlink:type="simple">CastExpr</nt> ( "castable"  "as"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SingleType" xlink:type="simple">SingleType</nt> )?</rhs></prod><prod num="57" id="prod-xquery-CastExpr"><lhs>CastExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-UnaryExpr" xlink:type="simple">UnaryExpr</nt> ( "cast"  "as"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SingleType" xlink:type="simple">SingleType</nt> )?</rhs></prod><prod num="58" id="prod-xquery-UnaryExpr"><lhs>UnaryExpr</lhs><rhs>("-"  |  "+")* <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ValueExpr" xlink:type="simple">ValueExpr</nt></rhs></prod><prod num="59" id="prod-xquery-ValueExpr"><lhs>ValueExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ValidateExpr" xlink:type="simple">ValidateExpr</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PathExpr" xlink:type="simple">PathExpr</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExtensionExpr" xlink:type="simple">ExtensionExpr</nt></rhs></prod><prod num="60" id="prod-xquery-GeneralComp"><lhs>GeneralComp</lhs><rhs>"="  |  "!="  |  "&lt;"  |  "&lt;="  |  "&gt;"  |  "&gt;="</rhs></prod><prod num="61" id="prod-xquery-ValueComp"><lhs>ValueComp</lhs><rhs>"eq"  |  "ne"  |  "lt"  |  "le"  |  "gt"  |  "ge"</rhs></prod><prod num="62" id="prod-xquery-NodeComp"><lhs>NodeComp</lhs><rhs>"is"  |  "&lt;&lt;"  |  "&gt;&gt;"</rhs></prod><prod num="63" id="prod-xquery-ValidateExpr"><lhs>ValidateExpr</lhs><rhs>"validate"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ValidationMode" xlink:type="simple">ValidationMode</nt>?  "{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  "}"</rhs></prod><prod num="64" id="prod-xquery-ValidationMode"><lhs>ValidationMode</lhs><rhs>"lax"  |  "strict"</rhs></prod><prod num="65" id="prod-xquery-ExtensionExpr"><lhs>ExtensionExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Pragma" xlink:type="simple">Pragma</nt>+  "{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>?  "}"</rhs></prod><prod num="66" id="prod-xquery-Pragma"><lhs>Pragma</lhs><rhs>"(#"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-S" xlink:type="simple">S</nt>?  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-S" xlink:type="simple">S</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PragmaContents" xlink:type="simple">PragmaContents</nt>)?  "#)"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="67" id="prod-xquery-PragmaContents"><lhs>PragmaContents</lhs><rhs>(<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Char" xlink:type="simple">Char</nt>* - (Char* '#)' Char*))</rhs></prod><prod num="68" id="prod-xquery-PathExpr"><lhs>PathExpr</lhs><rhs>("/"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-RelativePathExpr" xlink:type="simple">RelativePathExpr</nt>?)<br/>|  ("//"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-RelativePathExpr" xlink:type="simple">RelativePathExpr</nt>)<br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-RelativePathExpr" xlink:type="simple">RelativePathExpr</nt></rhs><com><phrase><xspecref ref="parse-note-leading-lone-slash" spec="XQ">gn: leading-lone-slash</xspecref></phrase></com></prod><prod num="69" id="prod-xquery-RelativePathExpr"><lhs>RelativePathExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-StepExpr" xlink:type="simple">StepExpr</nt>  (("/"  |  "//")  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-StepExpr" xlink:type="simple">StepExpr</nt>)*</rhs></prod><prod num="70" id="prod-xquery-StepExpr"><lhs>StepExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-FilterExpr" xlink:type="simple">FilterExpr</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AxisStep" xlink:type="simple">AxisStep</nt></rhs></prod><prod num="71" id="prod-xquery-AxisStep"><lhs>AxisStep</lhs><rhs>(<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ReverseStep" xlink:type="simple">ReverseStep</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ForwardStep" xlink:type="simple">ForwardStep</nt>)  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PredicateList" xlink:type="simple">PredicateList</nt></rhs></prod><prod num="72" id="prod-xquery-ForwardStep"><lhs>ForwardStep</lhs><rhs>(<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ForwardAxis" xlink:type="simple">ForwardAxis</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NodeTest" xlink:type="simple">NodeTest</nt>)  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AbbrevForwardStep" xlink:type="simple">AbbrevForwardStep</nt></rhs></prod><prod num="73" id="prod-xquery-ForwardAxis"><lhs>ForwardAxis</lhs><rhs>("child"  "::")<br/>|  ("descendant"  "::")<br/>|  ("attribute"  "::")<br/>|  ("self"  "::")<br/>|  ("descendant-or-self"  "::")<br/>|  ("following-sibling"  "::")<br/>|  ("following"  "::")</rhs></prod><prod num="74" id="prod-xquery-AbbrevForwardStep"><lhs>AbbrevForwardStep</lhs><rhs>"@"?  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NodeTest" xlink:type="simple">NodeTest</nt></rhs></prod><prod num="75" id="prod-xquery-ReverseStep"><lhs>ReverseStep</lhs><rhs>(<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ReverseAxis" xlink:type="simple">ReverseAxis</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NodeTest" xlink:type="simple">NodeTest</nt>)  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AbbrevReverseStep" xlink:type="simple">AbbrevReverseStep</nt></rhs></prod><prod num="76" id="prod-xquery-ReverseAxis"><lhs>ReverseAxis</lhs><rhs>("parent"  "::")<br/>|  ("ancestor"  "::")<br/>|  ("preceding-sibling"  "::")<br/>|  ("preceding"  "::")<br/>|  ("ancestor-or-self"  "::")</rhs></prod><prod num="77" id="prod-xquery-AbbrevReverseStep"><lhs>AbbrevReverseStep</lhs><rhs>".."</rhs></prod><prod num="78" id="prod-xquery-NodeTest"><lhs>NodeTest</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-KindTest" xlink:type="simple">KindTest</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NameTest" xlink:type="simple">NameTest</nt></rhs></prod><prod num="79" id="prod-xquery-NameTest"><lhs>NameTest</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Wildcard" xlink:type="simple">Wildcard</nt></rhs></prod><prod num="80" id="prod-xquery-Wildcard"><lhs>Wildcard</lhs><rhs>"*"<br/>|  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NCName" xlink:type="simple">NCName</nt>  ":"  "*")<br/>|  ("*"  ":"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NCName" xlink:type="simple">NCName</nt>)</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="81" id="prod-xquery-FilterExpr"><lhs>FilterExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PrimaryExpr" xlink:type="simple">PrimaryExpr</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PredicateList" xlink:type="simple">PredicateList</nt></rhs></prod><prod num="82" id="prod-xquery-PredicateList"><lhs>PredicateList</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Predicate" xlink:type="simple">Predicate</nt>*</rhs></prod><prod num="83" id="prod-xquery-Predicate"><lhs>Predicate</lhs><rhs>"["  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  "]"</rhs></prod><prod num="84" id="prod-xquery-PrimaryExpr"><lhs>PrimaryExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Literal" xlink:type="simple">Literal</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarRef" xlink:type="simple">VarRef</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ParenthesizedExpr" xlink:type="simple">ParenthesizedExpr</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ContextItemExpr" xlink:type="simple">ContextItemExpr</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-FunctionCall" xlink:type="simple">FunctionCall</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-OrderedExpr" xlink:type="simple">OrderedExpr</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-UnorderedExpr" xlink:type="simple">UnorderedExpr</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Constructor" xlink:type="simple">Constructor</nt></rhs></prod><prod num="85" id="prod-xquery-Literal"><lhs>Literal</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NumericLiteral" xlink:type="simple">NumericLiteral</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-StringLiteral" xlink:type="simple">StringLiteral</nt></rhs></prod><prod num="86" id="prod-xquery-NumericLiteral"><lhs>NumericLiteral</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-IntegerLiteral" xlink:type="simple">IntegerLiteral</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DecimalLiteral" xlink:type="simple">DecimalLiteral</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DoubleLiteral" xlink:type="simple">DoubleLiteral</nt></rhs></prod><prod num="87" id="prod-xquery-VarRef"><lhs>VarRef</lhs><rhs>"$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt></rhs></prod><prod num="88" id="prod-xquery-VarName"><lhs>VarName</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt></rhs></prod><prod num="89" id="prod-xquery-ParenthesizedExpr"><lhs>ParenthesizedExpr</lhs><rhs>"("  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>?  ")"</rhs></prod><prod num="90" id="prod-xquery-ContextItemExpr"><lhs>ContextItemExpr</lhs><rhs>"."</rhs></prod><prod num="91" id="prod-xquery-OrderedExpr"><lhs>OrderedExpr</lhs><rhs>"ordered"  "{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  "}"</rhs></prod><prod num="92" id="prod-xquery-UnorderedExpr"><lhs>UnorderedExpr</lhs><rhs>"unordered"  "{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  "}"</rhs></prod><prod num="93" id="prod-xquery-FunctionCall"><lhs>FunctionCall</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  "("  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>  (","  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>)*)?  ")"</rhs><com><phrase><xspecref ref="parse-note-reserved-function-names" spec="XQ">gn: reserved-function-names</xspecref></phrase></com><com><phrase><xspecref ref="parse-note-parens" spec="XQ">gn: parens</xspecref></phrase></com></prod><prod num="94" id="prod-xquery-Constructor"><lhs>Constructor</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DirectConstructor" xlink:type="simple">DirectConstructor</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ComputedConstructor" xlink:type="simple">ComputedConstructor</nt></rhs></prod><prod num="95" id="prod-xquery-DirectConstructor"><lhs>DirectConstructor</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DirElemConstructor" xlink:type="simple">DirElemConstructor</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DirCommentConstructor" xlink:type="simple">DirCommentConstructor</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DirPIConstructor" xlink:type="simple">DirPIConstructor</nt></rhs></prod><prod num="96" id="prod-xquery-DirElemConstructor"><lhs>DirElemConstructor</lhs><rhs>"&lt;"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DirAttributeList" xlink:type="simple">DirAttributeList</nt>  ("/&gt;"  |  ("&gt;"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DirElemContent" xlink:type="simple">DirElemContent</nt>*  "&lt;/"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-S" xlink:type="simple">S</nt>?  "&gt;"))</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="97" id="prod-xquery-DirAttributeList"><lhs>DirAttributeList</lhs><rhs>(<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-S" xlink:type="simple">S</nt>  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-S" xlink:type="simple">S</nt>?  "="  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-S" xlink:type="simple">S</nt>?  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DirAttributeValue" xlink:type="simple">DirAttributeValue</nt>)?)*</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="98" id="prod-xquery-DirAttributeValue"><lhs>DirAttributeValue</lhs><rhs>('"'  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-EscapeQuot" xlink:type="simple">EscapeQuot</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QuotAttrValueContent" xlink:type="simple">QuotAttrValueContent</nt>)*  '"')<br/>|  ("'"  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-EscapeApos" xlink:type="simple">EscapeApos</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AposAttrValueContent" xlink:type="simple">AposAttrValueContent</nt>)*  "'")</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="99" id="prod-xquery-QuotAttrValueContent"><lhs>QuotAttrValueContent</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QuotAttrContentChar" xlink:type="simple">QuotAttrContentChar</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CommonContent" xlink:type="simple">CommonContent</nt></rhs></prod><prod num="100" id="prod-xquery-AposAttrValueContent"><lhs>AposAttrValueContent</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AposAttrContentChar" xlink:type="simple">AposAttrContentChar</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CommonContent" xlink:type="simple">CommonContent</nt></rhs></prod><prod num="101" id="prod-xquery-DirElemContent"><lhs>DirElemContent</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DirectConstructor" xlink:type="simple">DirectConstructor</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CDataSection" xlink:type="simple">CDataSection</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CommonContent" xlink:type="simple">CommonContent</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ElementContentChar" xlink:type="simple">ElementContentChar</nt></rhs></prod><prod num="102" id="prod-xquery-CommonContent"><lhs>CommonContent</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PredefinedEntityRef" xlink:type="simple">PredefinedEntityRef</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CharRef" xlink:type="simple">CharRef</nt>  |  "{{"  |  "}}"  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-EnclosedExpr" xlink:type="simple">EnclosedExpr</nt></rhs></prod><prod num="103" id="prod-xquery-DirCommentConstructor"><lhs>DirCommentConstructor</lhs><rhs>"&lt;!--"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DirCommentContents" xlink:type="simple">DirCommentContents</nt>  "--&gt;"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="104" id="prod-xquery-DirCommentContents"><lhs>DirCommentContents</lhs><rhs>((<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Char" xlink:type="simple">Char</nt> - '-')  |  ('-'  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Char" xlink:type="simple">Char</nt> - '-')))*</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="105" id="prod-xquery-DirPIConstructor"><lhs>DirPIConstructor</lhs><rhs>"&lt;?"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PITarget" xlink:type="simple">PITarget</nt>  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-S" xlink:type="simple">S</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DirPIContents" xlink:type="simple">DirPIContents</nt>)?  "?&gt;"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="106" id="prod-xquery-DirPIContents"><lhs>DirPIContents</lhs><rhs>(<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Char" xlink:type="simple">Char</nt>* - (Char* '?&gt;' Char*))</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="107" id="prod-xquery-CDataSection"><lhs>CDataSection</lhs><rhs>"&lt;![CDATA["  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CDataSectionContents" xlink:type="simple">CDataSectionContents</nt>  "]]&gt;"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="108" id="prod-xquery-CDataSectionContents"><lhs>CDataSectionContents</lhs><rhs>(<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Char" xlink:type="simple">Char</nt>* - (Char* ']]&gt;' Char*))</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="109" id="prod-xquery-ComputedConstructor"><lhs>ComputedConstructor</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CompDocConstructor" xlink:type="simple">CompDocConstructor</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CompElemConstructor" xlink:type="simple">CompElemConstructor</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CompAttrConstructor" xlink:type="simple">CompAttrConstructor</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CompTextConstructor" xlink:type="simple">CompTextConstructor</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CompCommentConstructor" xlink:type="simple">CompCommentConstructor</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CompPIConstructor" xlink:type="simple">CompPIConstructor</nt></rhs></prod><prod num="110" id="prod-xquery-CompDocConstructor"><lhs>CompDocConstructor</lhs><rhs>"document"  "{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  "}"</rhs></prod><prod num="111" id="prod-xquery-CompElemConstructor"><lhs>CompElemConstructor</lhs><rhs>"element"  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  |  ("{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  "}"))  "{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ContentExpr" xlink:type="simple">ContentExpr</nt>?  "}"</rhs></prod><prod num="112" id="prod-xquery-ContentExpr"><lhs>ContentExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt></rhs></prod><prod num="113" id="prod-xquery-CompAttrConstructor"><lhs>CompAttrConstructor</lhs><rhs>"attribute"  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt>  |  ("{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  "}"))  "{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>?  "}"</rhs></prod><prod num="114" id="prod-xquery-CompTextConstructor"><lhs>CompTextConstructor</lhs><rhs>"text"  "{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  "}"</rhs></prod><prod num="115" id="prod-xquery-CompCommentConstructor"><lhs>CompCommentConstructor</lhs><rhs>"comment"  "{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  "}"</rhs></prod><prod num="116" id="prod-xquery-CompPIConstructor"><lhs>CompPIConstructor</lhs><rhs>"processing-instruction"  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NCName" xlink:type="simple">NCName</nt>  |  ("{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>  "}"))  "{"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Expr" xlink:type="simple">Expr</nt>?  "}"</rhs></prod><prod num="117" id="prod-xquery-SingleType"><lhs>SingleType</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AtomicType" xlink:type="simple">AtomicType</nt>  "?"?</rhs></prod><prod num="118" id="prod-xquery-TypeDeclaration"><lhs>TypeDeclaration</lhs><rhs>"as"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SequenceType" xlink:type="simple">SequenceType</nt></rhs></prod><prod num="119" id="prod-xquery-SequenceType"><lhs>SequenceType</lhs><rhs>("empty-sequence"  "("  ")")<br/>|  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ItemType" xlink:type="simple">ItemType</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-OccurrenceIndicator" xlink:type="simple">OccurrenceIndicator</nt>?)</rhs></prod><prod num="120" id="prod-xquery-OccurrenceIndicator"><lhs>OccurrenceIndicator</lhs><rhs>"?"  |  "*"  |  "+"</rhs><com><phrase><xspecref ref="parse-note-occurrence-indicators" spec="XQ">gn: occurrence-indicators</xspecref></phrase></com></prod><prod num="121" id="prod-xquery-ItemType"><lhs>ItemType</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-KindTest" xlink:type="simple">KindTest</nt>  |  ("item"  "("  ")")  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AtomicType" xlink:type="simple">AtomicType</nt></rhs></prod><prod num="122" id="prod-xquery-AtomicType"><lhs>AtomicType</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt></rhs></prod><prod num="123" id="prod-xquery-KindTest"><lhs>KindTest</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-DocumentTest" xlink:type="simple">DocumentTest</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ElementTest" xlink:type="simple">ElementTest</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AttributeTest" xlink:type="simple">AttributeTest</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SchemaElementTest" xlink:type="simple">SchemaElementTest</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SchemaAttributeTest" xlink:type="simple">SchemaAttributeTest</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PITest" xlink:type="simple">PITest</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CommentTest" xlink:type="simple">CommentTest</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TextTest" xlink:type="simple">TextTest</nt><br/>|  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AnyKindTest" xlink:type="simple">AnyKindTest</nt></rhs></prod><prod num="124" id="prod-xquery-AnyKindTest"><lhs>AnyKindTest</lhs><rhs>"node"  "("  ")"</rhs></prod><prod num="125" id="prod-xquery-DocumentTest"><lhs>DocumentTest</lhs><rhs>"document-node"  "("  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ElementTest" xlink:type="simple">ElementTest</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SchemaElementTest" xlink:type="simple">SchemaElementTest</nt>)?  ")"</rhs></prod><prod num="126" id="prod-xquery-TextTest"><lhs>TextTest</lhs><rhs>"text"  "("  ")"</rhs></prod><prod num="127" id="prod-xquery-CommentTest"><lhs>CommentTest</lhs><rhs>"comment"  "("  ")"</rhs></prod><prod num="128" id="prod-xquery-PITest"><lhs>PITest</lhs><rhs>"processing-instruction"  "("  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NCName" xlink:type="simple">NCName</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-StringLiteral" xlink:type="simple">StringLiteral</nt>)?  ")"</rhs></prod><prod num="129" id="prod-xquery-AttributeTest"><lhs>AttributeTest</lhs><rhs>"attribute"  "("  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AttribNameOrWildcard" xlink:type="simple">AttribNameOrWildcard</nt>  (","  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TypeName" xlink:type="simple">TypeName</nt>)?)?  ")"</rhs></prod><prod num="130" id="prod-xquery-AttribNameOrWildcard"><lhs>AttribNameOrWildcard</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AttributeName" xlink:type="simple">AttributeName</nt>  |  "*"</rhs></prod><prod num="131" id="prod-xquery-SchemaAttributeTest"><lhs>SchemaAttributeTest</lhs><rhs>"schema-attribute"  "("  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AttributeDeclaration" xlink:type="simple">AttributeDeclaration</nt>  ")"</rhs></prod><prod num="132" id="prod-xquery-AttributeDeclaration"><lhs>AttributeDeclaration</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-AttributeName" xlink:type="simple">AttributeName</nt></rhs></prod><prod num="133" id="prod-xquery-ElementTest"><lhs>ElementTest</lhs><rhs>"element"  "("  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ElementNameOrWildcard" xlink:type="simple">ElementNameOrWildcard</nt>  (","  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TypeName" xlink:type="simple">TypeName</nt>  "?"?)?)?  ")"</rhs></prod><prod num="134" id="prod-xquery-ElementNameOrWildcard"><lhs>ElementNameOrWildcard</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ElementName" xlink:type="simple">ElementName</nt>  |  "*"</rhs></prod><prod num="135" id="prod-xquery-SchemaElementTest"><lhs>SchemaElementTest</lhs><rhs>"schema-element"  "("  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ElementDeclaration" xlink:type="simple">ElementDeclaration</nt>  ")"</rhs></prod><prod num="136" id="prod-xquery-ElementDeclaration"><lhs>ElementDeclaration</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ElementName" xlink:type="simple">ElementName</nt></rhs></prod><prod num="137" id="prod-xquery-AttributeName"><lhs>AttributeName</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt></rhs></prod><prod num="138" id="prod-xquery-ElementName"><lhs>ElementName</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt></rhs></prod><prod num="139" id="prod-xquery-TypeName"><lhs>TypeName</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-QName" xlink:type="simple">QName</nt></rhs></prod><prod num="140" id="prod-xquery-URILiteral"><lhs>URILiteral</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-StringLiteral" xlink:type="simple">StringLiteral</nt></rhs></prod><prod num="141" id="prod-xquery-RevalidationDecl"><lhs>RevalidationDecl</lhs><rhs>"declare"  "revalidation"  ("strict"  |  "lax"  |  "skip")</rhs></prod><prod num="142" id="prod-xquery-InsertExprTargetChoice"><lhs>InsertExprTargetChoice</lhs><rhs>(("as"  ("first"  |  "last"))?  "into")<br/>|  "after"<br/>|  "before"</rhs></prod><prod num="143" id="prod-xquery-InsertExpr"><lhs>InsertExpr</lhs><rhs>"insert"  ("node"  |  "nodes")  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-SourceExpr" xlink:type="simple">SourceExpr</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-InsertExprTargetChoice" xlink:type="simple">InsertExprTargetChoice</nt>  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TargetExpr" xlink:type="simple">TargetExpr</nt></rhs></prod><prod num="144" id="prod-xquery-DeleteExpr"><lhs>DeleteExpr</lhs><rhs>"delete"  ("node"  |  "nodes")  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TargetExpr" xlink:type="simple">TargetExpr</nt></rhs></prod><prod num="145" id="prod-xquery-ReplaceExpr"><lhs>ReplaceExpr</lhs><rhs>"replace"  ("value"  "of")?  "node"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TargetExpr" xlink:type="simple">TargetExpr</nt>  "with"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod><prod num="146" id="prod-xquery-RenameExpr"><lhs>RenameExpr</lhs><rhs>"rename"  "node"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-TargetExpr" xlink:type="simple">TargetExpr</nt>  "as"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-NewNameExpr" xlink:type="simple">NewNameExpr</nt></rhs></prod><prod num="147" id="prod-xquery-SourceExpr"><lhs>SourceExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod><prod num="148" id="prod-xquery-TargetExpr"><lhs>TargetExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod><prod num="149" id="prod-xquery-NewNameExpr"><lhs>NewNameExpr</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod><prod num="150" id="prod-xquery-TransformExpr"><lhs>TransformExpr</lhs><rhs>"copy"  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt>  ":="  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>  (","  "$"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-VarName" xlink:type="simple">VarName</nt>  ":="  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>)*  "modify"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt>  "return"  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-ExprSingle" xlink:type="simple">ExprSingle</nt></rhs></prod>
</scrap>

<div2 id="id-terminal-symbols"><head>Terminal Symbols</head><scrap headstyle="show">
		    
		  <head/><prod num="151" id="prod-xquery-IntegerLiteral"><lhs>IntegerLiteral</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Digits" xlink:type="simple">Digits</nt></rhs></prod><prod num="152" id="prod-xquery-DecimalLiteral"><lhs>DecimalLiteral</lhs><rhs>("."  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Digits" xlink:type="simple">Digits</nt>)  |  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Digits" xlink:type="simple">Digits</nt>  "."  [0-9]*)</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="153" id="prod-xquery-DoubleLiteral"><lhs>DoubleLiteral</lhs><rhs>(("."  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Digits" xlink:type="simple">Digits</nt>)  |  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Digits" xlink:type="simple">Digits</nt>  ("."  [0-9]*)?))  [eE]  [+-]?  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Digits" xlink:type="simple">Digits</nt></rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="154" id="prod-xquery-StringLiteral"><lhs>StringLiteral</lhs><rhs>('"'  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PredefinedEntityRef" xlink:type="simple">PredefinedEntityRef</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CharRef" xlink:type="simple">CharRef</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-EscapeQuot" xlink:type="simple">EscapeQuot</nt>  |  [^"&amp;])*  '"')  |  ("'"  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-PredefinedEntityRef" xlink:type="simple">PredefinedEntityRef</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CharRef" xlink:type="simple">CharRef</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-EscapeApos" xlink:type="simple">EscapeApos</nt>  |  [^'&amp;])*  "'")</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="155" id="prod-xquery-PredefinedEntityRef"><lhs>PredefinedEntityRef</lhs><rhs>"&amp;"  ("lt"  |  "gt"  |  "amp"  |  "quot"  |  "apos")  ";"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="156" id="prod-xquery-EscapeQuot"><lhs>EscapeQuot</lhs><rhs>'""'</rhs></prod><prod num="157" id="prod-xquery-EscapeApos"><lhs>EscapeApos</lhs><rhs>"''"</rhs></prod><prod num="158" id="prod-xquery-ElementContentChar"><lhs>ElementContentChar</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Char" xlink:type="simple">Char</nt> - [{}&lt;&amp;]</rhs></prod><prod num="159" id="prod-xquery-QuotAttrContentChar"><lhs>QuotAttrContentChar</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Char" xlink:type="simple">Char</nt> - ["{}&lt;&amp;]</rhs></prod><prod num="160" id="prod-xquery-AposAttrContentChar"><lhs>AposAttrContentChar</lhs><rhs><nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Char" xlink:type="simple">Char</nt> - ['{}&lt;&amp;]</rhs></prod><prod num="161" id="prod-xquery-Comment"><lhs>Comment</lhs><rhs>"(:"  (<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-CommentContents" xlink:type="simple">CommentContents</nt>  |  <nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Comment" xlink:type="simple">Comment</nt>)*  ":)"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com><com><phrase><xspecref ref="parse-note-comments" spec="XQ">gn: comments</xspecref></phrase></com></prod><prod num="162" id="prod-xquery-PITarget"><lhs>PITarget</lhs><rhs><xnt xmlns:xlink="http://www.w3.org/1999/xlink" spec="XML" ref="NT-PITarget" xlink:type="simple">[http://www.w3.org/TR/REC-xml#NT-PITarget]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XQ">gn: xml-version</xspecref></phrase></com></prod><prod num="163" id="prod-xquery-CharRef"><lhs>CharRef</lhs><rhs><xnt xmlns:xlink="http://www.w3.org/1999/xlink" spec="XML" ref="NT-CharRef" xlink:type="simple">[http://www.w3.org/TR/REC-xml#NT-CharRef]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XQ">gn: xml-version</xspecref></phrase></com></prod><prod num="164" id="prod-xquery-QName"><lhs>QName</lhs><rhs><xnt xmlns:xlink="http://www.w3.org/1999/xlink" spec="Names" ref="NT-QName" xlink:type="simple">[http://www.w3.org/TR/REC-xml-names/#NT-QName]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XQ">gn: xml-version</xspecref></phrase></com></prod><prod num="165" id="prod-xquery-NCName"><lhs>NCName</lhs><rhs><xnt xmlns:xlink="http://www.w3.org/1999/xlink" spec="Names" ref="NT-NCName" xlink:type="simple">[http://www.w3.org/TR/REC-xml-names/#NT-NCName]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XQ">gn: xml-version</xspecref></phrase></com></prod><prod num="166" id="prod-xquery-S"><lhs>S</lhs><rhs><xnt xmlns:xlink="http://www.w3.org/1999/xlink" spec="XML" ref="NT-S" xlink:type="simple">[http://www.w3.org/TR/REC-xml#NT-S]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XQ">gn: xml-version</xspecref></phrase></com></prod><prod num="167" id="prod-xquery-Char"><lhs>Char</lhs><rhs><xnt xmlns:xlink="http://www.w3.org/1999/xlink" spec="XML" ref="NT-Char" xlink:type="simple">[http://www.w3.org/TR/REC-xml#NT-Char]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XQ">gn: xml-version</xspecref></phrase></com></prod> 
		   
		</scrap>
<p>The following symbols are used only in the definition of
  terminal symbols; they are not terminal symbols in the
  grammar of <specref ref="id-grammar"/>.</p><scrap headstyle="show">
		    
		  <head/><prod num="168" id="prod-xquery-Digits"><lhs>Digits</lhs><rhs>[0-9]+</rhs></prod><prod num="169" id="prod-xquery-CommentContents"><lhs>CommentContents</lhs><rhs>(<nt xmlns:xlink="http://www.w3.org/1999/xlink" def="prod-xquery-Char" xlink:type="simple">Char</nt>+ - (Char* ('(:' | ':)') Char*))</rhs></prod> 
		   
		</scrap>
</div2>

<!--
<div2 id="id-core-update"><head>Core Grammar</head>
		    
     <scrap id="BNF-Grammar" role="non-terminal-structure-expand">
       <head id="BNF-Grammar-prods" >Non-Terminals</head>
       <prodrecap role="BNF-Grammar-prods" ref="BNF-Grammar-prods" at="../xquery-updates/temp/core-grammar.xml"/>
     </scrap>
</div2>
-->

</div1>


<div1 id="id-impl-defs">	
<head>Implementation-Defined Items</head>	


<p>The following items in this specification are implementation-defined:</p><olist><item><p>The revalidation modes that are supported by this implementation.</p></item><item><p>The default revalidation mode for this implementation.</p></item><item><p>Whether the implementation raises dynamic error <errorref code="0020" class="DY"/> if a node is deleted that had no parent before execution of the query began.</p></item><item><p>The mechanism (if any) by which an external function can return an XDM instance and/or a pending update list to the invoking query.</p></item><item><p>The semantics of <code>fn:put()</code>, including the kinds of nodes accepted as operands by this function.</p></item></olist></div1>


<div1 id="References">
<head>References</head>

<div2 id="id-normative-references">
<head>Normative References</head>

<blist>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="update-req" key="XQuery Update Facility Requirements" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">World Wide Web Consortium. 
<emph>XQuery Update Facility Requirements</emph>.
W3C Working Draft, 28 Aug. 2007.
See <loc href="http://www.w3.org/TR/xquery-update-10-requirements/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/xquery-update-10-requirements/</loc>.
</bibl>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" key="XQuery/XPath Data Model (XDM)" id="datamodel" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">World Wide Web Consortium. 
<emph>XQuery 1.0 and XPath 2.0 Data Model (XDM)</emph>. 
W3C Recommendation, 23 January 2007. 
See <loc href="http://www.w3.org/TR/xpath-datamodel/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/xpath-datamodel/</loc>.</bibl>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" key="XQuery 1.0" id="xquery" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">World Wide Web Consortium. 
<emph>XQuery 1.0: An XML Query Language</emph>. 
W3C Recommendation, 23 January 2007. 
See <loc href="http://www.w3.org/TR/xquery/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/xquery/</loc>.</bibl>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" key="XQueryX 1.0" id="xqueryx" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">World Wide Web Consortium. 
<emph>XQueryX, Version 1.0</emph>. 
W3C Recommendation, 23 January 2007.  
See <loc href="http://www.w3.org/TR/xqueryx/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/xqueryx/</loc>.</bibl>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="XQueryFormalSemantics" key="XQuery 1.0 and XPath 2.0 Formal Semantics" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">World Wide Web Consortium. 
<emph>XQuery 1.0 and XPath 2.0 Formal Semantics</emph>. 
W3C Recommendation, 23 Jan. 2007. 
See <loc href="http://www.w3.org/TR/xquery-semantics/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/xquery-semantics/</loc>.</bibl>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="RFC2119" key="RFC 2119" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">S. Bradner. 
<emph>Key Words for use in RFCs to Indicate Requirement Levels.</emph>
IETF RFC 2119. See <loc href="http://rfc.net/rfc2119.html" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.ietf.org/rfc/rfc2119.txt</loc>.</bibl>
</blist>

</div2>

<div2 id="id-non-normative-references">
<head>Non-normative References</head>

<blist>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="ietf-patches" key="XML Patch Operations" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Internet Engineering Task Force. 
<emph>An Extensible Markup Language (XML) 
Patch Operations Framework Utilizing XML Path Language (XPath) Selectors.</emph>. 
See <loc href="http://datatracker.ietf.org/idtracker/draft-ietf-simple-xml-patch-ops/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://datatracker.ietf.org/idtracker/draft-ietf-simple-xml-patch-ops/
</loc>.</bibl>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="update-use-cases" key="XQuery Update Facility 1.0 Use Cases" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">World Wide Web Consortium. 
<emph>XQuery Update Facility Use Cases</emph>. W3C Working Draft, 28 Aug. 2007. 
See <loc href="http://www.w3.org/TR/xquery-update-10-use-cases/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/xquery-update-10-use-cases/</loc>.

</bibl></blist>

</div2>

</div1>


<div1 id="id-errors">	
<head>Error Conditions</head>	


<div2 id="id-new-error-codes"><head>New Error Codes</head><error-list>
<error spec="XU" code="0001" class="ST" type="static">
<p>
It is a static error if an <termref def="dt-updating-expression">updating expression</termref> is used in any position other than one of the following:</p>
<olist><item><p>The topmost expression in the body of a query.</p></item><item><p>The <code>modify</code> clause of a transform expression.</p></item><item><p>The <code>return</code> clause of a FLWOR expression.</p></item><item><p>The <code>return</code> clauses of a typeswitch expression in which every <code>return</code> clause contains an <termref def="dt-updating-expression">updating expression</termref> or a <termref def="dt-vacuous-expression">vacuous expression</termref>.</p></item><item><p>The <code>then</code> and <code>else</code> clauses of a conditional statement in which both the <code>then</code> and <code>else</code> clauses contain either an <termref def="dt-updating-expression">updating expression</termref> or a <termref def="dt-vacuous-expression">vacuous expression</termref>.</p></item><item><p>An operand of a comma expression in which each operand is either an <termref def="dt-updating-expression">updating expression</termref> or a <termref def="dt-vacuous-expression">vacuous expression</termref>.</p></item><item><p>The content of a  parenthesized expression.</p></item><item><p>The body of a function declaration in which the keyword <code>updating</code> is specified.</p></item></olist></error>

<error spec="XU" code="0002" class="ST" type="static">
<p>
It is a static error if a <termref def="dt-simple-expression">simple expression</termref> that is not a <termref def="dt-vacuous-expression">vacuous expression</termref> is used in one of the following positions:</p>
<olist><item><p>The <code>modify</code> clause of a transform expression.</p></item><item><p>The top-level expression in the body of a function declaration in which the keyword <code>updating</code> is specified.</p></item></olist></error><error spec="XU" code="0003" class="ST" type="static">
<p>
It is a static error if a Prolog contains more than one revalidation declaration.</p>
</error><error spec="XU" code="0004" class="TY" type="type">
<p>
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.</p>
</error><error spec="XU" code="0005" class="TY" type="type">
<p>
In an insert expression where <code>into</code>, <code>as first into</code>, or <code>as last into</code> 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.</p>
</error><error spec="XU" code="0006" class="TY" type="type">
<p>
In an insert expression where <code>before</code> or <code>after</code> 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.</p>
</error><error spec="XU" code="0007" class="TY" type="type">
<p>
It is a type  error if the target expression of a delete expression does not return a sequence of zero or more nodes.</p>
</error><error spec="XU" code="0008" class="TY" type="type">
<p>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.</p>
</error><error spec="XU" code="0009" class="DY" type="dynamic">
<p>In a replace expression where <code>value of</code> is not specified, it is a dynamic error if the node returned by the target expression does not have a parent.</p>
</error><error spec="XU" code="0010" class="TY" type="type">
<p>In a replace expression where <code>value of</code> 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.</p>
</error><error spec="XU" code="0011" class="TY" type="type">
<p>In a replace expression where <code>value of</code> 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.</p>
</error><error spec="XU" code="0012" class="TY" type="type">
<p>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.</p>
</error><error spec="XU" code="0013" class="TY" type="type">
<p>In a transform expression, it is a type error if a source expression in the <code>copy</code> clause does not return a single node.</p>
</error><error spec="XU" code="0014" class="DY" type="dynamic">
<p>In a transform expression, it is a dynamic error if the <code>modify</code> clause modifies any node that was not created by the <code>copy</code> clause.</p>
</error><error spec="XU" code="0015" class="DY" type="dynamic">
<p>It is a dynamic error if any node is the target of more than one <code>rename</code> expression within the same query.</p>
</error><error spec="XU" code="0016" class="DY" type="dynamic">
<p>It is a dynamic error if any node is the target of more than one <code>replace</code> expression (without <code>value of</code> being specified) within the same query.</p>
</error><error spec="XU" code="0017" class="DY" type="dynamic">
<p>It is a dynamic error if any node is the target of more than one <code>replace value of</code> expression within the same query.</p>
</error><error spec="XU" code="0018" class="DY" type="dynamic">
<p>It is a dynamic error if a function that was declared to be <code>external</code> but not <code>updating</code> returns a non-empty pending update list.</p>
</error><error spec="XU" code="0019" class="DY" type="dynamic">
<p>It is a dynamic error if a function that was declared to be both <code>external</code> and <code>updating</code> returns a non-empty data model instance.</p>
</error><error spec="XU" code="0020" class="DY" type="dynamic">
<p>An implementation may (but is not required to) raise a dynamic error if a node is deleted that had no parent before the beginning of the current snapshot.</p>
</error><error spec="XU" code="0021" class="DY" type="dynamic">
<p>It is a dynamic error if the <termref def="dt-xdm-instance">XDM instance</termref> that  would result from applying all the updates in a query violates any constraint specified in <bibref ref="datamodel"/>. In this case, none of the updates in the query are made effective.</p>
</error><error spec="XU" code="0022" class="TY" type="type">
<p>It is a type error if an 
insert expression specifies the insertion of an attribute node into a 
document node.</p>
</error><error spec="XU" code="0023" class="DY" type="dynamic">
<p>It is a dynamic error if an insert, replace, or rename expression affects an element node by introducing a new namespace binding that  <termref def="dt-conflict">conflicts</termref> with one of its existing namespace bindings.</p>
</error><error spec="XU" code="0024" class="DY" type="dynamic">
<p>It is a dynamic error if the effect of a set of updating expressions is to introduce <termref def="dt-conflict">conflicting</termref> namespace bindings into an element node.</p>
</error><error spec="XU" code="0025" class="DY" type="dynamic">
<p>(Not currently used.)</p>
</error><error spec="XU" code="0026" class="ST" type="static">
<p>It is a static error if a revalidation declaration in a Prolog specifies a revalidation mode that is not supported by the current implementation.</p>
</error><error spec="XU" code="0027" class="DY" type="dynamic">
<p>It is a dynamic error if the target expression of an insert, replace, or rename expression evaluates to an empty sequence.</p>
</error><error spec="XU" code="0028" class="ST" type="static">
<p>It is a static error if a function declaration specifies both <code>updating</code> and a return type.</p>
</error><error spec="XU" code="0029" class="DY" type="dynamic">
<p>In an insert expression where <code>before</code> or <code>after</code> is specified, it is a dynamic  error if the node returned by the target expression does not have a parent.</p>
</error><error spec="XU" code="0030" class="DY" type="dynamic">
<p>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.</p>
</error><error spec="XU" code="0031" class="DY" type="dynamic">
<p>It is a dynamic error if multiple calls to <code>fn:put</code> in the same snapshot specify the same URI (after resolution of relative URIs).</p>
</error><error spec="FO" code="0001" class="UP" type="dynamic">
<p>It is a dynamic error if the first operand of <code>fn:put</code> is not a node of a supported kind.</p>
</error><error spec="FO" code="0002" class="UP" type="dynamic">
<p>It is a dynamic error if the second operand of <code>fn:put</code> is not a valid lexical representation of the <code>xs:anyURI</code> type.</p>
</error></error-list></div2><div2 id="id-amended-error-codes"><head>Amendments to Existing Error Codes</head><error-list><error spec="XP" code="0005" class="ST" type="static">
<p>During the analysis phase, it is a static error if the static type assigned to a simple expression other than <code>( )</code> or <code>data(( ))</code> is <code>empty-sequence( )</code>.</p>
</error><error spec="XQ" code="0026" class="DY" type="dynamic">
<p>It is a dynamic error if a constructor or replace expression would result in a processing instruction node whose content includes the string "<code>?&gt;</code>".</p>
</error><error spec="XQ" code="0041" class="DY" type="dynamic">
<p>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 <code>xs:NCName</code>.</p>
</error><error spec="XQ" code="0072" class="DY" type="dynamic">
<p>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.</p>
</error><error spec="XQ" code="0074" class="DY" type="dynamic">
<p>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.)</p>
</error></error-list></div2></div1>


<div1 id="id-xquf-xqueryx">
<head>XML Syntax (XQueryX) for XQuery Update Facility 1.0</head>

<p>
<bibref ref="xqueryx"/> defines an XML representation of <bibref ref="xquery"/>. 
<bibref ref="update-req"/> 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 <specref ref="id-grammar"/>. 
This XML representation for XQuery Update Facility 1.0 integrates
with the XML representation for XQuery 1.0.</p>

<p>
The XML Schema specified in this appendix accomplishes its integration by importing
the XML Schema defined for XQueryX in <bibref ref="xqueryx"/>,
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. 
</p>


<div2 id="id-xquf-update-schema">
<head>Schema</head>

<p>
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.</p>

<eg xml:space="preserve">

&lt;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"&gt;

&lt;!-- Initial creation                  2006-08-17: Jim Melton --&gt;
&lt;!-- Added ufRevalidationDecl          2006-08-21: Jim Melton --&gt;
&lt;!-- Overhaul to bring up to date      2007-08-07: Jim Melton --&gt;
&lt;!-- Reconfirmed correctness for CR    2008-02-27: Jim Melton --&gt;

  &lt;xsd:import namespace="http://www.w3.org/2005/XQueryX"
     schemaLocation="http://www.w3.org/2007/xquery-update-10/
xquery-update-10-xqueryx-redef.xsd"/&gt;


  &lt;!-- Add revalidationDecl to alternatives in prolog setters --&gt;
  &lt;xsd:element name="revalidationDecl"
               substitutionGroup="xqx:prologPartOneItem"&gt;
    &lt;xsd:simpleType&gt;
      &lt;xsd:restriction base="xsd:NMTOKEN"&gt;
        &lt;xsd:enumeration value="strict"/&gt;
        &lt;xsd:enumeration value="lax"/&gt;
        &lt;xsd:enumeration value="skip"/&gt;
      &lt;/xsd:restriction&gt;
    &lt;/xsd:simpleType&gt;
  &lt;/xsd:element&gt;


  &lt;!-- Create substitution group for update facility exprs    --&gt;
  &lt;xsd:complexType name="expr"&gt;
    &lt;xsd:complexContent&gt;
      &lt;xsd:extension base="xqx:expr"/&gt;
    &lt;/xsd:complexContent&gt;
  &lt;/xsd:complexType&gt;

  &lt;!-- Make the update facilities subst grp part of expr grp  --&gt;
  &lt;xsd:element name="expr" type="xqxuf:expr" abstract="true"
               substitutionGroup="xqx:expr"/&gt;


  &lt;!-- InsertExpr                                             --&gt;
  &lt;xsd:complexType name="insertExpr"&gt;
    &lt;xsd:complexContent&gt;
      &lt;xsd:extension base="xqxuf:expr"&gt;
        &lt;xsd:sequence&gt;
          &lt;xsd:element name="sourceExpr"
                       type="xqx:exprWrapper"/&gt;
          &lt;xsd:choice&gt;
            &lt;xsd:element name="insertInto"&gt;
              &lt;xsd:complexType&gt;
                &lt;xsd:sequence minOccurs="0" maxOccurs="1"&gt;
                  &lt;xsd:choice&gt;
                    &lt;xsd:element name="insertAsFirst" 
                                 type="xqx:emptyContent"/&gt;
                    &lt;xsd:element name="insertAsLast" 
                                 type="xqx:emptyContent"/&gt;
                  &lt;/xsd:choice&gt;
                &lt;/xsd:sequence&gt;
              &lt;/xsd:complexType&gt;
            &lt;/xsd:element&gt;
            &lt;xsd:element name="insertAfter"
                         type="xqx:emptyContent"/&gt;
            &lt;xsd:element name="insertBefore"
                         type="xqx:emptyContent"/&gt;
          &lt;/xsd:choice&gt;
          &lt;xsd:element name="targetExpr"
                       type="xqx:exprWrapper"/&gt;
        &lt;/xsd:sequence&gt;
      &lt;/xsd:extension&gt;
    &lt;/xsd:complexContent&gt;
  &lt;/xsd:complexType&gt;

  &lt;xsd:element name="insertExpr" type="xqxuf:insertExpr" 
               substitutionGroup="xqxuf:expr"/&gt;


  &lt;!-- DeleteExpr                                             --&gt;
  &lt;xsd:complexType name="deleteExpr"&gt;
    &lt;xsd:complexContent&gt;
      &lt;xsd:extension base="xqxuf:expr"&gt;
        &lt;xsd:sequence&gt;
         &lt;xsd:element name="targetExpr"
                      type="xqx:exprWrapper"/&gt;
        &lt;/xsd:sequence&gt;
      &lt;/xsd:extension&gt;
    &lt;/xsd:complexContent&gt;
  &lt;/xsd:complexType&gt;

  &lt;xsd:element name="deleteExpr" type="xqxuf:deleteExpr" 
               substitutionGroup="xqxuf:expr"/&gt;


  &lt;!-- ReplaceExpr                                            --&gt;
  &lt;xsd:complexType name="replaceExpr"&gt;
    &lt;xsd:complexContent&gt;
      &lt;xsd:extension base="xqxuf:expr"&gt;
        &lt;xsd:sequence&gt;
          &lt;xsd:element name="replaceValue"
                       type="xqx:emptyContent"
                       minOccurs="0" maxOccurs="1"/&gt;
          &lt;xsd:element name="targetExpr"
                       type="xqx:exprWrapper"/&gt;
          &lt;xsd:element name="replacementExpr"
                       type="xqx:exprWrapper"/&gt;
        &lt;/xsd:sequence&gt;
      &lt;/xsd:extension&gt;
    &lt;/xsd:complexContent&gt;
  &lt;/xsd:complexType&gt;

  &lt;xsd:element name="replaceExpr" type="xqxuf:replaceExpr" 
               substitutionGroup="xqxuf:expr"/&gt;


  &lt;!-- RenameExpr                                             --&gt;
  &lt;xsd:complexType name="renameExpr"&gt;
    &lt;xsd:complexContent&gt;
      &lt;xsd:extension base="xqxuf:expr"&gt;
        &lt;xsd:sequence&gt;
          &lt;xsd:element name="targetExpr"
                       type="xqx:exprWrapper"/&gt;
          &lt;xsd:element name="newNameExpr"
                       type="xqx:exprWrapper"/&gt;
        &lt;/xsd:sequence&gt;
      &lt;/xsd:extension&gt;
    &lt;/xsd:complexContent&gt;
  &lt;/xsd:complexType&gt;

  &lt;xsd:element name="renameExpr" type="xqxuf:renameExpr" 
               substitutionGroup="xqxuf:expr"/&gt;


  &lt;!-- TransformExpr                                          --&gt;
  &lt;xsd:complexType name="transformExpr"&gt;
    &lt;xsd:complexContent&gt;
      &lt;xsd:extension base="xqxuf:expr"&gt;
        &lt;xsd:sequence&gt;
          &lt;xsd:element name="transformCopies"&gt;
            &lt;xsd:complexType&gt;
              &lt;xsd:sequence&gt;
                &lt;xsd:element name="transformCopy" minOccurs="1" 
                             maxOccurs="unbounded"&gt;
                  &lt;xsd:complexType&gt;
                    &lt;xsd:sequence&gt;
                      &lt;xsd:element ref="xqx:varRef"/&gt;
                      &lt;xsd:element name="copySource"
                                   type="xqx:exprWrapper"/&gt;
                    &lt;/xsd:sequence&gt;
                  &lt;/xsd:complexType&gt;
                &lt;/xsd:element&gt;
              &lt;/xsd:sequence&gt;
            &lt;/xsd:complexType&gt;
          &lt;/xsd:element&gt;
          &lt;xsd:element name="modifyExpr"
                       type="xqx:exprWrapper"/&gt;
          &lt;xsd:element name="returnExpr"
                       type="xqx:exprWrapper"/&gt;
        &lt;/xsd:sequence&gt;
      &lt;/xsd:extension&gt;
    &lt;/xsd:complexContent&gt;
  &lt;/xsd:complexType&gt;

  &lt;xsd:element name="transformExpr" type="xqxuf:transformExpr" 
               substitutionGroup="xqxuf:expr"/&gt;


&lt;/xsd:schema&gt;



&lt;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"&gt;

&lt;!-- Redefine one or more components of the XQueryX XML Schema --&gt;
&lt;xsd:redefine schemaLocation="http://www.w3.org/2005/XQueryX/xqueryx.xsd"&gt;

&lt;!-- Redefine the functionDecl complex type --&gt;
  &lt;xsd:complexType name="functionDecl"&gt;
    &lt;xsd:complexContent&gt;
      &lt;xsd:extension base="functionDecl"&gt;
        &lt;xsd:attribute name="updatingFunction"
                       type="xsd:boolean" default="false"/&gt;
      &lt;/xsd:extension&gt;
    &lt;/xsd:complexContent&gt;
  &lt;/xsd:complexType&gt;

&lt;/xsd:redefine&gt;

&lt;/xsd:schema&gt;

</eg>

</div2>


<div2 id="id-xquf-update-stylesheet">
<head>Stylesheet</head>

<p>
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 <bibref ref="xqueryx"/>,
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. 
</p>

<eg xml:space="preserve">

&lt;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"&gt;

&lt;!-- Initial creation                  2006-08-17: Jim Melton --&gt;
&lt;!-- Added revalidationDecl            2006-08-21: Jim Melton --&gt;
&lt;!-- Bring up to date with spec        2007-08-07: Jim Melton --&gt;
&lt;!-- Surround updating exprs w/parens  2007-09-13: Jim Melton --&gt;


&lt;xsl:import href="http://www.w3.org/2005/XQueryX/xqueryx.xsl"/&gt;


&lt;!-- revalidationDecl                                         --&gt;
&lt;xsl:template match="xqxuf:revalidationDecl"&gt;
  &lt;xsl:text&gt;declare revalidation &lt;/xsl:text&gt;
  &lt;xsl:apply-templates/&gt;
&lt;/xsl:template&gt;


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


&lt;!-- sourceExpr                                               --&gt;
&lt;xsl:template match="xqxuf:sourceExpr"&gt;
  &lt;xsl:apply-templates/&gt;
&lt;/xsl:template&gt;


&lt;!-- insertInto                                               --&gt;
&lt;xsl:template match="xqxuf:insertInto"&gt;
  &lt;xsl:if test="child::node()"&gt;
    &lt;xsl:text&gt;as &lt;/xsl:text&gt;
  &lt;/xsl:if&gt;
  &lt;xsl:apply-templates/&gt;
  &lt;xsl:text&gt;into &lt;/xsl:text&gt;
&lt;/xsl:template&gt;


&lt;!-- insertAsFirst                                            --&gt;
&lt;xsl:template match="xqxuf:insertAsFirst"&gt;
  &lt;xsl:text&gt;first &lt;/xsl:text&gt;
&lt;/xsl:template&gt;


&lt;!-- insertAsLast                                             --&gt;
&lt;xsl:template match="xqxuf:insertAsLast"&gt;
  &lt;xsl:text&gt;last &lt;/xsl:text&gt;
&lt;/xsl:template&gt;


&lt;!-- insertAfter                                              --&gt;
&lt;xsl:template match="xqxuf:insertAfter"&gt;
  &lt;xsl:text&gt;after &lt;/xsl:text&gt;
&lt;/xsl:template&gt;


&lt;!-- insertBefore                                             --&gt;
&lt;xsl:template match="xqxuf:insertBefore"&gt;
  &lt;xsl:text&gt;before &lt;/xsl:text&gt;
&lt;/xsl:template&gt;


&lt;!-- targetExpr                                               --&gt;
&lt;xsl:template match="xqxuf:targetExpr"&gt;
  &lt;xsl:apply-templates/&gt;
&lt;/xsl:template&gt;


&lt;!-- deleteExpr                                               --&gt;
&lt;xsl:template match="xqxuf:deleteExpr"&gt;
  &lt;xsl:value-of select="$LPAREN"/&gt;
  &lt;xsl:text&gt;delete nodes &lt;/xsl:text&gt;
  &lt;xsl:apply-templates/&gt;
  &lt;xsl:value-of select="$RPAREN"/&gt;
&lt;/xsl:template&gt;


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


&lt;!-- replacementExpr                                          --&gt;
&lt;xsl:template match="xqxuf:replacementExpr"&gt;
  &lt;xsl:apply-templates/&gt;
&lt;/xsl:template&gt;


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


&lt;!-- newNameExpr                                              --&gt;
&lt;xsl:template match="xqxuf:newNameExpr"&gt;
  &lt;xsl:apply-templates/&gt;
&lt;/xsl:template&gt;


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


&lt;!-- Part of transformExpr                                    --&gt;
&lt;xsl:template match="xqxuf:transformCopies"&gt;
  &lt;xsl:call-template name="commaSeparatedList"/&gt;
&lt;/xsl:template&gt;


&lt;!-- Part of transformExpr                                    --&gt;
&lt;xsl:template match="xqxuf:transformCopy"&gt;
  &lt;xsl:apply-templates select="xqx:varRef"/&gt;
  &lt;xsl:text&gt; := &lt;/xsl:text&gt;
  &lt;xsl:apply-templates select="xqxuf:copySource"/&gt;
&lt;/xsl:template&gt;

&lt;!-- Part of transformExpr                                    --&gt;
&lt;xsl:template match="xqxuf:copySource"&gt;
  &lt;xsl:apply-templates/&gt;
&lt;/xsl:template&gt;

&lt;!-- Part of transformExpr                                    --&gt;
&lt;xsl:template match="xqxuf:modifyExpr"&gt;
  &lt;xsl:apply-templates/&gt;
&lt;/xsl:template&gt;


&lt;!-- Part of transformExpr                                    --&gt;
&lt;xsl:template match="xqxuf:returnExpr"&gt;
  &lt;xsl:apply-templates/&gt;
&lt;/xsl:template&gt;


&lt;!-- Over-ride the template for functionDecl in XQueryX.xsd   --&gt;
  &lt;xsl:template match="xqx:functionDecl" priority="100"&gt;
    &lt;xsl:text&gt;declare &lt;/xsl:text&gt;
    &lt;xsl:if test="@xqx:updatingFunction and
                  @xqx:updatingFunction = 'true'"&gt;
      &lt;xsl:text&gt;updating &lt;/xsl:text&gt;
    &lt;/xsl:if&gt;
    &lt;xsl:text&gt;function &lt;/xsl:text&gt;
    &lt;xsl:apply-templates select="xqx:functionName"/&gt;
    &lt;xsl:apply-templates select="xqx:paramList"/&gt;
    &lt;xsl:apply-templates select="xqx:typeDeclaration"/&gt;
    &lt;xsl:apply-templates select="xqx:functionBody"/&gt;
    &lt;xsl:if test="xqx:externalDefinition"&gt;
      &lt;xsl:text&gt; external &lt;/xsl:text&gt;
    &lt;/xsl:if&gt;
  &lt;/xsl:template&gt;


&lt;/xsl:stylesheet&gt;

</eg>

</div2>


<div2 id="id-xquf-update-examples">
<head>Example</head>

<p>
The following example is based on the data and queries in the use cases
in <bibref ref="update-use-cases"/>. 
In this example, we show the English description of the query,
the XQuery Update Facility solution given in <bibref ref="update-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 <specref ref="id-xquf-update-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 <emph>a</emph> 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?
</p>

<p>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 <bibref ref="update-use-cases"/> may be helpful in evaluating
the correctness of the Update Facility XQueryX solution in each example. </p>

<p>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. 
</p>

<p>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. </p>

<p>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.</p>

<p>This example is based on Q6 from <bibref ref="update-use-cases"/>,
use case Parts: "modifying recursive documents":</p>


<div3 id="id-xquery-rep"><head>XQuery Representation</head>

<eg xml:space="preserve">
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

</eg></div3>


<div3 id="id-xqueryx-rep"><head>XQueryX Representation</head>

<eg xml:space="preserve">
&lt;?xml version="1.0"?&gt;
&lt;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"&gt;

  &lt;xqx:versionDecl&gt;
    &lt;xqx:version&gt;1.0&lt;/xqx:version&gt;
  &lt;/xqx:versionDecl&gt;
  &lt;xqx:mainModule&gt;
    &lt;xqx:queryBody&gt;
      &lt;xqx:flworExpr&gt;
        &lt;xqx:forClause&gt;
          &lt;xqx:forClauseItem&gt;
            &lt;xqx:typedVariableBinding&gt;
              &lt;xqx:varName&gt;keyword&lt;/xqx:varName&gt;
            &lt;/xqx:typedVariableBinding&gt;
            &lt;xqx:positionalVariableBinding&gt;i
            &lt;/xqx:positionalVariableBinding&gt;
            &lt;xqx:forExpr&gt;
              &lt;xqx:sequenceExpr&gt;
                &lt;xqx:stringConstantExpr&gt;
                  &lt;xqx:value&gt;car&lt;/xqx:value&gt;
                &lt;/xqx:stringConstantExpr&gt;
                &lt;xqx:stringConstantExpr&gt;
                  &lt;xqx:value&gt;skateboard&lt;/xqx:value&gt;
                &lt;/xqx:stringConstantExpr&gt;
                &lt;xqx:stringConstantExpr&gt;
                  &lt;xqx:value&gt;canoe&lt;/xqx:value&gt;
                &lt;/xqx:stringConstantExpr&gt;
              &lt;/xqx:sequenceExpr&gt;
            &lt;/xqx:forExpr&gt;
          &lt;/xqx:forClauseItem&gt;
          &lt;xqx:forClauseItem&gt;
            &lt;xqx:typedVariableBinding&gt;
              &lt;xqx:varName&gt;parent&lt;/xqx:varName&gt;
            &lt;/xqx:typedVariableBinding&gt;
            &lt;xqx:forExpr&gt;
              &lt;xqx:pathExpr&gt;
                &lt;xqx:stepExpr&gt;
                  &lt;xqx:filterExpr&gt;
                    &lt;xqx:functionCallExpr&gt;
                      &lt;xqx:functionName
                        xqx:prefix="fn"&gt;doc&lt;/xqx:functionName&gt;
                      &lt;xqx:arguments&gt;
                        &lt;xqx:stringConstantExpr&gt;
                          &lt;xqx:value&gt;part-tree.xml&lt;/xqx:value&gt;
                        &lt;/xqx:stringConstantExpr&gt;
                      &lt;/xqx:arguments&gt;
                    &lt;/xqx:functionCallExpr&gt;
                  &lt;/xqx:filterExpr&gt;
                &lt;/xqx:stepExpr&gt;
                &lt;xqx:stepExpr&gt;
                  &lt;xqx:xpathAxis&gt;descendant-or-self&lt;/xqx:xpathAxis&gt;
                  &lt;xqx:nameTest&gt;part&lt;/xqx:nameTest&gt;
                  &lt;xqx:predicates&gt;
                    &lt;xqx:equalOp&gt;
                      &lt;xqx:firstOperand&gt;
                        &lt;xqx:pathExpr&gt;
                          &lt;xqx:stepExpr&gt;
                            &lt;xqx:xpathAxis&gt;attribute&lt;/xqx:xpathAxis&gt;
                            &lt;xqx:nameTest&gt;name&lt;/xqx:nameTest&gt;
                          &lt;/xqx:stepExpr&gt;
                        &lt;/xqx:pathExpr&gt;
                      &lt;/xqx:firstOperand&gt;
                      &lt;xqx:secondOperand&gt;
                        &lt;xqx:varRef&gt;
                          &lt;xqx:name&gt;keyword&lt;/xqx:name&gt;
                        &lt;/xqx:varRef&gt;
                      &lt;/xqx:secondOperand&gt;
                    &lt;/xqx:equalOp&gt;
                  &lt;/xqx:predicates&gt;
                &lt;/xqx:stepExpr&gt;
              &lt;/xqx:pathExpr&gt;
            &lt;/xqx:forExpr&gt;
          &lt;/xqx:forClauseItem&gt;
        &lt;/xqx:forClause&gt;
        &lt;xqx:letClause&gt;
          &lt;xqx:letClauseItem&gt;
            &lt;xqx:typedVariableBinding&gt;
              &lt;xqx:varName&gt;descendants&lt;/xqx:varName&gt;
            &lt;/xqx:typedVariableBinding&gt;
            &lt;xqx:letExpr&gt;
              &lt;xqx:pathExpr&gt;
                &lt;xqx:stepExpr&gt;
                  &lt;xqx:filterExpr&gt;
                    &lt;xqx:varRef&gt;
                      &lt;xqx:name&gt;parent&lt;/xqx:name&gt;
                    &lt;/xqx:varRef&gt;
                  &lt;/xqx:filterExpr&gt;
                &lt;/xqx:stepExpr&gt;
                &lt;xqx:stepExpr&gt;
                  &lt;xqx:xpathAxis&gt;descendant-or-self&lt;/xqx:xpathAxis&gt;
                  &lt;xqx:nameTest&gt;part&lt;/xqx:nameTest&gt;
                &lt;/xqx:stepExpr&gt;
              &lt;/xqx:pathExpr&gt;
            &lt;/xqx:letExpr&gt;
          &lt;/xqx:letClauseItem&gt;
        &lt;/xqx:letClause&gt;
        &lt;xqx:forClause&gt;
          &lt;xqx:forClauseItem&gt;
            &lt;xqx:typedVariableBinding&gt;
              &lt;xqx:varName&gt;p&lt;/xqx:varName&gt;
            &lt;/xqx:typedVariableBinding&gt;
            &lt;xqx:forExpr&gt;
              &lt;xqx:sequenceExpr&gt;
                &lt;xqx:varRef&gt;
                  &lt;xqx:name&gt;parent&lt;/xqx:name&gt;
                &lt;/xqx:varRef&gt;
                &lt;xqx:varRef&gt;
                  &lt;xqx:name&gt;descendants&lt;/xqx:name&gt;
                &lt;/xqx:varRef&gt;
              &lt;/xqx:sequenceExpr&gt;
            &lt;/xqx:forExpr&gt;
          &lt;/xqx:forClauseItem&gt;
        &lt;/xqx:forClause&gt;
        &lt;xqx:returnClause&gt;
          &lt;xqxuf:replaceExpr&gt;
            &lt;xqxuf:replaceValue/&gt;
            &lt;xqxuf:targetExpr&gt;
              &lt;xqx:pathExpr&gt;
                &lt;xqx:stepExpr&gt;
                  &lt;xqx:filterExpr&gt;
                    &lt;xqx:varRef&gt;
                      &lt;xqx:name&gt;p&lt;/xqx:name&gt;
                    &lt;/xqx:varRef&gt;
                  &lt;/xqx:filterExpr&gt;
                &lt;/xqx:stepExpr&gt;
                &lt;xqx:stepExpr&gt;
                  &lt;xqx:xpathAxis&gt;attribute&lt;/xqx:xpathAxis&gt;
                  &lt;xqx:nameTest&gt;partid&lt;/xqx:nameTest&gt;
                &lt;/xqx:stepExpr&gt;
              &lt;/xqx:pathExpr&gt;
            &lt;/xqxuf:targetExpr&gt;
            &lt;xqxuf:replacementExpr&gt;
              &lt;xqx:addOp&gt;
                &lt;xqx:firstOperand&gt;
                  &lt;xqx:multiplyOp&gt;
                    &lt;xqx:firstOperand&gt;
                      &lt;xqx:varRef&gt;
                        &lt;xqx:name&gt;i&lt;/xqx:name&gt;
                      &lt;/xqx:varRef&gt;
                    &lt;/xqx:firstOperand&gt;
                    &lt;xqx:secondOperand&gt;
                      &lt;xqx:integerConstantExpr&gt;
                        &lt;xqx:value&gt;1000&lt;/xqx:value&gt;
                      &lt;/xqx:integerConstantExpr&gt;
                    &lt;/xqx:secondOperand&gt;
                  &lt;/xqx:multiplyOp&gt;
                &lt;/xqx:firstOperand&gt;
                &lt;xqx:secondOperand&gt;
                  &lt;xqx:pathExpr&gt;
                    &lt;xqx:stepExpr&gt;
                      &lt;xqx:filterExpr&gt;
                        &lt;xqx:varRef&gt;
                          &lt;xqx:name&gt;p&lt;/xqx:name&gt;
                        &lt;/xqx:varRef&gt;
                      &lt;/xqx:filterExpr&gt;
                    &lt;/xqx:stepExpr&gt;
                    &lt;xqx:stepExpr&gt;
                      &lt;xqx:xpathAxis&gt;attribute&lt;/xqx:xpathAxis&gt;
                      &lt;xqx:nameTest&gt;partid&lt;/xqx:nameTest&gt;
                    &lt;/xqx:stepExpr&gt;
                  &lt;/xqx:pathExpr&gt;
                &lt;/xqx:secondOperand&gt;
              &lt;/xqx:addOp&gt;
            &lt;/xqxuf:replacementExpr&gt;
          &lt;/xqxuf:replaceExpr&gt;
        &lt;/xqx:returnClause&gt;
      &lt;/xqx:flworExpr&gt;
    &lt;/xqx:queryBody&gt;
  &lt;/xqx:mainModule&gt;
&lt;/xqx:module&gt;

</eg></div3>


<div3 id="id-transformed-rep"><head>Transformed XQuery Representation</head>

<p>Application of the stylesheet in <specref ref="id-xquf-update-stylesheet"/> to the
Update Facility XQueryX representation results in the following XQuery representation:</p>
<eg xml:space="preserve">
 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)
)

</eg></div3>

</div2>

</div1>


<inform-div1 id="id-glossary">
<head>Glossary</head>
<!-- This processing instruction automatically generates the glossary. -->
<?glossary?>
</inform-div1>

<inform-div1 id="id-precedence-rationale">	
<head>Rationale for Precedence of Update Primitives</head>	

<p>In <specref ref="id-upd-apply-updates"/>, semantic rules specify the order in which the <termref def="dt-update-primitive">update primitives</termref> on a <termref def="dt-pending-update-list">pending update list</termref> 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:</p>
<ulist><item><p><code>insertAttribute</code>, <code>replaceValue</code>, and <code>rename</code> primitives do not conflict with any 
other primitives other than <code>put</code>.</p></item><item><p><code>insertInto</code> primitives must be applied before <code>insertIntoAsFirst/Last</code> and 
<code>insertBefore/After</code> 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."</p></item><item><p><code>insertBefore/After</code> primitives must be applied before <code>replaceNode</code> 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.</p></item><item><p><code>insertIntoAsFirst/Last</code> primitives must be applied before <code>replaceElementContent</code> 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   <code>replaceElementContent</code> primitive.</p></item><item><p><code>replaceNode</code> primitives must be applied before <code>replaceElementContent</code> 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.</p></item><item><p><code>replaceNode</code> primitives must be applied before <code>delete</code> primitives. Reason: After a node has been 
deleted, it no longer has a parent. Replacing a node that has no parent is undefined.</p></item><item><p><code>put</code> primitives must be applied after all other primitives in order that documents stored by a snapshot will reflect all update operations applied by the snapshot.</p></item></ulist></inform-div1>


<inform-div1 id="id-revision-log">
  <head>Revision Log</head>

  <p>This log records the substantive changes that have been made to this document since the Candidate Recommendation of 14 March 2008. Minor editorial changes are not included in this log.</p>
  <olist>
    <item>
      <p>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: <specref ref="id-variable-declaration"/>.</p>
    </item><item><p>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: <specref ref="id-rename"/>.</p></item><item><p>When a <code>upd:rename</code> operation is applied to an element node, and the <code>$newname</code> operand is a QName that has neither a namespace prefix nor a namespace URI, part of the semantics of the operation is to remove the namespace binding for the empty prefix (if any) from the element node. Partial resolution of Bug 5629. Section affected: <specref ref="id-upd-rename"/>.</p></item><item><p>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 <code>upd:delete</code> primitive.) Partial resolution of Bug 5632. Sections affected: <specref ref="id-delete"/>, <specref ref="id-upd-delete"/>.</p></item><item><p>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 <code>upd:mergeUpdates</code> and <code>upd:applyUpdates</code>. Checks for err:XUDY0024 are no longer part of the semantics of <code>upd:insertAttributes</code>, <code>upd:replaceNode</code>, or <code>upd:rename</code>. The net effect of these changes is to enable implementations to catch conflicting namespace bindings earlier and to associate them with specific expressions. Dynamic errors are no longer generated by individual update primitives on Pending Update Lists. Partial resolution of Bug 5632. Sections affected: <specref ref="id-insert"/>, <specref ref="id-replace"/>, <specref ref="id-upd-insert-attributes"/><specref ref="id-upd-replacenode"/>, <specref ref="id-upd-rename"/>, <specref ref="id-upd-merge-updates"/>, <specref ref="id-upd-apply-updates"/>.</p></item><item><p>The following changes were made to the semantics of <code>fn:put</code> (resolving Bug 5646):</p><olist><item><p><code>fn:put</code> now generates an update primitive called <code>upd:put</code>, which is held on the pending update list and applied after all other update primitives. Sections: <specref ref="id-func-put"/>, <specref ref="id-upd-put"/>.</p></item><item><p>It is an error to invoke <code>fn:put</code> more than once on the same URI within a snapshot. Sections: <specref ref="id-compatibility"/>, <specref ref="id-upd-merge-updates"/>, <specref ref="id-upd-apply-updates"/>, <specref ref="id-new-error-codes"/>.</p></item><item><p><code>fn:put</code> is classified as an updating function. Section: <specref ref="id-function-declaration"/>.</p></item></olist></item><item><p>Moved the subsection on Function Declarations inside the section on Extensions to the Prolog. Resolves Bug 5701. Section affected: <specref ref="id-function-declaration"/></p></item><item><p>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: <specref ref="id-static-typing-changes"/>, <specref ref="id-amended-error-codes"/>.</p></item>
    
    
  </olist>
</inform-div1>


</back>
</spec>