Exporters From Japan
Wholesale exporters from Japan   Company Established 1983
CARVIEW
Select Language

4 Static Typing Feature

XQuery 1.0 includes an optional static typing feature. This section describes the static typing feature for the XQuery Update Facility 1.0. Implementations of this specification that support optional static typing must implement the following static typing rules, along with the XQuery 1.0 static typing rules defined in [XQuery 1.0 and XPath 2.0 Formal Semantics].

4.1 Overview and notations

The concepts and notations used in this specification are the same as those used to define the static typing feature for XQuery 1.0. For convenience, we recall here some of the main concepts and notations. We refer the reader to [XQuery 1.0 and XPath 2.0 Formal Semantics] for a more detailed introduction.

The static typing feature for the XQuery Update Facility 1.0 is defined based on a processing model similar to the one of XQuery 1.0. We first define the XQuery Update Facility 1.0 Core, as a subset of the XQuery Update Facility 1.0. Then for each kind of updating expression, we give the normalization rules from the XQuery Update Facility 1.0 into that Core, as well as the inference rules that compute the type for each Core expression.

Notation

Normalization rules map expressions in the XQuery Update Facility 1.0 into expressions in the XQuery Update Facility 1.0 Core. They are written as follows.

 
[Expr]Expr
==
CoreExpr

Notation

The static semantics is specified through a judgment which gives for each expression its corresponding static type. The meaning of that judgment is defined through inference rules as in [XQuery 1.0 and XPath 2.0 Formal Semantics].

The judgment

statEnv |- Expr : Type

holds when, in the static environment statEnv, the expression Expr has type Type.

Notation

The static environment is the same as the one defined in [XQuery 1.0 and XPath 2.0 Formal Semantics], extended with an entry corresponding to the revalidation mode, as follows.

statEnv.revalidationMode
The statEnv.revalidationMode environment component designates the revalidation mode in the XQuery Update Facility 1.0 static context.
The statEnv.revalidationMode environment component is one of strict, lax, or skip.

4.3 Core Grammar

We extend the XQuery Core defined in [XQuery 1.0 and XPath 2.0 Formal Semantics] with five expressions needed to support the XQuery Update Facility 1.0: insert, delete, rename, replace, and transform.

[23 (Core)]   ExprSingle   ::=   FLWORExpr
| QuantifiedExpr
| TypeswitchExpr
| IfExpr
| InsertExpr
| DeleteExpr
| RenameExpr
| ReplaceExpr
| TransformExpr
| OrExpr
[99 (Core)]   InsertExpr   ::=   "insert" "nodes" SourceExpr InsertExprTargetChoice TargetExpr
[98 (Core)]   InsertExprTargetChoice   ::=   (("as" ("first" | "last"))? "into")
| "after"
| "before"
[103 (Core)]   SourceExpr   ::=   ExprSingle
[104 (Core)]   TargetExpr   ::=   ExprSingle
[100 (Core)]   DeleteExpr   ::=   "delete" "nodes" TargetExpr
[101 (Core)]   ReplaceExpr   ::=   "replace" ("value" "of")? "node" TargetExpr "with" ExprSingle
[102 (Core)]   RenameExpr   ::=   "rename" "node" TargetExpr "as" NewNameExpr
[105 (Core)]   NewNameExpr   ::=   ExprSingle
[106 (Core)]   TransformExpr   ::=   "copy" "$" VarName ":=" ExprSingle ("," "$" VarName ":=" ExprSingle)* "modify" ExprSingle "return" ExprSingle

4.4 XQuery Update Facility 1.0 Prolog

In addition to the normalization rules defined in [XQuery 1.0 and XPath 2.0 Formal Semantics] for the XQuery 1.0 prolog, the following normalization rules apply to the revalidation mode setter.

Normalization

Revalidation declarations are left unchanged through normalization.

 
[RevalidationDecl]PrologDecl
==
RevalidationDecl

Static Context Processing

The revalidation declaration modifies the revalidation mode in the static context.

statEnv1 = statEnv + revalidationMode( RevalidationMode)

statEnv |- declare revalidation RevalidationMode =>stat statEnv1

4.5 XQuery Update Facility 1.0 Expressions

In addition to the normalization and static typing rules defined in [XQuery 1.0 and XPath 2.0 Formal Semantics] for XQuery 1.0 expressions, the normalization and static typing rules described in this specification apply to the expressions in the XQuery Update Facility 1.0. For each expression except the transform expression, the final type is the empty type which corresponds to the value being returned. In each case, the static typing rules check that every sub-expression is well-typed, and that the resulting value is consistent with the constraints specific to each expression. For instance, the expression used in a delete must return a sequence of nodes.

4.5.1 Insert

Normalization

The following normalization rules apply to insert expressions. Note that whether the expression is written using the 'nodes' or 'node' modifier, the normalized expression always uses the 'nodes' modifier.

 
[insert (node|nodes) Expr1 InsertExprTargetChoice Expr2]Expr
==
insert nodes fs:item-sequence-to-node-sequence([Expr1]Expr) InsertExprTargetChoice [Expr2]Expr

Where fs:item-sequence-to-node-sequence is the special function used for computing element content and is defined in [XQuery 1.0 and XPath 2.0 Formal Semantics].

Static Type Analysis

The static typing rule for insert depends on whether it is an insert into, or an insert before or after.

In the case of an insert into, the inference depends on whether the target node is an element or a document node (in which case it does not allow attribute nodes to be inserted). This is expressed by the two following rules.

statEnv  |- Expr1 : Type1
statEnv |- Type1 <: (attribute *)*, (element * | text | comment | processing-instruction *)*
statEnv  |- Expr2 : Type2
statEnv |- Type2 <: (element *)?

statEnv  |- insert nodes Expr1 ((as (first | last))? into) Expr2 : empty

statEnv  |- Expr1 : Type1
statEnv |- Type1 <: (element * | text | comment | processing-instruction *)*
statEnv  |- Expr2 : Type2
statEnv |- Type2 <: [document-node()?]sequencetype

statEnv  |- insert nodes Expr1 ((as (first | last))? into) Expr2 : empty

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

statEnv  |- Expr1 : Type1
statEnv |- Type1 <: (attribute *)*, (element * | text | comment | processing-instruction *)*
statEnv  |- Expr2 : Type2
statEnv |- Type2 <: (element * | text | comment | processing-instruction *)?

statEnv  |- insert nodes Expr1 (after | before) Expr2 : empty

4.5.2 Delete

Normalization

The following normalization rule applies to delete expressions. Note that whether the expression is written using the 'nodes' or 'node' modifier, the normalized expression always uses the 'nodes' modifier.

 
[delete (node|nodes) Expr1]Expr
==
delete nodes [Expr1]Expr

Static Type Analysis

The static typing rule for delete is as follows.

statEnv  |- Expr : Type
statEnv |- Type <: [node()*]sequencetype

statEnv  |- delete (node|nodes) Expr : empty

4.5.3 Replace

Normalization

The following normalization rules applies to replace expressions.

 
[replace node Expr1 with Expr2]Expr
==
replace node [Expr1]Expr with fs:item-sequence-to-node-sequence([Expr2]Expr)

Normalization of replace value of expressions.

 
[replace value of node Expr1 with Expr2]Expr
==
replace value of node [Expr1]Expr with [text { Expr2 }]Expr

Static Type Analysis

