Zorba

XQueryP

FLWOR Foundation Proposal, Dec. 22, 2006

This version:
http://www.flworfound.org/pubs/2006/WD-xqueryp-20061215/
Latest version:
http://www.flworfound.org/pubs/xqueryp/
Previous version:
Editors:
Don Chamberlin, IBM Almaden Research Center <chamberlin@almaden.ibm.com>
MIchael Carey, BEA Systems <mcarey@bea.com>
Daniela Florescu, Oracle Corporation <dana.florescu@oracle.com>
Donald Kossmann, ETH Zurich <kossmann@inf.ethz.ch>
Paul Pedersen, FLWOR Foundation <pcp071098@yahoo.com>
Jonathan Robie, Data Direct <jonathan.robie@datadirect.com>

Abstract

This document defines an extension of the XML Query language, XQuery 1.0. The XQueryP language provides procedular extension to XQuery that permit the language to be used as an effective Web application programming platform.

Status of this Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current Zorba publications and the latest revision of this technical report can be found in the Zorba technical reports index at http://www.zorba.org/TR/.

This document is designed to be read in conjunction with the following documents:

Table of Contents

1 Introduction
2 Extensions to XQuery 1.0
    2.1 Extensions to the Processing Model
    2.2 Extensions to the Prolog
    2.3 New Kinds of Expressions
        2.3.1 Blocks
        2.3.2 Assignment
        2.3.3 While
        2.3.4 Try-catch
    2.4 Extensions to Existing Expressions
        2.4.1 FLWOR Expression
        2.4.2 Typeswitch Expression
        2.4.3 Conditional Expression
        2.4.4 Comma Expression
        2.4.5 Parenthesized Expression
        2.4.6 Function Declaration
        2.4.7 Function Call
        2.4.8 Other Expressions
    2.5 Extensions to Built-in Function Library
        2.5.1 fn:set
3 Sequential Execution Mode
  

Appendices

A EBNF for XQueryP Grammar
B References
C Error Conditions
D Glossary
E Revision Log


1 Introduction

This document defines the syntax and semantics of XQueryP, an extension to XQuery 1.0. This language extension provides procedural programming facilities intended to make XQueryP into a simple and powerful Web application programming environment.

[Definition: Within this document, the term XQuery refers to the language specified by XQuery 1.0, XQuery 1.0 Update Facility, and XQuery 1.0 and XPath 2.0 Full-Text.]

[Definition: The term data model refers to the data model specified by XQuery 1.0 and XPath 2.0 Data Model (XDM).]

[Definition: The term XDM instance denotes an unconstrained sequence of zero or more nodes and/or atomic values as defined by the data model.]

2 Extensions to XQuery 1.0

An XQuery 1.0 expression takes one or more XDM instances as input and returns an XDM instance as a result. In XQuery 1.0, an expression never modifies the state of an existing node; however, constructor expressions create new nodes with new identities.

The XQuery Update Facility introduces a new category of expression called updating expressions, which can modify the state of an existing node.

The XQuery Full-Text Extension defines a set of expressions and an extended data model (tokenized text), which can be used for full-text and text-structural searches over collections of XML documents.

The goal of the XQueryP proposal is to define the smallest extension to XQuery that makes development of XML applications reasonably feasible.

The extensions to XQuery 1.0 provided by XQueryP may be characterized as follow:

  1. sequential execution mode: an ordering of sub-expression in the XQuery expression tree that determines the ordering of side-effects,
  2. blocks: an expression with explicit sequential ordering,
  3. assignments: dynamic binding of variables to values,
  4. while expressions: the standard procedural control-flow primitive, and
  5. try-catch expressions: exception handling.

2.1 Extensions to the Processing Model

In XQuery, as in SQL, data is passed from one expression to another by physical nesting of expressions. Side effects are saved on "pending update lists" and made effective only as the last step in the query processing. As a result, the side effects of one expression cannot be seen by other expressions. This approach does not scale well to complex applications. Application development would be made easier by the notion od a "state" that could be modified by successive updating expressions. The idea of a state, represented by a set of variables, is a natural extension of XQuery, since the language already has variables that are bound by various kinds of expressions such as for, let, some, and every.