If the value of modifier is not specified, a replace expression replaces one node with a new sequence of zero or more nodes.

An attribute node can be replaced only by zero or more attribute nodes.

statEnv  |- Expr1 : Type1
statEnv |- Type1 <: (attribute *)?
statEnv  |- Expr2 : Type2
statEnv |- Type2 <: (attribute *)*

statEnv  |- replace node Expr1 with Expr2 : empty

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

statEnv  |- Expr1 : Type1
statEnv |- Type1 <: (element * | text | comment | processing-instruction *)?
statEnv  |- Expr2 : Type2
statEnv |- Type2 <: (element * | text | comment | processing-instruction *)*

statEnv  |- replace node Expr1 with Expr2 : empty

If the value of modifier is specified, a replace expression replaces the content of a single node, which must not be a document node by either a single text node or empty.

statEnv  |- Expr1 : Type1
statEnv |- Type1 <: (attribute *| element * | text | comment | processing-instruction *)?
statEnv  |- Expr2 : Type2
statEnv |- Type2 <: text?

statEnv  |- replace value of node Expr1 with Expr2 : empty

4.5.4 Rename

Normalization

The following normalization rule applies to rename expressions.

 
[rename node Expr1 as Expr2]Expr
==
rename node [Expr1]Expr as fn:data([Expr2]Expr)

Static Type Analysis

The target of a rename expression must be either an element, attribute or processing-instruction, and its new name must be either of type xs:QName, xs:string, or xs:untypedAtomic.

statEnv  |- Expr1 : Type1
statEnv |- Type1 <: (attribute *| element * | processing-instruction *)?
statEnv  |- Expr2 : Type2
statEnv |- Type2 <: (xs:QName | xs:string | xs:untypedAtomic)

statEnv  |- rename node Expr1 as Expr2 : empty

4.5.5 Transform

Normalization

The following normalization rule applies to transform expressions.

 
[
copy
  VarName1 := Expr1
    ...
  VarNamen := Exprn
  modify Expr0 return Exprr
]Expr
==
copy
  VarName1 := fs:item-sequence-to-node-sequence([Expr1]Expr)
    ...
  VarNamen := fs:item-sequence-to-node-sequence([Exprn]Expr)
  modify [Expr0]Expr return [Exprr]Expr

Static Type Analysis

The transform expression is type checked using the following inference rule.

statEnv  |- Expr1 : Type1
statEnv |-  Type1 <: [node()]sequencetype
statEnv |- VarName1 of var expands to Variable1
statEnv1 = statEnv + varType(Variable1 => Type1[node()]sequencetype)
...
statEnvn-1 |-  Exprn : Typen
statEnvn-1 |-  Typen <: [node()]sequencetype
statEnv |- VarNamen of var expands to Variablen
statEnvn = statEnvn-1 + varType(Variablen => Typen[node()]sequencetype)
statEnvn |-  Expr0 : Type0
statEnvn |-  Exprr : Typer

statEnv  |- 
copy
  VarName1 := Expr1
    ...
  VarNamen := Exprn
  modify Expr0 return Exprr
: Typer

5 Conformance

This section defines the conformance criteria for an XQuery processor. In this section, the following terms are used to indicate the requirement levels defined in [RFC 2119]. [Definition: MUST means that the item is an absolute requirement of the specification.] [Definition: MAY means that an item is truly optional.] [Definition: SHOULD means that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.]

An XQuery processor that claims to conform to this specification MUST include a claim of Minimal Conformance as defined in [5.1 Minimal Conformance]. In addition to a claim of Minimal Conformance, it MAY claim conformance to one or more optional features defined in [5.2 Optional Features].

5.1 Minimal Conformance

Minimal Conformance to this specification MUST include all of the following items:

  1. Minimal Conformance to [XQuery 1.0].

  2. Support for everything specified in this document except those features specified in [5.2 Optional Features] to be optional and [E XML Syntax (XQueryX) for XQuery Update Facility 1.0]. If an implementation does not provide a given optional feature, it MUST implement any requirements specified in [5.2 Optional Features] for implementations that do not provide that feature.

  3. A definition of every item specified to be implementation-defined, unless that item is part of an optional feature that is not supported by the implementation. A list of implementation-defined items can be found in [B Implementation-Defined Items].

    Note:

    Implementations are not required to define items specified to be implementation-dependent.

5.2 Optional Features

An implementation of XQuery that includes the Update Facility MAY also support the Optional Features of [XQuery 1.0]. These are Schema Import Feature, Schema Validation Feature, Static Typing Feature, Full Axis Feature, Module Feature, and Serialization Feature.

If an implementation claims support of the Static Typing Feature, then it MAY also claim support of the Update Facility Static Typing Feature.

5.2.1 Update Facility Static Typing Feature

[Definition: The Update Facility Static Typing Feature provides support for the static semantics defined in [4 Static Typing Feature], and requires implementations to detect and report type errors during the static analysis phase.]

If an implementation does not support the Update Static Typing Feature, 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 MAY raise that error during the static analysis phase. The choice of whether to raise such an error at analysis time is implementation-dependent.

Note:

An implementation that does not support the Update Static Typing Feature is not required to raise type errors during the static analysis phase; however, it MUST detect and raise non-type-related static errors during the static analysis phase.

6 XQueryX Conformance

This section defines the conformance criteria for an XQueryX processor that includes the Update Facility.

In this section, the terms MUST, MAY, and SHOULD are used as defined in [5 Conformance].

An XQueryX processor that claims to conform to this specification MUST implement the XQueryX syntax as defined in [E XML Syntax (XQueryX) for XQuery Update Facility 1.0] and include a claim of Minimal Conformance as defined in [5.1 Minimal Conformance]. In addition to a claim of Minimal Conformance, it MAY claim conformance to one or more optional features defined in [5.2 Optional Features].

A EBNF for XQuery 1.0 Grammar with Update 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)? "#)"
[67]   PragmaContents   ::=   (Char* - (Char* '#)' Char*))
[68]   PathExpr   ::=   ("/" RelativePathExpr?)
| ("//" RelativePathExpr)
| RelativePathExpr
[69]   RelativePathExpr   ::=   StepExpr (("/" | "//") StepExpr)*
[70]   StepExpr   ::=   FilterExpr | AxisStep
[71]   AxisStep   ::=   (ReverseStep | ForwardStep) PredicateList
[72]   ForwardStep   ::=   (ForwardAxis NodeTest) | AbbrevForwardStep
[73]   ForwardAxis   ::=   ("child" "::")
| ("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)
[81]   FilterExpr   ::=   PrimaryExpr PredicateList
[82]   PredicateList   ::=   Predicate*
[83]   Predicate   ::=   "[" Expr "]"
[84]   PrimaryExpr   ::=   Literal | VarRef | ParenthesizedExpr | ContextItemExpr | FunctionCall | OrderedExpr | UnorderedExpr | Constructor
[85]   Literal   ::=   NumericLiteral | StringLiteral
[86]   NumericLiteral   ::=   IntegerLiteral | DecimalLiteral | DoubleLiteral
[87]   VarRef   ::=   "$" VarName
[88]   VarName   ::=   QName
[89]   ParenthesizedExpr   ::=   "(" Expr? ")"
[90]   ContextItemExpr   ::=   "."
[91]   OrderedExpr   ::=   "ordered" "{" Expr "}"
[92]   UnorderedExpr   ::=   "unordered" "{" Expr "}"
[93]   FunctionCall   ::=   QName "(" (ExprSingle ("," ExprSingle)*)? ")"
[94]   Constructor   ::=   DirectConstructor
| ComputedConstructor
[95]   DirectConstructor   ::=   DirElemConstructor
| DirCommentConstructor
| DirPIConstructor
[96]   DirElemConstructor   ::=   "<" QName DirAttributeList ("/>" | (">" DirElemContent* "</" QName S? ">"))
[97]   DirAttributeList   ::=   (S (QName S? "=" S? DirAttributeValue)?)*
[98]   DirAttributeValue   ::=   ('"' (EscapeQuot | QuotAttrValueContent)* '"')
| ("'" (EscapeApos | AposAttrValueContent)* "'")
[99]   QuotAttrValueContent   ::=   QuotAttrContentChar
| CommonContent
[100]   AposAttrValueContent   ::=   AposAttrContentChar
| CommonContent
[101]   DirElemContent   ::=   DirectConstructor
| CDataSection
| CommonContent
| ElementContentChar
[102]   CommonContent   ::=   PredefinedEntityRef | CharRef | "{{" | "}}" | EnclosedExpr
[103]   DirCommentConstructor   ::=   "<!--" DirCommentContents "-->"
[104]   DirCommentContents   ::=   ((Char - '-') | ('-' (Char - '-')))*
[105]   DirPIConstructor   ::=   "<?" PITarget (S DirPIContents)? "?>"
[106]   DirPIContents   ::=   (Char* - (Char* '?>' Char*))
[107]   CDataSection   ::=   "<![CDATA[" CDataSectionContents "]]>"
[108]   CDataSectionContents   ::=   (Char* - (Char* ']]>' Char*))
[109]   ComputedConstructor   ::=   CompDocConstructor
| CompElemConstructor
| CompAttrConstructor
| CompTextConstructor
| CompCommentConstructor
| CompPIConstructor
[110]   CompDocConstructor   ::=   "document" "{" Expr "}"
[111]   CompElemConstructor   ::=   "element" (QName | ("{" Expr "}")) "{" ContentExpr? "}"
[112]   ContentExpr   ::=   Expr
[113]   CompAttrConstructor   ::=   "attribute" (QName | ("{" Expr "}")) "{" Expr? "}"
[114]   CompTextConstructor   ::=   "text" "{" Expr "}"
[115]   CompCommentConstructor   ::=   "comment" "{" Expr "}"
[116]   CompPIConstructor   ::=   "processing-instruction" (NCName | ("{" Expr "}")) "{" Expr? "}"
[117]   SingleType   ::=   AtomicType "?"?
[118]   TypeDeclaration   ::=   "as" SequenceType
[119]   SequenceType   ::=   ("empty-sequence" "(" ")")
| (ItemType OccurrenceIndicator?)
[120]   OccurrenceIndicator   ::=   "?" | "*" | "+"
[121]   ItemType   ::=   KindTest | ("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]   InsertExprTargetChoice   ::=   (("as" ("first" | "last"))? "into")
| "after"
| "before"
[143]   InsertExpr   ::=   "insert" ("node" | "nodes") SourceExpr InsertExprTargetChoice TargetExpr
[144]   DeleteExpr   ::=   "delete" ("node" | "nodes") TargetExpr
[145]   ReplaceExpr   ::=   "replace" ("value" "of")? "node" TargetExpr "with" ExprSingle
[146]   RenameExpr   ::=   "rename" "node" TargetExpr "as" NewNameExpr
[147]   SourceExpr   ::=   ExprSingle
[148]   TargetExpr   ::=   ExprSingle
[149]   NewNameExpr   ::=   ExprSingle
[150]   TransformExpr   ::=   "copy" "$" VarName ":=" ExprSingle ("," "$" VarName ":=" ExprSingle)* "modify" ExprSingle "return" ExprSingle

A.1 Terminal Symbols

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

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

[168]   Digits   ::=   [0-9]+
[169]   CommentContents   ::=   (Char+ - (Char* ('(:' | ':)') Char*))
  • The mechanism (if any) by which an external function can return an XDM instance and/or a pending update list to the invoking query.

  • The semantics of fn:put(), including the kinds of nodes accepted as operands by this function.

  • C References

    C.1 Normative References

    XQuery Update Facility 1.0 Requirements
    XQuery Update Facility 1.0 Requirements, Don Chamberlin and Jonathan Robie, Editors. World Wide Web Consortium, 25 January 2011. This version is https://www.w3.org/TR/2011/NOTE-xquery-update-10-requirements-20110125/. The latest version is available at https://www.w3.org/TR/xquery-update-10-requirements/.
    XQuery 1.0 and XPath 2.0 Data Model
    XQuery 1.0 and XPath 2.0 Data Model (XDM) (Second Edition), Norman Walsh, Mary Fernández, Ashok Malhotra, et. al., Editors. World Wide Web Consortium, 14 December 2010. This version is https://www.w3.org/TR/2010/REC-xpath-datamodel-20101214/. The latest version is available at https://www.w3.org/TR/xpath-datamodel/.
    XQuery 1.0
    XQuery 1.0: An XML Query Language (Second Edition), Don Chamberlin, Anders Berglund, Scott Boag, et. al., Editors. World Wide Web Consortium, 14 December 2010. This version is https://www.w3.org/TR/2010/REC-xquery-20101214/. The latest version is available at https://www.w3.org/TR/xquery/.
    XQuery 1.0 and XPath 2.0 Functions and Operators
    XQuery 1.0 and XPath 2.0 Functions and Operators (Second Edition), Ashok Malhotra, Jim Melton, and Norman Walsh, Editors. World Wide Web Consortium, 14 December 2010. This version is https://www.w3.org/TR/2010/REC-xpath-functions-20101214/. The latest version is available at https://www.w3.org/TR/xpath-functions/.
    XQueryX 1.0
    XML Syntax for XQuery 1.0 (XQueryX) (Second Edition), Jim Melton and Subramanian Muralidhar, Editors. World Wide Web Consortium, 14 December 2010. This version is https://www.w3.org/TR/2010/REC-xqueryx-20101214/. The latest version is available at https://www.w3.org/TR/xqueryx/.
    XQuery 1.0 and XPath 2.0 Formal Semantics
    XQuery 1.0 and XPath 2.0 Formal Semantics (Second Edition), Jérôme Siméon, Denise Draper, Peter Frankhauser, et. al., Editors. World Wide Web Consortium, 14 December 2010. This version is https://www.w3.org/TR/2010/REC-xquery-semantics-20101214/. The latest version is available at https://www.w3.org/TR/xquery-semantics/.
    RFC 2119

    C.2 Non-normative References

    XML Patch Operations
    XQuery Update Facility 1.0 Use Cases
    XQuery Update Facility 1.0 Use Cases, Iona Manolescu and Jonathan Robie, Editors. World Wide Web Consortium, 25 January 2011. This version is https://www.w3.org/TR/2011/NOTE-xquery-update-10-use-cases-20110125/. The latest version is available at https://www.w3.org/TR/xquery-update-10-use-cases/.

    D Error Conditions

    D.1 New Error Codes

    err:XUST0001

    It is a static error if an updating expression is used in any position other than one of the following:

    1. The topmost expression in the body of a query.

    2. The modify clause of a transform expression.

    3. The return clause of a FLWOR expression.

    4. The return clauses of a typeswitch expression in which every return clause contains an updating expression or a vacuous expression.

    5. The then and else clauses of a conditional statement in which both the then and else clauses contain either an updating expression or a vacuous expression.

    6. An operand of a comma expression in which each operand is either an updating expression or a vacuous expression.

    7. The content of a parenthesized expression.

    8. The body of a function declaration in which the keyword updating is specified.

    err:XUST0002

    It is a static error if a simple expression that is not a vacuous expression is used in one of the following positions:

    1. The modify clause of a transform expression.

    2. The top-level expression in the body of a function declaration in which the keyword updating is specified.

    err:XUST0003

    It is a static error if a Prolog contains more than one revalidation declaration.

    err:XUTY0004

    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.

    err:XUTY0005

    In an insert expression where into, as first into, or as last into is specified, it is a type error if the target expression returns a non-empty result that does not consist of a single element or document node.

    err:XUTY0006

    In an insert expression where before or after is specified, it is a type error if the target expression returns a non-empty result that does not consist of a single element, text, comment, or processing instruction node.

    err:XUTY0007

    It is a type error if the target expression of a delete expression does not return a sequence of zero or more nodes.

    err:XUTY0008

    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.

    err:XUDY0009

    In a replace expression where value of is not specified, it is a dynamic error if the node returned by the target expression does not have a parent.

    err:XUTY0010

    In a replace expression where value of is not specified and the target is an element, text, comment, or processing instruction node, it is a type error if the replacement sequence does not consist of zero or more element, text, comment, or processing instruction nodes.

    err:XUTY0011

    In a replace expression where value of is not specified and the target is an attribute node, it is a type error if the replacement sequence does not consist of zero or more attribute nodes.

    err:XUTY0012

    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.

    err:XUTY0013

    In a transform expression, it is a type error if a source expression in the copy clause does not return a single node.

    err:XUDY0014

    In a transform expression, it is a dynamic error if the modify clause modifies any node that was not created by the copy clause.

    err:XUDY0015

    It is a dynamic error if any node is the target of more than one rename expression within the same query.

    err:XUDY0016

    It is a dynamic error if any node is the target of more than one replace expression (without value of being specified) within the same query.

    err:XUDY0017

    It is a dynamic error if any node is the target of more than one replace value of expression within the same query.

    err:XUDY0018

    It is a dynamic error if a function that was declared to be external but not updating returns a non-empty pending update list.

    err:XUDY0019

    It is a dynamic error if a function that was declared to be both external and updating returns a non-empty data model instance.

    err:XUDY0020

    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.

    err:XUDY0021

    It is a dynamic error if the XDM instance that would result from applying all the updates in a query violates any constraint specified in [XQuery 1.0 and XPath 2.0 Data Model]. In this case, none of the updates in the query are made effective.

    err:XUTY0022

    It is a type error if an insert expression specifies the insertion of an attribute node into a document node.

    err:XUDY0023

    It is a dynamic error if an insert, replace, or rename expression affects an element node by introducing a new namespace binding that conflicts with one of its existing namespace bindings.

    err:XUDY0024

    It is a dynamic error if the effect of a set of updating expressions is to introduce conflicting namespace bindings into an element node.

    err:XUDY0025

    (Not currently used.)

    err:XUST0026

    It is a static error if a revalidation declaration in a Prolog specifies a revalidation mode that is not supported by the current implementation.

    err:XUDY0027

    It is a dynamic error if the target expression of an insert, replace, or rename expression evaluates to an empty sequence.

    err:XUST0028

    It is a static error if a function declaration specifies both updating and a return type.

    err:XUDY0029

    In an insert expression where before or after is specified, it is a dynamic error if the node returned by the target expression does not have a parent.

    err:XUDY0030

    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.

    err:XUDY0031

    It is a dynamic error if multiple calls to fn:put in the same snapshot specify the same URI (after resolution of relative URIs).

    err:FOUP0001

    It is a dynamic error if the first operand of fn:put is not a node of a supported kind.

    err:FOUP0002

    It is a dynamic error if the second operand of fn:put is not a valid lexical representation of the xs:anyURI type.

    E XML Syntax (XQueryX) for XQuery Update Facility 1.0

    [XQueryX 1.0] defines an XML representation of [XQuery 1.0]. [XQuery Update Facility 1.0 Requirements] states "The syntax for updates MAY have more than one syntax binding. One syntax MUST be convenient for humans to read and write. One syntax MUST be expressed in XML in a way that reflects the underlying structure of the operations." This appendix specifies an XML Schema that defines the XML representation of XQuery Update Facility 1.0 by representing the abstract syntax found in [A EBNF for XQuery 1.0 Grammar with Update extensions]. This XML representation for XQuery Update Facility 1.0 integrates with the XML representation for XQuery 1.0.

    The XML Schema specified in this appendix accomplishes its integration by importing the XML Schema defined for XQueryX in [XQueryX 1.0], incorporating all of its type and element definitions. It then extends that schema by adding definitions of new types and elements in a namespace belonging to the Update Facility specification, as well as redefining one complex type.

    E.1 Schema

    This section specifies the two XML Schemas that define the complex types and elements for XQueryX in support of XQuery Update Facility 1.0, including changes to the prolog and the addition of several new expressions.

    <xsd:schema
         xmlns:xsd="https://www.w3.org/2001/XMLSchema" 
         xmlns:xqx="https://www.w3.org/2005/XQueryX"
         xmlns:xqxuf="https://www.w3.org/2007/xquery-update-10"
         targetNamespace="https://www.w3.org/2007/xquery-update-10"
         elementFormDefault="qualified" 
         attributeFormDefault="unqualified">
    <!-- Initial creation                  2006-08-17: Jim Melton -->
    <!-- Added ufRevalidationDecl          2006-08-21: Jim Melton -->
    <!-- Overhaul to bring up to date      2007-08-07: Jim Melton -->
    <!-- Reconfirmed correctness for CR    2008-02-27: Jim Melton -->
      <xsd:import namespace="https://www.w3.org/2005/XQueryX"
         schemaLocation="https://www.w3.org/2007/xquery-update-10/
    xquery-update-10-xqueryx-redef.xsd"/>
      <!-- Add revalidationDecl to alternatives in prolog setters -->
      <xsd:element name="revalidationDecl"
                   substitutionGroup="xqx:prologPartOneItem">
        <xsd:simpleType>
          <xsd:restriction base="xsd:NMTOKEN">
            <xsd:enumeration value="strict"/>
            <xsd:enumeration value="lax"/>
            <xsd:enumeration value="skip"/>
          </xsd:restriction>
        </xsd:simpleType>
      </xsd:element>
      <!-- Create substitution group for update facility exprs    -->
      <xsd:complexType name="expr">
        <xsd:complexContent>
          <xsd:extension base="xqx:expr"/>
        </xsd:complexContent>
      </xsd:complexType>
      <!-- Make the update facilities subst grp part of expr grp  -->
      <xsd:element name="expr" type="xqxuf:expr" abstract="true"
                   substitutionGroup="xqx:expr"/>
      <!-- InsertExpr                                             -->
      <xsd:complexType name="insertExpr">
        <xsd:complexContent>
          <xsd:extension base="xqxuf:expr">
            <xsd:sequence>
              <xsd:element name="sourceExpr"
                           type="xqx:exprWrapper"/>
              <xsd:choice>
                <xsd:element name="insertInto">
                  <xsd:complexType>
                    <xsd:sequence minOccurs="0" maxOccurs="1">
                      <xsd:choice>
                        <xsd:element name="insertAsFirst" 
                                     type="xqx:emptyContent"/>
                        <xsd:element name="insertAsLast" 
                                     type="xqx:emptyContent"/>
                      </xsd:choice>
                    </xsd:sequence>
                  </xsd:complexType>
                </xsd:element>
                <xsd:element name="insertAfter"
                             type="xqx:emptyContent"/>
                <xsd:element name="insertBefore"
                             type="xqx:emptyContent"/>
              </xsd:choice>
              <xsd:element name="targetExpr"
                           type="xqx:exprWrapper"/>
            </xsd:sequence>
          </xsd:extension>
        </xsd:complexContent>
      </xsd:complexType>
      <xsd:element name="insertExpr" type="xqxuf:insertExpr" 
                   substitutionGroup="xqxuf:expr"/>
      <!-- DeleteExpr                                             -->
      <xsd:complexType name="deleteExpr">
        <xsd:complexContent>
          <xsd:extension base="xqxuf:expr">
            <xsd:sequence>
             <xsd:element name="targetExpr"
                          type="xqx:exprWrapper"/>
            </xsd:sequence>
          </xsd:extension>
        </xsd:complexContent>
      </xsd:complexType>
      <xsd:element name="deleteExpr" type="xqxuf:deleteExpr" 
                   substitutionGroup="xqxuf:expr"/>
      <!-- ReplaceExpr                                            -->
      <xsd:complexType name="replaceExpr">
        <xsd:complexContent>
          <xsd:extension base="xqxuf:expr">
            <xsd:sequence>
              <xsd:element name="replaceValue"
                           type="xqx:emptyContent"
                           minOccurs="0" maxOccurs="1"/>
              <xsd:element name="targetExpr"
                           type="xqx:exprWrapper"/>
              <xsd:element name="replacementExpr"
                           type="xqx:exprWrapper"/>
            </xsd:sequence>
          </xsd:extension>
        </xsd:complexContent>
      </xsd:complexType>
      <xsd:element name="replaceExpr" type="xqxuf:replaceExpr" 
                   substitutionGroup="xqxuf:expr"/>
      <!-- RenameExpr                                             -->
      <xsd:complexType name="renameExpr">
        <xsd:complexContent>
          <xsd:extension base="xqxuf:expr">
            <xsd:sequence>
              <xsd:element name="targetExpr"
                           type="xqx:exprWrapper"/>
              <xsd:element name="newNameExpr"
                           type="xqx:exprWrapper"/>
            </xsd:sequence>
          </xsd:extension>
        </xsd:complexContent>
      </xsd:complexType>
      <xsd:element name="renameExpr" type="xqxuf:renameExpr" 
                   substitutionGroup="xqxuf:expr"/>
      <!-- TransformExpr                                          -->
      <xsd:complexType name="transformExpr">
        <xsd:complexContent>
          <xsd:extension base="xqxuf:expr">
            <xsd:sequence>
              <xsd:element name="transformCopies">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="transformCopy" minOccurs="1" 
                                 maxOccurs="unbounded">
                      <xsd:complexType>
                        <xsd:sequence>
                          <xsd:element ref="xqx:varRef"/>
                          <xsd:element name="copySource"
                                       type="xqx:exprWrapper"/>
                        </xsd:sequence>
                      </xsd:complexType>
                    </xsd:element>
                  </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="modifyExpr"
                           type="xqx:exprWrapper"/>
              <xsd:element name="returnExpr"
                           type="xqx:exprWrapper"/>
            </xsd:sequence>
          </xsd:extension>
        </xsd:complexContent>
      </xsd:complexType>
      <xsd:element name="transformExpr" type="xqxuf:transformExpr" 
                   substitutionGroup="xqxuf:expr"/>
    </xsd:schema>
    <xsd:schema xmlns:xsd="https://www.w3.org/2001/XMLSchema"
    	            xmlns="https://www.w3.org/2005/XQueryX"
    	            targetNamespace="https://www.w3.org/2005/XQueryX"
    	            elementFormDefault="qualified" attributeFormDefault="qualified">
    <!-- Redefine one or more components of the XQueryX XML Schema -->
    <xsd:redefine schemaLocation="https://www.w3.org/2005/XQueryX/xqueryx.xsd">
    <!-- Redefine the functionDecl complex type -->
      <xsd:complexType name="functionDecl">
        <xsd:complexContent>
          <xsd:extension base="functionDecl">
            <xsd:attribute name="updatingFunction"
                           type="xsd:boolean" default="false"/>
          </xsd:extension>
        </xsd:complexContent>
      </xsd:complexType>
    </xsd:redefine>
    </xsd:schema>
    

    E.2 Stylesheet

    This section specifies the XSLT stylesheet that defines the semantics of XQueryX in support of XQuery Update Facility 1.0. It imports the XSLT stylesheet defined in [XQueryX 1.0], and provides additional templates that define the semantics of the XQueryX representation of XQuery Update Facility 1.0 by transforming that XQueryX representation into the human readable syntax of XQuery Update Facility 1.0.

    <xsl:stylesheet version="1.0"
                    xmlns:xsl="https://www.w3.org/1999/XSL/Transform"
                    xmlns:xqxuf="https://www.w3.org/2007/xquery-update-10"
                    xmlns:xqx="https://www.w3.org/2005/XQueryX">
    <!-- Initial creation                  2006-08-17: Jim Melton -->
    <!-- Added revalidationDecl            2006-08-21: Jim Melton -->
    <!-- Bring up to date with spec        2007-08-07: Jim Melton -->
    <!-- Surround updating exprs w/parens  2007-09-13: Jim Melton -->
    <xsl:import href="https://www.w3.org/2005/XQueryX/xqueryx.xsl"/>
    <!-- revalidationDecl                                         -->
    <xsl:template match="xqxuf:revalidationDecl">
      <xsl:text>declare revalidation </xsl:text>
      <xsl:apply-templates/>
    </xsl:template>
    <!-- insertExpr                                               -->
    <xsl:template match="xqxuf:insertExpr">
      <xsl:value-of select="$LPAREN"/>
      <xsl:text>insert nodes </xsl:text>
      <xsl:value-of select="$NEWLINE"/>
      <xsl:apply-templates select="xqxuf:sourceExpr"/>
      <xsl:value-of select="$NEWLINE"/>
      <xsl:apply-templates select="xqxuf:insertInto |
                                   xqxuf:insertBefore |
                                   xqxuf:insertAfter"/>
      <xsl:value-of select="$NEWLINE"/>
      <xsl:apply-templates select="xqxuf:targetExpr"/>
      <xsl:value-of select="$RPAREN"/>
    </xsl:template>
    <!-- sourceExpr                                               -->
    <xsl:template match="xqxuf:sourceExpr">
      <xsl:apply-templates/>
    </xsl:template>
    <!-- insertInto                                               -->
    <xsl:template match="xqxuf:insertInto">
      <xsl:if test="child::node()">
        <xsl:text>as </xsl:text>
      </xsl:if>
      <xsl:apply-templates/>
      <xsl:text>into </xsl:text>
    </xsl:template>
    <!-- insertAsFirst                                            -->
    <xsl:template match="xqxuf:insertAsFirst">
      <xsl:text>first </xsl:text>
    </xsl:template>
    <!-- insertAsLast                                             -->
    <xsl:template match="xqxuf:insertAsLast">
      <xsl:text>last </xsl:text>
    </xsl:template>
    <!-- insertAfter                                              -->
    <xsl:template match="xqxuf:insertAfter">
      <xsl:text>after </xsl:text>
    </xsl:template>
    <!-- insertBefore                                             -->
    <xsl:template match="xqxuf:insertBefore">
      <xsl:text>before </xsl:text>
    </xsl:template>
    <!-- targetExpr                                               -->
    <xsl:template match="xqxuf:targetExpr">
      <xsl:apply-templates/>
    </xsl:template>
    <!-- deleteExpr                                               -->
    <xsl:template match="xqxuf:deleteExpr">
      <xsl:value-of select="$LPAREN"/>
      <xsl:text>delete nodes </xsl:text>
      <xsl:apply-templates/>
      <xsl:value-of select="$RPAREN"/>
    </xsl:template>
    <!-- replaceExpr                                              -->
    <xsl:template match="xqxuf:replaceExpr">
      <xsl:value-of select="$LPAREN"/>
      <xsl:text>replace </xsl:text>
      <xsl:if test="xqxuf:replaceValue">
        <xsl:text>value of </xsl:text>
      </xsl:if>
      <xsl:text>node </xsl:text>
      <xsl:apply-templates select="xqxuf:targetExpr"/>
      <xsl:text> with </xsl:text>
      <xsl:apply-templates select="xqxuf:replacementExpr"/>
      <xsl:value-of select="$RPAREN"/>
    </xsl:template>
    <!-- replacementExpr                                          -->
    <xsl:template match="xqxuf:replacementExpr">
      <xsl:apply-templates/>
    </xsl:template>
    <!-- renameExpr                                               -->
    <xsl:template match="xqxuf:renameExpr">
      <xsl:value-of select="$LPAREN"/>
      <xsl:text>rename node </xsl:text>
      <xsl:apply-templates select="xqxuf:targetExpr"/>
      <xsl:text> as </xsl:text>
      <xsl:apply-templates select="xqxuf:newNameExpr"/>
      <xsl:value-of select="$RPAREN"/>
    </xsl:template>
    <!-- newNameExpr                                              -->
    <xsl:template match="xqxuf:newNameExpr">
      <xsl:apply-templates/>
    </xsl:template>
    <!-- transformExpr                                            -->
    <xsl:template match="xqxuf:transformExpr">
      <xsl:value-of select="$LPAREN"/>
      <xsl:text>copy </xsl:text>
      <xsl:apply-templates select="xqxuf:transformCopies"/>
      <xsl:value-of select="$NEWLINE"/>
      <xsl:text>  modify </xsl:text>
      <xsl:apply-templates select="xqxuf:modifyExpr"/>
      <xsl:value-of select="$NEWLINE"/>
      <xsl:text>  return </xsl:text>
      <xsl:apply-templates select="xqxuf:returnExpr"/>
      <xsl:value-of select="$RPAREN"/>
    </xsl:template>
    <!-- Part of transformExpr                                    -->
    <xsl:template match="xqxuf:transformCopies">
      <xsl:call-template name="commaSeparatedList"/>
    </xsl:template>
    <!-- Part of transformExpr                                    -->
    <xsl:template match="xqxuf:transformCopy">
      <xsl:apply-templates select="xqx:varRef"/>
      <xsl:text> := </xsl:text>
      <xsl:apply-templates select="xqxuf:copySource"/>
    </xsl:template>
    <!-- Part of transformExpr                                    -->
    <xsl:template match="xqxuf:copySource">
      <xsl:apply-templates/>
    </xsl:template>
    <!-- Part of transformExpr                                    -->
    <xsl:template match="xqxuf:modifyExpr">
      <xsl:apply-templates/>
    </xsl:template>
    <!-- Part of transformExpr                                    -->
    <xsl:template match="xqxuf:returnExpr">
      <xsl:apply-templates/>
    </xsl:template>
    <!-- Over-ride the template for functionDecl in XQueryX.xsd   -->
      <xsl:template match="xqx:functionDecl" priority="100">
        <xsl:text>declare </xsl:text>
        <xsl:if test="@xqx:updatingFunction and
                      @xqx:updatingFunction = 'true'">
          <xsl:text>updating </xsl:text>
        </xsl:if>
        <xsl:text>function </xsl:text>
        <xsl:apply-templates select="xqx:functionName"/>
        <xsl:apply-templates select="xqx:paramList"/>
        <xsl:apply-templates select="xqx:typeDeclaration"/>
        <xsl:apply-templates select="xqx:functionBody"/>
        <xsl:if test="xqx:externalDefinition">
          <xsl:text> external </xsl:text>
        </xsl:if>
      </xsl:template>
    </xsl:stylesheet>
    

    E.3 Example

    The following example is based on the data and queries in the use cases in [XQuery Update Facility 1.0 Use Cases]. In this example, we show the English description of the query, the XQuery Update Facility solution given in [XQuery Update Facility 1.0 Use Cases], an XQueryX solution, and the XQuery Update Facility expression that results from applying the Update Facility XQueryX-to-XQuery Update Facility transformation defined by the stylesheet in [E.2 Stylesheet] to the Update Facility XQueryX solution. The XQuery Update Facility expression that is produced is presented only as a sanity-check—the intent of the stylesheet is not to recreate the original XQuery expression, but to produce a valid XQuery expression with the same semantics. The semantics of the Update Facility XQueryX solution are determined by the semantics of the XQuery Update Facility expression that results from that transformation. The "correctness" of that transformation is determined by asking the following the question: Can some Update Facility XQueryX processor QX process some Update Facility XQueryX document D1 to produce results R1, after which the stylesheet is used to translate D1 into an XQuery Update Facility expression E1 that, when processed by some XQuery Update Facility processor Q, produces results R2 that are equivalent (under some meaningful definition of "equivalent") to results R1?

    Comparison of the results of the Update Facility XQueryX-to-XQuery Update Facility transformation given in this document with the XQuery Update Facility solutions in [XQuery Update Facility 1.0 Use Cases] may be helpful in evaluating the correctness of the Update Facility XQueryX solution in each example.

    The XQuery Update Facility Use Cases solution given for each example is provided only to assist readers of this document in understanding the Update Facility XQueryX solution. There is no intent to imply that this document specifies a "compilation" or "transformation" of XQuery Update Facility syntax into Update Facility XQueryX syntax.

    In the following example, note that path expressions are expanded to show their structure. Also, note that the prefix syntax for binary operators like "and" makes the precedence explicit. In general, humans find it easier to read an XML representation that does not expand path expressions, but it is less convenient for programmatic representation and manipulation. XQueryX is designed as a language that is convenient for production and modification by software, and not as a convenient syntax for humans to read and write.

    Finally, please note that white space, including new lines, have been added to some of the Update Facility XQueryX documents and XQuery Update Facility expressions for readability. That additional white space is not produced by the Update Facility XQueryX-to-XQuery Update Facility transformation.

    This example is based on Q6 from [XQuery Update Facility 1.0 Use Cases], use case Parts: "modifying recursive documents":

    E.3.2 XQueryX Representation

    <?xml version="1.0"?>
    <xqx:module xmlns:xqxuf="https://www.w3.org/2007/xquery-update-10"
                xmlns:xqx="https://www.w3.org/2005/XQueryX"
                xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="https://www.w3.org/2007/xquery-update-10
        https://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsd
        https://www.w3.org/2005/XQueryX
        https://www.w3.org/2005/XQueryX/xqueryx.xsd">
      <xqx:versionDecl>
        <xqx:version>1.0</xqx:version>
      </xqx:versionDecl>
      <xqx:mainModule>
        <xqx:queryBody>
          <xqx:flworExpr>
            <xqx:forClause>
              <xqx:forClauseItem>
                <xqx:typedVariableBinding>
                  <xqx:varName>keyword</xqx:varName>
                </xqx:typedVariableBinding>
                <xqx:positionalVariableBinding>i
                </xqx:positionalVariableBinding>
                <xqx:forExpr>
                  <xqx:sequenceExpr>
                    <xqx:stringConstantExpr>
                      <xqx:value>car</xqx:value>
                    </xqx:stringConstantExpr>
                    <xqx:stringConstantExpr>
                      <xqx:value>skateboard</xqx:value>
                    </xqx:stringConstantExpr>
                    <xqx:stringConstantExpr>
                      <xqx:value>canoe</xqx:value>
                    </xqx:stringConstantExpr>
                  </xqx:sequenceExpr>
                </xqx:forExpr>
              </xqx:forClauseItem>
              <xqx:forClauseItem>
                <xqx:typedVariableBinding>
                  <xqx:varName>parent</xqx:varName>
                </xqx:typedVariableBinding>
                <xqx:forExpr>
                  <xqx:pathExpr>
                    <xqx:stepExpr>
                      <xqx:filterExpr>
                        <xqx:functionCallExpr>
                          <xqx:functionName
                            xqx:prefix="fn">doc</xqx:functionName>
                          <xqx:arguments>
                            <xqx:stringConstantExpr>
                              <xqx:value>part-tree.xml</xqx:value>
                            </xqx:stringConstantExpr>
                          </xqx:arguments>
                        </xqx:functionCallExpr>
                      </xqx:filterExpr>
                    </xqx:stepExpr>
                    <xqx:stepExpr>
                      <xqx:xpathAxis>descendant-or-self</xqx:xpathAxis>
                      <xqx:nameTest>part</xqx:nameTest>
                      <xqx:predicates>
                        <xqx:equalOp>
                          <xqx:firstOperand>
                            <xqx:pathExpr>
                              <xqx:stepExpr>
                                <xqx:xpathAxis>attribute</xqx:xpathAxis>
                                <xqx:nameTest>name</xqx:nameTest>
                              </xqx:stepExpr>
                            </xqx:pathExpr>
                          </xqx:firstOperand>
                          <xqx:secondOperand>
                            <xqx:varRef>
                              <xqx:name>keyword</xqx:name>
                            </xqx:varRef>
                          </xqx:secondOperand>
                        </xqx:equalOp>
                      </xqx:predicates>
                    </xqx:stepExpr>
                  </xqx:pathExpr>
                </xqx:forExpr>
              </xqx:forClauseItem>
            </xqx:forClause>
            <xqx:letClause>
              <xqx:letClauseItem>
                <xqx:typedVariableBinding>
                  <xqx:varName>descendants</xqx:varName>
                </xqx:typedVariableBinding>
                <xqx:letExpr>
                  <xqx:pathExpr>
                    <xqx:stepExpr>
                      <xqx:filterExpr>
                        <xqx:varRef>
                          <xqx:name>parent</xqx:name>
                        </xqx:varRef>
                      </xqx:filterExpr>
                    </xqx:stepExpr>
                    <xqx:stepExpr>
                      <xqx:xpathAxis>descendant-or-self</xqx:xpathAxis>
                      <xqx:nameTest>part</xqx:nameTest>
                    </xqx:stepExpr>
                  </xqx:pathExpr>
                </xqx:letExpr>
              </xqx:letClauseItem>
            </xqx:letClause>
            <xqx:forClause>
              <xqx:forClauseItem>
                <xqx:typedVariableBinding>
                  <xqx:varName>p</xqx:varName>
                </xqx:typedVariableBinding>
                <xqx:forExpr>
                  <xqx:sequenceExpr>
                    <xqx:varRef>
                      <xqx:name>parent</xqx:name>
                    </xqx:varRef>
                    <xqx:varRef>
                      <xqx:name>descendants</xqx:name>
                    </xqx:varRef>
                  </xqx:sequenceExpr>
                </xqx:forExpr>
              </xqx:forClauseItem>
            </xqx:forClause>
            <xqx:returnClause>
              <xqxuf:replaceExpr>
                <xqxuf:replaceValue/>
                <xqxuf:targetExpr>
                  <xqx:pathExpr>
                    <xqx:stepExpr>
                      <xqx:filterExpr>
                        <xqx:varRef>
                          <xqx:name>p</xqx:name>
                        </xqx:varRef>
                      </xqx:filterExpr>
                    </xqx:stepExpr>
                    <xqx:stepExpr>
                      <xqx:xpathAxis>attribute</xqx:xpathAxis>
                      <xqx:nameTest>partid</xqx:nameTest>
                    </xqx:stepExpr>
                  </xqx:pathExpr>
                </xqxuf:targetExpr>
                <xqxuf:replacementExpr>
                  <xqx:addOp>
                    <xqx:firstOperand>
                      <xqx:multiplyOp>
                        <xqx:firstOperand>
                          <xqx:varRef>
                            <xqx:name>i</xqx:name>
                          </xqx:varRef>
                        </xqx:firstOperand>
                        <xqx:secondOperand>
                          <xqx:integerConstantExpr>
                            <xqx:value>1000</xqx:value>
                          </xqx:integerConstantExpr>
                        </xqx:secondOperand>
                      </xqx:multiplyOp>
                    </xqx:firstOperand>
                    <xqx:secondOperand>
                      <xqx:pathExpr>
                        <xqx:stepExpr>
                          <xqx:filterExpr>
                            <xqx:varRef>
                              <xqx:name>p</xqx:name>
                            </xqx:varRef>
                          </xqx:filterExpr>
                        </xqx:stepExpr>
                        <xqx:stepExpr>
                          <xqx:xpathAxis>attribute</xqx:xpathAxis>
                          <xqx:nameTest>partid</xqx:nameTest>
                        </xqx:stepExpr>
                      </xqx:pathExpr>
                    </xqx:secondOperand>
                  </xqx:addOp>
                </xqxuf:replacementExpr>
              </xqxuf:replaceExpr>
            </xqx:returnClause>
          </xqx:flworExpr>
        </xqx:queryBody>
      </xqx:mainModule>
    </xqx:module>
    

    E.3.3 Transformed XQuery Representation

    Application of the stylesheet in [E.2 Stylesheet] to the Update Facility XQueryX representation results in the following XQuery representation:

     xquery version "1.0";
    ( for $keyword at $i in ("car", "skateboard", "canoe"),
     $parent in
       fn:doc("part-tree.xml")/descendant-or-self::part
         [(attribute::name = $keyword)]
     let $descendants:=$parent/descendant-or-self::part
     for $p in ($parent, $descendants)
     return
       replace value of node $p/attribute::partid
         with (($i*1000)+$p/attribute::partid)
    )
    

    F Glossary (Non-Normative)

    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].

    basic updating expression

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

    conflict

    Two namespace bindings are said to conflict if their namespace prefixes (or absence thereof) are the same but their namespace URI's (or absence thereof) are different.

    data model

    The term data model refers to the data model specified by [XQuery 1.0 and XPath 2.0 Data Model].

    implied namespace binding

    The implied namespace binding of a QName is the association of its namespace prefix (or absence thereof) with its namespace URI (or absence thereof).

    mark

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

    may

    MAY means that an item is truly optional.

    must

    MUST means that the item is an absolute requirement of the specification.

    node identity

    The term node identity denotes the unique identity that is a property of every node in an XDM instance (see Section 2.3 Node IdentityDM.)

    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.

    revalidation declaration

    A revalidation declaration sets the revalidation mode in the static context, overriding any implementation-defined default.

    revalidation mode

    Revalidation mode, which may be strict, lax, or skip, is a component of the static context that controls the behavior of the upd:revalidate operation.

    should

    SHOULD means that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.

    simple expression

    A simple expression is any XQuery expression that is not an updating expression.

    snapshot

    A snapshot is a scope within which expressions are evaluated with respect to a fixed XDM instance and updates are held pending.

    static typing feature

    The Update Facility Static Typing Feature provides support for the static semantics defined in [4 Static Typing Feature], and requires implementations to detect and report type errors during the static analysis phase.

    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.

    update routine

    Update routines are sequences of actions that are used in the definition of XQuery semantics but do not appear on pending update lists.

    updating expression

    An updating expression is a basic updating expression or any expression (other than a transform expression) that directly contains an updating expression.

    updating function

    Functions whose declarations contain the keyword updating, and certain built-in functions including fn:put, are called updating functions.

    vacuous expression

    A vacuous expression is a simple expression that can only return an empty sequence or raise an error.

    vacuous expression

    Certain expressions are defined in this specification to be vacuous expressions. These all have the characteristic that they can be determined statically to either return an empty sequence or raise an error.

    G Rationale for Precedence of Update Primitives (Non-Normative)

    In [3.2.2 upd:applyUpdates], semantic rules specify the order in which the update primitives on a pending update list are applied. The purpose of this ordering is to ensure that the result of applying the pending update list is deterministic. The order of application of the update primitives was derived from the following reasoning:

    • insertAttribute, replaceValue, and rename primitives do not conflict with any other primitives other than put.

    • insertIntoprimitives must be applied before insertIntoAsFirst/Last and insertBefore/Afterprimitives. Reason: if an unpositioned insert were applied after a positioned insert, it might interfere with the position established by the earlier positioned insert. For example, suppose node A is inserted "before" node B. A later unpositioned insert into the common parent of A and B might intervene between A and B, which is not allowed by the semantics of "insert before."

    • insertBefore/Afterprimitives must be applied before replaceNode primitives. Reason: After a node has been replaced, it no longer has a parent, so "before" and "after" the replaced node are no longer defined.

    • insertIntoAsFirst/Lastprimitives must be applied before replaceElementContent primitives. Reason: this was a decision of the working group. The intent of this decision is that, if both of these primitives are applied to the same target node in a query, the effective result is determined by the replaceElementContent primitive.

    • replaceNodeprimitives must be applied before replaceElementContent primitives. Reason: if element content that includes a node N has been replaced, then N no longer has a parent. In this case, "replace node N" is undefined.

    • replaceNodeprimitives must be applied before delete primitives. Reason: After a node has been deleted, it no longer has a parent. Replacing a node that has no parent is undefined.

    • putprimitives must be applied after all other primitives in order that documents stored by a snapshot will reflect all update operations applied by the snapshot.

    H Revision Log (Non-Normative)

    The following substantive changes have been made to this document since the Candidate Recommendation of 9 June 2009. Minor editorial changes are not included in this log.

    1. Fixed a bug involving namespace propagation and default namespaces. Resolves Bug 9432.

    2. Added missing parameter to upd:applyUpdates(). Resolves Bug 9262.

    3. Added missing text governing namespace binding conflicts when the namespace prefix for an attribute is absent. Resolves Bug 9257.

    4. Fixed two errors governing namespace bindings created by upd:replaceNode(). The erroneous text said that the namespace binding was created on the attribute itself, rather than the parent element. Resolves Bug 9256.

    5. Added a note indicating that some examples are rejected by implementations that support static typing. See Bug 8006.

    The following substantive changes have been made to this document since the Candidate Recommendation of 14 March 2008.

    1. Added a rule: the expression on the right-hand-side of a variable declaration the initializing expression) must be a simple expression. Resolves Bug 5699. Section affected: [2.2.2 Variable Declaration].

    2. When a rename expression operates on an attribute node, err:XUDY0023 can be raised only if the new name of the attribute is in a namespace. Renaming an attribute to a QName that has neither a namespace prefix nor a namespace URI is not an error, even if the parent element has a default namespace. Partial resolution of Bug 5629. Section affected: [2.4.4 Rename].

    3. When a upd:rename operation is applied to an element node, and the $newname 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: [3.1.11 upd:rename].

    4. Optional error err:XUDY0020 (deletion of a node that has no parent) is made part of the semantics of the delete expression (formerly it was described under the upd:delete primitive). Partial resolution of Bug 5632. Sections affected: [2.4.2 Delete], [3.1.7 upd:delete].

    5. Error err:XUDY0024 (updates introducing conflicting namespace bindings) is made part of the semantics of the insert and replace expressions. Also, consistency constraints on Pending Update Lists, raising err:XUDY0024 if multiple primitives on a PUL have conflicting namespace bindings, have been added to the semantics of upd:mergeUpdates and upd:applyUpdates. Checks for err:XUDY0024 are no longer part of the semantics of upd:insertAttributes, upd:replaceNode, or upd:rename. 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: [2.4.1 Insert], [2.4.3 Replace], [3.1.6 upd:insertAttributes], [3.1.8 upd:replaceNode], [3.1.11 upd:rename], [3.2.1 upd:mergeUpdates], [3.2.2 upd:applyUpdates].

    6. The following changes were made to the semantics of fn:put (resolving Bug 5646):

      1. fn:put now generates an update primitive called upd:put, which is held on the pending update list and applied after all other update primitives. Sections: [2.6.1 fn:put], [3.1.12 upd:put].

      2. It is an error to invoke fn:put more than once on the same URI within a snapshot. Sections: [2.4.6 Compatibility of Updating Expressions], [3.2.1 upd:mergeUpdates], [3.2.2 upd:applyUpdates], [D.1 New Error Codes].

      3. fn:put is classified as an updating function. Section: [2.2.3 Function Declaration].

    7. Moved the subsection on Function Declarations inside the section on Extensions to the Prolog. Resolves Bug 5701. Section affected: [2.2.3 Function Declaration]

    8. In the Static Typing Feature for XQuery Update Facility, err:XPST0005 applies only to simple expressions (not to updating expressions.) Resolves Bug 5700. Sections affected: [4.2 Change to Static Typing Rules of XQuery 1.0], [D.2 Amendments to Existing Error Codes].

    9. In the Static Type Analysis for TransformExpr, the static type of each copy-variable used to be the type inferred from its source expression; now it's just node().

    No substantive changes have been made to this document since the Proposed Recommendation of 25 January 2011.

     
    Original Source | Taken Source