The XQuery Update Facility defines an internal "apply" operation that makes updates visible, and invokes this operation at the root of the expression tree. If the "apply" operation were invoked at earlier stages in query processing, expressions would be able to see the side effects of other expressions. In order to make the result well-defined, it would be necessary to define an ordering on the evaluation of expressions in the expression tree. We propose to define such an ordering and to make it effective by means of a prolog declaration called an execution declaration. In the absence of an execution declaration, the semantics of XQuery are exactly as specified by XQuery 1.0 and the XQuery Update Facility. If an execution declaration is present, the query is said to be in sequential mode, and a sequential ordering is defined on the expression tree. The semantics of updating expressions are changed to invoke the "apply" operation immediately rather than returning a pending update list. In sequential mode, each expression can see the side effects of previous expressions. In sequential mode, the effect of evaluating an expression tree must be the same as though the expressions were evaluated in sequential order. If none of the expressions have side effects, sequential mode is not relevant, and all the optimizations available in XQuery 1.0 still apply. In the presence of side effects, the evaluation order of expressions is effectively constrained by the interdependencies among the expressions, which can be detected by standard data-flow optimization techniques.

2.2 Extensions to the Prolog

[7]    Setter    ::=    BoundarySpaceDecl | DefaultCollationDecl | BaseURIDecl | ConstructionDecl | OrderingModeDecl | EmptyOrderDecl | CopyNamespacesDecl | RevalidationDecl
| ExecutionDecl

[141]    ExecutionDecl    ::=    "declare" "execution" ("sequential" | "default")

The Prolog is extended by adding a new kind of Setter called an execution declaration.

[Definition: The execution declaration sets the execution mode in the static context, overriding any implementation-defined default.]

[Definition: Execution mode, which may be set to sequential or default, is a component of the static context that imposes a sequential ordering on the evaluation of XQuery expressions, including updates.]

The value of execution mode is determined as follows:

  • Default initial value: default.

  • Can be overwritten by an implementation: Yes

  • Scope: Global.

  • Consistency rules: Must be sequential or default.

In sequential mode a sequential ordering is defined on the XQuery expression tree. The semantics of updating expressions are changed to invoke the "apply" operation immediately rather than returning a pending update list. In sequential mode, each expression can see the effects of previous expressions in the same module.

In sequential mode, the effect of evaluating an expression tree must be the same as though the expression were evaluated in sequential order. If none of the sub-expressions have side-effects, then sequential mode is neutral.

The evaluation order of expressions in sequential mode is defined as follows:

2.3 New Kinds of Expressions

[84]    PrimaryExpr    ::=    Literal
| VarRef
| ParenthesizedExpr
| ContextItemExpr
| FunctionCall
| OrderedExpr
| UnorderedExpr
| Constructor
| Block

[32]    ExprSingle    ::=    FLWORExpr
| QuantifiedExpr
| TypeswitchExpr
| IfExpr
| OrExpr
| InsertExpr
| DeleteExpr
| RenameExpr
| ReplaceExpr
| TransformExpr
| AssignExpr | WhileExpr | TryCatchExpr

XQueryP extends the syntax of PrimaryExpr by adding a Block expression. XQueryP extends the syntax of ExprSingle by adding three new types of expression: AssignExpr, WhileExpr and TryCatchExpr. The syntax and semantics of these expressions are described in the following sections.

2.3.1 Block

[401]    Block    ::=    "{" (BlockDecl ";" )* Expr (";" Expr)* "}"
[402]    BlockDecl    ::=    "declare" "$" VarName TypeDeclaration? (":=" ExprSingle)? ("," "$" VarName TypeDeclaration? (":=" ExprSingle)? )*

Example:

  • The following example illustrates usage of a block. The example increases the price of all items in a catalog whose price is less than 100 by ten percent, and returns the updated items. It is often desirable for an expression to both update an element and return it (or some value computed from it), both for efficiency and because it might (as in this case) be impossible to find the updated elements by a subsequent query.
    for $item in /catalog/item[price < 100]
    return
    {do replace value of $item/price with $item/price * 1.1; $item}

A block may contain a mixture of updating and non-updating expressions. In common usage, it is expected that all the expressions in a block, possibly excepting the final one, will be updating expressions. A block is defined to be an updating expression if any of its contained expressions is an updating expression. Inside a block, the syntax and semantics of a declaration are very similar to those of a let-clause in a FLWOR expression. Each declaration names one or more variables and can provide a type and an initializing expression for each variable.

The semantics of a block expression are as follows:

  1. If execution mode is not sequential, a block raises a static error. If execution mode is sequential, the declarations (if any) are processed in order, bringing new variables into scope inside the block.
  2. The expressions are evaluated from left to right, with the side effects of each expression made effective immediately.
  3. The results of all the expressions except the last one are ignored. The result of the last expression is returned as the result of the block.
  4. The individual variable declarations are processed in order from left to right.
  5. For each variable declaration, the initializing expression (if any) must be a non-updating expression, and its type must match the declared type (using the rules for SequenceType matching).
  6. The initializing expression (if any) isevaluated and the resulting value is bound to the declared variable.
  7. The scope of each declared variable is the remainder of the block, including the initializing expressions of subsequent declared variables, but not including its own initializing expression.
  8. Each variable declaration occludes any existing inscope variable with the same name.
  9. If a declaration inside a block does not specify a type for a variable, the implicit type of the variable is xs:anyType.
  10. If a declaration does not specify an initializing expression for a variable, the variable is not bound to a value. Any reference to such a variable (other than on the left-hand-side of an assignment expression, as described in the next section) is a dynamic error.

2.3.2 Assignment

[403]    AssignExpr    ::=    "set" "$" VarName ":=" ExprSingle

Assignment expressions bind variables to values. They allow different parts of a computation to exchange information through side effects rather than by returning values. Like the insert, delete, replace, and rename expressions, theassignment expression is an updating expression that returns an empty sequence.

Example:

  • The following example illustrates the use of a block containing an assignment expression. The example generates a list of project elements in document order, showing the individual cost and cumulative cost of each project in the year 2005.
    { declare $total-cost as xs:decimal := 0;
      for $p in /project[year eq 2005]
      return 
      { set $total-cost := $total-cost + $p/cost; 
        <project> 
          <name>{$p/name}</name>
          <cost>{$p/cost}</cost>
          <cumulative-cost>{$total-cost}</cumulative-cost> 
        </project> 
      }
    }

The semantics of an assignment expression are as follows:

  1. If execution mode is not sequential, a static error is raised.
  2. If execution mode is sequential, the variable named on the lefthand-side of the assignment expression must have been declared in the query prolog or in a containing block, and must not have been overridden by a variable binding in a for-clause, let-clause, typeswitch, or quantified expression.
  3. The expression on the right-hand side of the assignment expression must be a non-updating expression, and its type must match the type of the variable on the left-hand-side, using the rules for SequenceType matching.
  4. The right-hand-side expression is evaluated and the resulting value is bound to the named variable, replacing its existing value (if any).

2.3.3 While Expression

[404]    WhileExpr    ::=    "while" "(" TestExpr ")" "return" BodyExpr
[405]    TestExpr    ::=    ExprSingle
[406]    BodyExpr    ::=    ExprSingle

A FLWOR expression iterates over a predefined set of values. In sequential mode, successive iterations may see a different dynamic context, and there is a need to terminate an iteration based on the dynamic context. This is accomplished by introducing a new iterator called a while expression.

Example:

  • The following example ...
    while ( ... ) return ...

The semantics of a while expression are as follows:

  1. If execution mode is not sequential, a static error is raised.
  2. The test expression must not be an updating expression.
  3. The test expression is evaluated. The following two-step process is then repeated as long as the effective boolean value of the test expression is true:

    • The body expression is evaluated and its side effects are made effective.

    • The test expression is re-evaluated.

  4. The result of a while expression is the concatenation of all the values returned by its body expression, in iteration order.
  5. A while expression is an updating expression if its body expression is an updating expression; otherwise it is a non-updating expression.

2.3.4 Try-catch Expression

[407]    TryCatchExpr    ::=    "try" "(" TryExpr ")" "catch" CatchExpr
[408]    TryExpr    ::=    ExprSingle
[409]    CatchExpr    ::=    ...

.

Example:

  • The following example ...
    try ( ... ) catch ...

The semantics of a try-catch expression are as follows:

  1. .
  2. .

2.4 Extensions to Existing Expressions

XQueryP provides extensions to the semantics of several existing kinds of XQuery expressions, as specified in this section.

2.4.1 FLWOR Expression

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

  1. If ..

The following example .. :

  • Update ..
    for $p in ..

2.4.2 Typeswitch Expression

[43]    TypeswitchExpr    ::=    "typeswitch" "(" Expr ")" CaseClause+ "default" ("$" VarName)? "return" ExprSingle
[44]    CaseClause    ::=    "case" ("$" VarName "as")? SequenceType "return" ExprSingle

The syntax of the typeswitch expression is unchanged. Its semantics are extended as follows (the term "branch" refers to any case or default clause in the typeswitch expression):

  1. If ..

2.4.3 Conditional Expression

The semantics of conditional expressions are extended as follows (the term "branch" refers to the then and else clauses in the conditional expression):

  1. If ..

The following example illustrates .. :

  • If the ..
    if ..

2.4.4 Comma Expression

The semantics of comma expressions (composed of one or more expressions concatenated by the comma operator, as described in Section 3.3.1 of [XQuery 1.0]) are extended as follows:

  1. If ..

The following example illustrates ..

  • This example ..
    let ..

2.4.5 Parenthesized Expression

The semantics of a parenthesized expression (any XQuery expression enclosed in parentheses) are extended as follows:

  1. If ..

The following example illustrates ..

  • This example ..
    let ..

2.4.6 Function Declaration

[26]    FunctionDecl    ::=    "declare" "updating"? "function" QName "(" ParamList? ")" ("as" SequenceType)? (EnclosedExpr | "external")

The syntax of a function declaration is ..

The following example ..

  • This function ..
    declare ..

2.4.7 Function Call

The semantics of a function call are extended as follows:

The function call is evaluated as specified in Section 3.1.5 of [XQuery 1.0]. If any input parameter of the function ..

2.4.8 Other Expressions

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:

..

2.5 Extensions to Built-in Function Library

XQuery Update Facility provides extensions to XQuery built-in function library, as specified in this section.

2.5.1 fn:set

fn:set($node as node())

Summary: Stores a

Implementations may provide user-defined error handling options that allow processing to continue following an error in storing a resource.

3 Sequential Execution Mode

This section describes sequential execution mode.

A EBNF for XQuery 1.0 Grammar with XQueryP extensions

The EBNF in this document and in this section is aligned with the current XML Query 1.0 grammar (see [XQuery 1.0]).

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

A.1 Terminal Symbols

[150]    IntegerLiteral    ::=    Digits
[151]    DecimalLiteral    ::=    ("." Digits) | (Digits "." [0-9]*) /* ws: explicitXQ */
[152]    DoubleLiteral    ::=    (("." Digits) | (Digits ("." [0-9]*)?)) [eE] [+-]? Digits /* ws: explicitXQ */
[153]    StringLiteral    ::=    ('"' (PredefinedEntityRef | CharRef | EscapeQuot | [^"&])* '"') | ("'" (PredefinedEntityRef | CharRef | EscapeApos | [^'&])* "'") /* ws: explicitXQ */
[154]    PredefinedEntityRef    ::=    "&" ("lt" | "gt" | "amp" | "quot" | "apos") ";" /* ws: explicitXQ */
[155]    EscapeQuot    ::=    '""'
[156]    EscapeApos    ::=    "''"
[157]    ElementContentChar    ::=    Char - [{}<&]
[158]    QuotAttrContentChar    ::=    Char - ["{}<&]
[159]    AposAttrContentChar    ::=    Char - ['{}<&]
[160]    Comment    ::=    "(:" (CommentContents | Comment)* ":)" /* ws: explicitXQ */
/* gn: commentsXQ */
[161]    PITarget    ::=    [http://www.w3.org/TR/REC-xml#NT-PITarget]XML /* gn: xml-versionXQ */
[162]    CharRef    ::=    [http://www.w3.org/TR/REC-xml#NT-CharRef]XML /* gn: xml-versionXQ */
[163]    QName    ::=    [http://www.w3.org/TR/REC-xml-names/#NT-QName]Names /* gn: xml-versionXQ */
[164]    NCName    ::=    [http://www.w3.org/TR/REC-xml-names/#NT-NCName]Names /* gn: xml-versionXQ */
[165]    S    ::=    [http://www.w3.org/TR/REC-xml#NT-S]XML /* gn: xml-versionXQ */
[166]    Char    ::=    [http://www.w3.org/TR/REC-xml#NT-Char]XML /* gn: xml-versionXQ */

The following symbols are used only in the definition of terminal symbols; they are not terminal symbols in the grammar of A EBNF for XQuery 1.0 Grammar with Update extensions.

[167]    Digits    ::=    [0-9]+
[168]    CommentContents    ::=    (Char+ - (Char* ('(:' | ':)') Char*))

B References

XQuery 1.0
World Wide Web Consortium. XQuery 1.0: An XML Query Language. W3C Proposed Recommendation, 21 November 2006. See http://www.w3.org/TR/xquery/.
XQuery Update Facility
World Wide Web Consortium. XQuery Update Facility. W3C Working Draft, 11 July 2006. See http://www.w3.org/TR/xqupdate.
XQuery 1.0 and XPath 2.0 Full-Text
World Wide Web Consortium. XQuery 1.0 and XPath 2.0 Full-Text. W3C Working Draft, 1 May 2006. See http://www.w3.org/TR/xquery-full-text/.
XQuery/XPath Data Model (XDM)
World Wide Web Consortium. XQuery 1.0 and XPath 2.0 Data Model (XDM). W3C Working Draft, 03 November 2005. See http://www.w3.org/TR/xpath-datamodel/.

C Error Conditions

err:XQP0001

D Glossary (Non-Normative)

basic updating expression

A basic updating expression is an insert, delete, replace, or rename expression, or a call to an updating function.

data model

The term data model refers to the data model specified by [XQuery/XPath Data Model (XDM)].

mark

To mark a node means to identify the node as participating in a later operation.

non-updating expression

A non-updating expression is any XQuery expression that is not an updating expression.

pending update list

A pending update list is an unordered collection of update primitives, which represent node state changes that have not yet been applied.

snapshot semantics

The upd:applyUpdates operation determines the scope within which all expressions are evaluated before any updates are applied. This is sometimes called the scope of snapshot semantics.

target node

The first argument of an update primitive, called its target node, is the principal node to be affected by the update primitive.

update operation

Update operations are used in defining the semantics of XQuery updates, but are not directly available to users. Update operations are defined in 3 Update Operations.

update primitive

Update primitives are the components of pending update lists. Each update primitive represents a node state change that has not yet been applied.

updating expression

An updating expression is an expression that contains a basic updating expression that is not inside the modify clause of a transform expression.

XDM instance

The term XDM instance denotes an unconstrained sequence of zero or more nodes and/or atomic values as defined by the data model.

XQuery

Within this document, the term XQuery refers to the language specified by [XQuery 1.0].

E Revision Log (Non-Normative)

This log records the substantive changes that have been made to this document since the Initial Working Draft.

E.1 Version