ConceptioArchiveW3C TR
W3C TRopen access

xquery sx 10

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

XQuery Scripting Extension 1.0 /**/ /* from xsl:query.xsl (C) */ code { font-family: monospace; }

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

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

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

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

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

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

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

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

a.judgment:visited, a.judgment:link { font-family: sans-serif; color: black; text-decoration: none } a.processing:visited, a.processing:link { color: black; text-decoration: none } a.env:visited, a.env:link { color: black; text-decoration: none } table.small { font-size: x-small; } /* from xsl-query.xsl (B) */ table.small { font-size: x-small; } a.judgment:visited, a.judgment:link { font-family: sans-serif; color: black; text-decoration: none } a.processing:visited, a.processing:link { color: black; text-decoration: none } a.env:visited, a.env:link { color: black; text-decoration: none } /**/ This version: http://www.w3.org/TR/2014/NOTE-xquery-sx-10-20140918/ Latest version: http://www.w3.org/TR/xquery-sx-10/ Previous versions: http://www.w3.org/TR/2010/WD-xquery-sx-10-20100408/ http://www.w3.org/TR/2008/WD-xquery-sx-10-20081203/ http://www.w3.org/TR/2008/WD-xquery-sx-10-20080328/ Editors: John Snelson, MarkLogic <[email protected]> Don Chamberlin, IBM Almaden Research Center, via http://www.almaden.ibm.com/cs/people/chamberlin/ Daniel Engovatov, W3C invited expert Dana Florescu, Oracle Corporation <[email protected]> Giorgio Ghelli, University of Pisa <[email protected]> Jim Melton, Oracle Corporation <[email protected]> Jérôme Siméon, IBM T.J. Watson Research Center <[email protected]> Copyright W3C ® MIT ERCIM Keio Beihang liability trademark document use This specification defines an extension to [XQuery 1.0] [XQuery Update Facility] This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index This document is governed by the 14 October 2005 W3C Process Document This is a Working Group Note Process Document XML Query Working Group XML Activity This Working Group Note being published in order to document the work that the XML Query Working Group has done in the area of providing an imperative extension to XQuery. The WG was unable to achieve consensus on several significant aspects of this technology and determined to terminate work on the project in mid-2014. This document incorporates changes made against the previous publication of the Working Draft. Changes to this document since the previous publication of the Working Draft are detailed in [G Revision Log] Please report errors in this document using W3C's public Bugzilla system http://www.w3.org/XML/2005/04/qt-bugzilla [email protected] http://lists.w3.org/Archives/Public/public-qt-comments/ Publication as a Working Group Note This document was produced by a group operating under the 5 February 2004 W3C Patent Policy public list of any patent disclosures Essential Claim(s) section 6 of the W3C Patent Policy 1 Introduction Extensions to the Processing Model Evaluation Order Snapshot and Execution Scope Variable Binding Revalidation Updating Expression Constraints Sequential Expressions Extensions to the Static Context Predefined Namespace Query Mode Extensions to the Prolog Assignable Global Variables Function Declarations Query Mode Option New Kinds of Expressions Apply Expression Block Expressions Assignment Expression While Expression Exit Expression Query Mode Pragma Changes to Existing Expressions Parentheses Function Calls Path Expressions Predicates Concatenation Expressions Direct and Computed Node Constructors FLWOR Expressions Conditional Expressions Quantified Expressions Typeswitch Expressions Insert, Delete, Replace, and Rename Expressions Transform Expressions Other Expressions Example A EBNF for XQuery 1.0 Grammar with Scripting Extensions Terminal Symbols Extra-grammatical Constraints XML Syntax (XQueryX) for XQuery Scripting Extension 1.0 Schema Stylesheet Example XQuery Representation XQueryX Representation Transformed XQuery Representation Implementation-Defined Items References Error Conditions New Error Codes Amendments to Existing Error Codes Glossary Revision Log Since the 3 December 2008 Working Draft Since the 28 March 2008 Working Draft XQuery Scripting Extension extends [XQuery 1.0] [XQuery Scripting Requirements] [XQuery Update Facility] Definition XQUF [XQuery Update Facility] Definition XQSX In this document, examples and material labeled as "Note" are provided for explanatory purposes and are not normative. XQSX It is a strict superset of XQUF XQUF XQSX XQUF [XQuery 1.0] It does not introduce any "modes" that affect the semantics of expressions. As in XQUF XDM instance pending update list Definition XDM instance [XQuery Data Model] Definition pending update list [XQuery Update Facility] Expressions in XQSX may have side-effects that are visible to subsequent expressions (according to their evaluation order [XQuery 1.0] [XQuery Update Facility] [ Definition XQSX evaluation order Note: Since none of the XQuery expressions existing before XQSX XQSX The term snapshot [XQuery Update Facility] Definition snapshot XDM instance upd:applyUpdates XQUF XQSX [XQuery 1.0 and XPath 2.0 Functions and Operators] stable FO fn:current-time fn:doc execution scope FO XQSX In XQSX, each of the following expressions is both a snapshot and execution scope: each ConcatExpr within an ApplyExpr each initialization expression in a BlockVarDecl the expression on the right-hand side of an AssignmentExpr the expression in an ExitExpr the test expression in a WhileExpr To ensure type soundness, variable bindings are revalidated at the end of each scope to check that any updates applied have not made them invalid with repect to their declared types. It is a dynamic error [ err:SXDY0003 upd:applyUpdates XQSX updating expressions XDM instance pending update list pending update list An updating expression simple expression updating expression updating expression An expression may not be both sequential updating updating sequential expression err:SXST0002 The pending update list upd:mergeUpdates pending update lists pending update list XQSX sequential expressions XQUF [5 New Kinds of Expressions] [6 Changes to Existing Expressions] [ Definition updating expression pending update list XDM instance pending update list [ Definition sequential expression XDM instance XDM instance pending update list [ Definition simple expression updating expression sequential expression XDM instance The classification of each expression into one of the above categories is performed by static analysis. For each kind of expression, XQSX Note that simple expressions updating expressions sequential expressions Expression category Can return non-empty XDM instance? Can return non-empty PUL? Can have immediate side-effects? Simple YES NO NO Updating YES YES NO Sequential YES NO YES XQSX xqsx http://www.w3.org/2008/xquery-sx-10 [ Definition query mode updating sequential expressions sequential simple sequential In particular, query mode affects the category rules for [6.3 Path Expressions] [6.4 Predicates] [6.7 FLWOR Expressions] [6.9 Quantified Expressions] 24 VarDecl ::= "declare" ("unassignable"? | "assignable") "variable" "$" QName TypeDeclaration ExprSingle XQSX assignable unassignable Definition assignable [5.3 Assignment Expression] unassignable The semantics of assignable variables are the same as the semantics of unassignable variables, except that the static type of an assignable variable without a declared type is always item()* The initializing expression of a prolog variable (whether assignable or not) must be a simple expression err:XUST0001 26 FunctionDecl ::= ("declare" ("simple"? | "updating") "function" QName ParamList SequenceType EnclosedExpr QName ParamList SequenceType Block Definitions: [ Definition simple function updating sequential simple function simple [ Definition updating function updating [ Definition sequential function sequential Category Rules: If the body of a simple function simple expression If the body of an updating function updating simple expression If the body of a sequential function sequential simple expression If the body of a function violates the category rules for it's declared category, [ err:SXST0008 Semantics: The semantics of simple functions [XQuery Update Facility] [XQuery 1.0] XQSX The semantics of updating functions [XQuery Update Facility] A return type is permitted. If external pending update list XDM instance If the result of an updating function Section 3.1.5 Function Calls XQ err:XPTY0004 XQ30 updating function item()* The semantics of sequential functions The result of a sequential function [5.5 Exit Expression] If the result of a sequential function Section 3.1.5 Function Calls XQ err:XPTY0004 XQ30 sequential function item()* If a sequential function external pending update list err:SXDY0004 13 OptionDecl ::= "declare" "option" QName StringLiteral XQSX xqsx:query-mode query mode err:SXST0009 xqsx:query-mode sequential simple Implementations of XQSX http://www.w3.org/2008/xquery-sx-10 xqsx:query-mode XQSX 31 Expr ::= ApplyExpr 32 ApplyExpr ::= ConcatExpr ConcatExpr 33 ConcatExpr ::= ExprSingle ExprSingle 34 ExprSingle ::= FLWORExpr QuantifiedExpr TypeswitchExpr IfExpr InsertExpr DeleteExpr RenameExpr ReplaceExpr TransformExpr BlockExpr AssignmentExpr ExitExpr WhileExpr OrExpr 32 ApplyExpr ::= ConcatExpr ConcatExpr Category Rules: [ Definition apply expression sequential expression The operands of the apply expression may be an expression of any category. Semantics: The operand expressions of an apply expression pending update list upd:applyUpdates XDM instance The result of the apply expression is the XDM instance pending update list 153 BlockExpr ::= "block" Block 154 Block ::= "{" BlockDecls BlockBody 155 BlockDecls ::= ( BlockVarDecl 156 BlockVarDecl ::= "declare" "$" VarName TypeDeclaration ExprSingle VarName TypeDeclaration ExprSingle 157 BlockBody ::= Expr Category Rules: [ Definition initializing expression Initializing expressions Note: Block variable declarations, unlike Prolog variable declarations, permit their initializing expressions updating sequential expressions If a BlockExpr contains initializing expressions updating sequential expression sequential expression simple sequential expression err:SXST0002 If a BlockExpr only contains initializing expressions simple expressions Semantics: A block consists of zero or more block variable declarations followed by a body. Each block variable declaration defines a modifiable local variable whose scope is the remainder of the block (not including its initializing expression It is a static error [ err:SXST0005 The type of each declared variable is added to in-scope variables static context item()* initializing expression initializing expression err:XPTY0004 XQ30 The block variable declarations are evaluated in the order written. The block variable declaration evaluates its initializing expression XDM instance variable values dynamic context pending update list upd:applyUpdates initializing expression variable values err:SXTY0006 After all the block variable declarations have been evaluated, the BlockBody expression is evaluated. The result of the block expression is the XDM instance pending update list 158 AssignmentExpr ::= "$" VarName ExprSingle Category Rules: An assignment expression is a sequential expression Semantics: The variable on the left-hand side of the assignment must have been declared in one of the following ways, otherwise a static error [ err:SXST0007 By a block variable declaration As a parameter to a sequential function By a variable declaration in the Prolog declared as assignable In all cases the variable must be in the in-scope variables, otherwise a static error is raised [ err:XPST0008 XQ30 Note: Variables bound in FLWOR, typeswitch, or quantified expressions may not appear on the left-hand side of an assignment. The expression on the right-hand side is evaluated, resulting in an XDM instance pending update list If the XDM instance err:XPTY0004 XQ30 XDM instance variable values dynamic context The pending update list upd:applyUpdates The result of an Assignment Expression is an empty XDM instance pending update list 160 WhileExpr ::= "while" "(" ExprSingle WhileBody 161 WhileBody ::= Block Category Rules: [ Definition test expression test expression A static error [ err:SXST0002 updating expression A while expression is a sequential expression Semantics: The while expression is used for conditional iteration. It is evaluated as follows: The test expression XDM instance pending update list pending update list test expression upd:applyUpdates If the effective Boolean value of the test expression test expression test expression test expression test expression The result of a while expression is an empty XDM instance pending update list Example: In the following query, a while expression is used to compute a sequence containing all the Fibonacci numbers that are less than 100. block { declare $a as xs:integer := 0; declare $b as xs:integer := 1; declare $c as xs:integer := $a + $b; declare $fibseq as xs:integer* := ($a, $b); while ($c < 100) { $fibseq := ($fibseq, $c); $a := $b; $b := $c; $c := $a + $b; };

$fibseq; } 159 ExitExpr ::= "exit" "returning" ExprSingle Category Rules: The operand of an exit expression may be an expression of any category. An exit expression is a sequential expression Semantics: An exit expression serves to define the result of the enclosing function or query body. The operand expression of the exit expression is evaluated, resulting in an XDM instance pending update list pending update list upd:applyUpdates If an exit expression is evaluated within the body of a function, further evaluation of the function body is interrupted and the XDM instance If an exit expression is evaluated within a query body (i.e., not within the body of a function), further evaluation of the query is interrupted and the XDM instance Note: An exit expression in a block terminates evaluation of the enclosing function body or query, not just the immediately enclosing block. 67 ExtensionExpr ::= Pragma Expr 68 Pragma ::= "(#" S QName S PragmaContents 69 PragmaContents ::= ( Char XQSX xqsx:query-mode query mode err:SXST0009 xqsx:query-mode sequential simple Implementations of XQSX http://www.w3.org/2008/xquery-sx-10 xqsx:query-mode XQSX [XQuery 1.0] [XQuery Update Facility] 91 ParenthesizedExpr ::= "(" Expr Category Rules: An expression of any category may be enclosed in parentheses; the resulting expression has the same category as the original expression. An empty parenthesized expression ( ) simple expression 95 FunctionCall ::= QName ExprSingle ExprSingle Category Rules: If the function called is a simple function simple updating expressions simple sequential expressions updating expression updating expression sequential expression sequential expression simple expression If the function called is an updating function simple expressions updating expressions updating expression If the function called is a sequential function simple expressions sequential expressions sequential expression If the arguments of a function call violate the category rules for the function's category, [ err:SXST0002 Evaluation Order: Argument expressions are evaluated from left to right, then the function is invoked. Additional Semantics: The pending update lists pending update list upd:mergeUpdates 70 PathExpr ::= ("/" RelativePathExpr RelativePathExpr RelativePathExpr 71 RelativePathExpr ::= StepExpr StepExpr Category Rules: The category of a path expression is determined by the following rules: If query mode simple err:XUST0001 updating sequential expression If any StepExpr in the RelativePathExpr is an updating expression updating simple expressions err:SXST0002 updating expression If any StepExpr in the RelativePathExpr is a sequential expression sequential simple expressions err:SXST0002 sequential expression Otherwise, the path expression is a simple expression Evaluation Order: StepExpr are evaluated in order from left to right. Additional Semantics: The pending update lists upd:mergeUpdates 73 AxisStep ::= ( ReverseStep ForwardStep PredicateList 83 FilterExpr ::= PrimaryExpr PredicateList 84 PredicateList ::= Predicate 85 Predicate ::= "[" Expr Category Rules: The category of a FilterExpr or AxisStep is determined by the following rules: If query mode simple err:XUST0001 updating sequential expression If either the primary expression or any predicate expression of a FilterExpr or AxisStep is an updating expression updating simple expressions err:SXST0002 updating expression If either the primary expression or any predicate expression of a FilterExpr or AxisStep is a sequential expression sequential simple expressions err:SXST0002 sequential expression Otherwise, the FilterExpr or AxisStep is a simple expression Evaluation Order: First the reverse step, forward step or primary expression is evaluated, then predicates are evaluated from left to right. Each predicate expression must be evaluated to completion before the next is evaluated. Additional Semantics: The pending update list pending update lists upd:mergeUpdates 33 ConcatExpr ::= ExprSingle ExprSingle Category Rules: The category of a concatenation expression is determined by the following rules: If any operand is an updating expression updating simple expressions err:SXST0002 updating expression If any operand is a sequential expression sequential simple expressions err:SXST0002 sequential expression Otherwise, the concatenation expression is a simple expression Evaluation Order: Operand expressions are evaluated once, from left to right. Side effects of each sequential operand expression are visible to subsequent operand expressions. Additional Semantics: The concatenation expression evaluates each of its operands and concatenates the resulting XDM instances pending update lists Pending update lists upd:mergeUpdates 98 DirElemConstructor ::= "<" QName DirAttributeList DirElemContent QName S 99 DirAttributeList ::= ( S QName S S DirAttributeValue 109 CDataSection ::= "<![CDATA[" CDataSectionContents 107 DirPIConstructor ::= "<?" PITarget S DirPIContents 105 DirCommentConstructor ::= "<!--" DirCommentContents 113 CompElemConstructor ::= "element" ( QName Expr ContentExpr 115 CompAttrConstructor ::= "attribute" ( QName Expr Expr 112 CompDocConstructor ::= "document" "{" Expr 116 CompTextConstructor ::= "text" "{" Expr 118 CompPIConstructor ::= "processing-instruction" ( NCName Expr Expr 117 CompCommentConstructor ::= "comment" "{" Expr Category Rules: The category of a node constructor is determined by the following rules: If any operand is an updating expression updating simple expressions err:SXST0002 updating expression If any operand is a sequential expression sequential simple expressions err:SXST0002 sequential expression Otherwise, the node constructor is a simple expression Evaluation Order: The name expression is evaluated (computed element/attribute/processing-instruction constructors only). The direct attribute constructors are evaluated from left to right (direct element constructors only). The child or value expressions are evaluated from left to right. Additional Semantics: The pending update lists upd:mergeUpdates 35 FLWORExpr ::= ( ForClause LetClause WhereClause OrderByClause ExprSingle 36 ForClause ::= "for" "$" VarName TypeDeclaration PositionalVar ExprSingle VarName TypeDeclaration PositionalVar ExprSingle 37 PositionalVar ::= "at" "$" VarName 38 LetClause ::= "let" "$" VarName TypeDeclaration ExprSingle VarName TypeDeclaration ExprSingle 39 WhereClause ::= "where" ExprSingle 40 OrderByClause ::= (("order" "by") | ("stable" "order" "by")) OrderSpecList 41 OrderSpecList ::= OrderSpec OrderSpec 42 OrderSpec ::= ExprSingle OrderModifier 43 OrderModifier ::= ("ascending" | "descending")? ("empty" ("greatest" | "least"))? ("collation" URILiteral Category Rules: The for let where order by simple updating expressions simple sequential expressions If query mode simple err:XUST0001 for let where order by updating sequential expression If the above clauses contain an updating expression simple expression updating expression err:SXST0002 updating expression If the above clauses contain a sequential expression simple expression sequential expression err:SXST0002 sequential expression If the above clauses do not contain an updating expression sequential expression return return Evaluation Order: For Clause: Let Clause: Where Clause: Order By Clause: Return Clause: Additional Semantics: The result of a FLWOR expression is the concatenation of the XDM instances pending update lists return pending update lists Pending update lists upd:mergeUpdates 47 IfExpr ::= "if" "(" Expr ExprSingle ExprSingle Category Rules: The test, then and else expressions can be of any type. An error [ err:SXST0002 updating sequential If the test, then or else expression is an updating expression updating expression If the test, then or else expression is a sequential expression sequential expression Otherise, the conditional expression is a simple expression Evaluation Order: The test expression is evaluated first. Next either the then expression or the else expression (but not both) is evaluated. Additional Semantics: The pending update list pending update lists upd:mergeUpdates 44 QuantifiedExpr ::= ("some" | "every") "$" VarName TypeDeclaration ExprSingle VarName TypeDeclaration ExprSingle ExprSingle Category Rules: The category of a quantified expression is determined by the following rules: If query mode simple err:XUST0001 updating sequential expression If any quantified expression clause or the satisfies expression is an updating expression updating simple expressions err:SXST0002 updating expression If any quantified expression clause or the satisfies expression is a sequential expression sequential simple expressions err:SXST0002 sequential expression Otherwise, the quantified expression is a simple expression Evaluation Order: The quantified expression clauses are initially evaluated as specified by [XQuery 1.0] Additional Semantics: The pending update list pending update lists upd:mergeUpdates 45 TypeswitchExpr ::= "typeswitch" "(" Expr CaseClause VarName ExprSingle Category Rules: The operand, case and default expressions can be of any type. An error [ err:SXST0002 updating sequential If an operand, case or default expression is an updating expression updating expression If an operand, case or default expression is a sequential expression sequential expression Otherise, the typeswitch expression is a simple expression Evaluation Order: The operand expression is evaluated first. Then, exactly one of the return expressions is evaluated. Additional Semantics: The pending update list pending update lists upd:mergeUpdates 145 InsertExpr ::= "insert" ("node" | "nodes") SourceExpr InsertExprTargetChoice TargetExpr 144 InsertExprTargetChoice ::= (("as" ("first" | "last"))? "into") 146 DeleteExpr ::= "delete" ("node" | "nodes") TargetExpr 147 ReplaceExpr ::= "replace" ("value" "of")? "node" TargetExpr ExprSingle 148 RenameExpr ::= "rename" "node" TargetExpr NewNameExpr 149 SourceExpr ::= ExprSingle 150 TargetExpr ::= ExprSingle 151 NewNameExpr ::= ExprSingle Category Rules: Insert, delete, replace, and rename expressions are updating expressions updating simple expressions err:SXST0002 sequential expression Evaluation Order: Order of evaluation for insert, delete, replace, and rename expressions is irrelevent since their operands cannot be sequential expressions. Additional Semantics: The pending update list pending update lists pending update list upd:mergeUpdates 152 TransformExpr ::= "copy" "$" VarName ExprSingle VarName ExprSingle ExprSingle ExprSingle Category Rules: The copy, modify and return clauses of a transform expression can be of any type. An error [ err:SXST0002 updating sequential If one of the copy or return clauses is an updating expression updating expression If one of the copy, modify or return clauses is a sequential expression sequential expression Otherise, the transform expression is a simple expression Evaluation Order: Copy clauses are evaluated in order, then the modify expression is evaluated. Finally the return clause is evaluated. Additional Semantics: The semantics of a transform expression as defined in Section 2.4.5 Transform XU If the modify clause returns a non-empty XDM instance The pending update list pending update lists upd:mergeUpdates All expressions not listed above are extended as follows. This includes the following kinds of expressions: Range expressions Union, intersect, and except expressions Arithmetic, comparison, and logical expressions Ordered and unordered expressions Instance of, cast, castable, and treat expressions Validate expressions Extension expressions (pragmas) Category Rules: All other expressions are extended to accept any type of expressions as their operands. An error [ err:SXST0002 updating sequential updating updating sequential sequential simple Evaluation Order: Operand expressions are evaluated once, from left to right. Additional Semantics: The pending update list pending update lists upd:mergeUpdates The following function returns true false declare sequential function validate-and-log($username as xs:string) as xs:boolean { declare $log as document-node() := fn:doc("log.xml"); declare $entry as element() := <access-attempt> <timestamp>{fn:current-dateTime()}</timestamp> <user-name>{$username}</user-name> <access-allowed/> </access-attempt> ; declare $result as xs:boolean; if ($username = doc("users.xml")/current-users/user/name ) then ( replace value of node $entry/access-allowed with "Yes"; $result := true(); ) else ( replace value of node $entry/access-allowed with "No"; $result := false(); ); insert node $entry as last into $log; fn:put($log, "log.xml"); exit returning $result; } The EBNF in this document and in this section is aligned with the current XML Query 1.0 grammar (see [XQuery 1.0] 1 Module ::= VersionDecl LibraryModule MainModule 2 VersionDecl ::= "xquery" "version" StringLiteral StringLiteral Separator 3 MainModule ::= Prolog QueryBody 4 LibraryModule ::= ModuleDecl Prolog 5 ModuleDecl ::= "module" "namespace" NCName URILiteral Separator 6 Prolog ::= (( DefaultNamespaceDecl Setter NamespaceDecl Import Separator VarDecl FunctionDecl OptionDecl Separator 7 Setter ::= BoundarySpaceDecl DefaultCollationDecl BaseURIDecl ConstructionDecl OrderingModeDecl EmptyOrderDecl RevalidationDecl CopyNamespacesDecl 8 Import ::= SchemaImport ModuleImport 9 Separator ::= ";" 10 NamespaceDecl ::= "declare" "namespace" NCName URILiteral 11 BoundarySpaceDecl ::= "declare" "boundary-space" ("preserve" | "strip") 12 DefaultNamespaceDecl ::= "declare" "default" ("element" | "function") "namespace" URILiteral 13 OptionDecl ::= "declare" "option" QName StringLiteral 14 OrderingModeDecl ::= "declare" "ordering" ("ordered" | "unordered") 15 EmptyOrderDecl ::= "declare" "default" "order" "empty" ("greatest" | "least") 16 CopyNamespacesDecl ::= "declare" "copy-namespaces" PreserveMode InheritMode 17 PreserveMode ::= "preserve" | "no-preserve" 18 InheritMode ::= "inherit" | "no-inherit" 19 DefaultCollationDecl ::= "declare" "default" "collation" URILiteral 20 BaseURIDecl ::= "declare" "base-uri" URILiteral 21 SchemaImport ::= "import" "schema" SchemaPrefix URILiteral URILiteral URILiteral 22 SchemaPrefix ::= ("namespace" NCName 23 ModuleImport ::= "import" "module" ("namespace" NCName URILiteral URILiteral URILiteral 24 VarDecl ::= "declare" ("unassignable"? | "assignable") "variable" "$" QName TypeDeclaration ExprSingle 25 ConstructionDecl ::= "declare" "construction" ("strip" | "preserve") 26 FunctionDecl ::= ("declare" ("simple"? | "updating") "function" QName ParamList SequenceType EnclosedExpr QName ParamList SequenceType Block 27 ParamList ::= Param Param 28 Param ::= "$" QName TypeDeclaration 29 EnclosedExpr ::= "{" Expr 30 QueryBody ::= Expr 31 Expr ::= ApplyExpr 32 ApplyExpr ::= ConcatExpr ConcatExpr 33 ConcatExpr ::= ExprSingle ExprSingle 34 ExprSingle ::= FLWORExpr QuantifiedExpr TypeswitchExpr IfExpr InsertExpr DeleteExpr RenameExpr ReplaceExpr TransformExpr BlockExpr AssignmentExpr ExitExpr WhileExpr OrExpr 35 FLWORExpr ::= ( ForClause LetClause WhereClause OrderByClause ExprSingle 36 ForClause ::= "for" "$" VarName TypeDeclaration PositionalVar ExprSingle VarName TypeDeclaration PositionalVar ExprSingle 37 PositionalVar ::= "at" "$" VarName 38 LetClause ::= "let" "$" VarName TypeDeclaration ExprSingle VarName TypeDeclaration ExprSingle 39 WhereClause ::= "where" ExprSingle 40 OrderByClause ::= (("order" "by") | ("stable" "order" "by")) OrderSpecList 41 OrderSpecList ::= OrderSpec OrderSpec 42 OrderSpec ::= ExprSingle OrderModifier 43 OrderModifier ::= ("ascending" | "descending")? ("empty" ("greatest" | "least"))? ("collation" URILiteral 44 QuantifiedExpr ::= ("some" | "every") "$" VarName TypeDeclaration ExprSingle VarName TypeDeclaration ExprSingle ExprSingle 45 TypeswitchExpr ::= "typeswitch" "(" Expr CaseClause VarName ExprSingle 46 CaseClause ::= "case" ("$" VarName SequenceType ExprSingle 47 IfExpr ::= "if" "(" Expr ExprSingle ExprSingle 48 OrExpr ::= AndExpr AndExpr 49 AndExpr ::= ComparisonExpr ComparisonExpr 50 ComparisonExpr ::= RangeExpr ValueComp GeneralComp NodeComp RangeExpr 51 RangeExpr ::= AdditiveExpr AdditiveExpr 52 AdditiveExpr ::= MultiplicativeExpr MultiplicativeExpr 53 MultiplicativeExpr ::= UnionExpr UnionExpr 54 UnionExpr ::= IntersectExceptExpr IntersectExceptExpr 55 IntersectExceptExpr ::= InstanceofExpr InstanceofExpr 56 InstanceofExpr ::= TreatExpr SequenceType 57 TreatExpr ::= CastableExpr SequenceType 58 CastableExpr ::= CastExpr SingleType 59 CastExpr ::= UnaryExpr SingleType 60 UnaryExpr ::= ("-" | "+")* ValueExpr 61 ValueExpr ::= ValidateExpr PathExpr ExtensionExpr 62 GeneralComp ::= "=" | "!=" | "<" | "<=" | ">" | ">=" 63 ValueComp ::= "eq" | "ne" | "lt" | "le" | "gt" | "ge" 64 NodeComp ::= "is" | "<<" | ">>" 65 ValidateExpr ::= "validate" ValidationMode Expr 66 ValidationMode ::= "lax" | "strict" 67 ExtensionExpr ::= Pragma Expr 68 Pragma ::= "(#" S QName S PragmaContents /* ws: explicit XQ 69 PragmaContents ::= ( Char 70 PathExpr ::= ("/" RelativePathExpr RelativePathExpr RelativePathExpr /* gn: leading-lone-slash XQ 71 RelativePathExpr ::= StepExpr StepExpr 72 StepExpr ::= FilterExpr AxisStep 73 AxisStep ::= ( ReverseStep ForwardStep PredicateList 74 ForwardStep ::= ( ForwardAxis NodeTest AbbrevForwardStep 75 ForwardAxis ::= ("child" "::") 76 AbbrevForwardStep ::= "@"? NodeTest 77 ReverseStep ::= ( ReverseAxis NodeTest AbbrevReverseStep 78 ReverseAxis ::= ("parent" "::") 79 AbbrevReverseStep ::= ".." 80 NodeTest ::= KindTest NameTest 81 NameTest ::= QName Wildcard 82 Wildcard ::= "*" NCName NCName /* ws: explicit XQ 83 FilterExpr ::= PrimaryExpr PredicateList 84 PredicateList ::= Predicate 85 Predicate ::= "[" Expr 86 PrimaryExpr ::= Literal VarRef ParenthesizedExpr ContextItemExpr FunctionCall OrderedExpr UnorderedExpr Constructor 87 Literal ::= NumericLiteral StringLiteral 88 NumericLiteral ::= IntegerLiteral DecimalLiteral DoubleLiteral 89 VarRef ::= "$" VarName 90 VarName ::= QName 91 ParenthesizedExpr ::= "(" Expr 92 ContextItemExpr ::= "." 93 OrderedExpr ::= "ordered" "{" Expr 94 UnorderedExpr ::= "unordered" "{" Expr 95 FunctionCall ::= QName ExprSingle ExprSingle /* gn: sx-reserved-function-names /* gn: parens XQ 96 Constructor ::= DirectConstructor ComputedConstructor 97 DirectConstructor ::= DirElemConstructor DirCommentConstructor DirPIConstructor 98 DirElemConstructor ::= "<" QName DirAttributeList DirElemContent QName S /* ws: explicit XQ 99 DirAttributeList ::= ( S QName S S DirAttributeValue /* ws: explicit XQ 100 DirAttributeValue ::= ('"' ( EscapeQuot QuotAttrValueContent EscapeApos AposAttrValueContent /* ws: explicit XQ 101 QuotAttrValueContent ::= QuotAttrContentChar CommonContent 102 AposAttrValueContent ::= AposAttrContentChar CommonContent 103 DirElemContent ::= DirectConstructor CDataSection CommonContent ElementContentChar 104 CommonContent ::= PredefinedEntityRef CharRef EnclosedExpr 105 DirCommentConstructor ::= "<!--" DirCommentContents /* ws: explicit XQ 106 DirCommentContents ::= (( Char Char /* ws: explicit XQ 107 DirPIConstructor ::= "<?" PITarget S DirPIContents /* ws: explicit XQ 108 DirPIContents ::= ( Char /* ws: explicit XQ 109 CDataSection ::= "<![CDATA[" CDataSectionContents /* ws: explicit XQ 110 CDataSectionContents ::= ( Char /* ws: explicit XQ 111 ComputedConstructor ::= CompDocConstructor CompElemConstructor CompAttrConstructor CompTextConstructor CompCommentConstructor CompPIConstructor 112 CompDocConstructor ::= "document" "{" Expr 113 CompElemConstructor ::= "element" ( QName Expr ContentExpr 114 ContentExpr ::= Expr 115 CompAttrConstructor ::= "attribute" ( QName Expr Expr 116 CompTextConstructor ::= "text" "{" Expr 117 CompCommentConstructor ::= "comment" "{" Expr 118 CompPIConstructor ::= "processing-instruction" ( NCName Expr Expr 119 SingleType ::= AtomicType 120 TypeDeclaration ::= "as" SequenceType 121 SequenceType ::= ("empty-sequence" "(" ")") ItemType OccurrenceIndicator 122 OccurrenceIndicator ::= "?" | "*" | "+" /* gn: occurrence-indicators XQ 123 ItemType ::= KindTest AtomicType 124 AtomicType ::= QName 125 KindTest ::= DocumentTest ElementTest AttributeTest SchemaElementTest SchemaAttributeTest PITest CommentTest TextTest AnyKindTest 126 AnyKindTest ::= "node" "(" ")" 127 DocumentTest ::= "document-node" "(" ( ElementTest SchemaElementTest 128 TextTest ::= "text" "(" ")" 129 CommentTest ::= "comment" "(" ")" 130 PITest ::= "processing-instruction" "(" ( NCName StringLiteral 131 AttributeTest ::= "attribute" "(" ( AttribNameOrWildcard TypeName 132 AttribNameOrWildcard ::= AttributeName 133 SchemaAttributeTest ::= "schema-attribute" "(" AttributeDeclaration 134 AttributeDeclaration ::= AttributeName 135 ElementTest ::= "element" "(" ( ElementNameOrWildcard TypeName 136 ElementNameOrWildcard ::= ElementName 137 SchemaElementTest ::= "schema-element" "(" ElementDeclaration 138 ElementDeclaration ::= ElementName 139 AttributeName ::= QName 140 ElementName ::= QName 141 TypeName ::= QName 142 URILiteral ::= StringLiteral 143 RevalidationDecl ::= "declare" "revalidation" ("strict" | "lax" | "skip") 144 InsertExprTargetChoice ::= (("as" ("first" | "last"))? "into") 145 InsertExpr ::= "insert" ("node" | "nodes") SourceExpr InsertExprTargetChoice TargetExpr 146 DeleteExpr ::= "delete" ("node" | "nodes") TargetExpr 147 ReplaceExpr ::= "replace" ("value" "of")? "node" TargetExpr ExprSingle 148 RenameExpr ::= "rename" "node" TargetExpr NewNameExpr 149 SourceExpr ::= ExprSingle 150 TargetExpr ::= ExprSingle 151 NewNameExpr ::= ExprSingle 152 TransformExpr ::= "copy" "$" VarName ExprSingle VarName ExprSingle ExprSingle ExprSingle 153 BlockExpr ::= "block" Block 154 Block ::= "{" BlockDecls BlockBody 155 BlockDecls ::= ( BlockVarDecl 156 BlockVarDecl ::= "declare" "$" VarName TypeDeclaration ExprSingle VarName TypeDeclaration ExprSingle 157 BlockBody ::= Expr 158 AssignmentExpr ::= "$" VarName ExprSingle 159 ExitExpr ::= "exit" "returning" ExprSingle 160 WhileExpr ::= "while" "(" ExprSingle WhileBody 161 WhileBody ::= Block 162 IntegerLiteral ::= Digits 163 DecimalLiteral ::= ("." Digits Digits /* ws: explicit XQ 164 DoubleLiteral ::= (("." Digits Digits Digits /* ws: explicit XQ 165 StringLiteral ::= ('"' ( PredefinedEntityRef CharRef EscapeQuot PredefinedEntityRef CharRef EscapeApos /* ws: explicit XQ 166 PredefinedEntityRef ::= "&" ("lt" | "gt" | "amp" | "quot" | "apos") ";" /* ws: explicit XQ 167 EscapeQuot ::= '""' 168 EscapeApos ::= "''" 169 ElementContentChar ::= Char 170 QuotAttrContentChar ::= Char 171 AposAttrContentChar ::= Char 172 Comment ::= "(:" ( CommentContents Comment /* ws: explicit XQ /* gn: comments XQ 173 PITarget ::= [http://www.w3.org/TR/REC-xml#NT-PITarget] XML /* gn: xml-version XQ 174 CharRef ::= [http://www.w3.org/TR/REC-xml#NT-CharRef] XML /* gn: xml-version XQ 175 QName ::= [http://www.w3.org/TR/REC-xml-names/#NT-QName] Names /* gn: xml-version XQ 176 NCName ::= [http://www.w3.org/TR/REC-xml-names/#NT-NCName] Names /* gn: xml-version XQ 177 S ::= [http://www.w3.org/TR/REC-xml#NT-S] XML /* gn: xml-version XQ 178 Char ::= [http://www.w3.org/TR/REC-xml#NT-Char] XML /* gn: xml-version XQ 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 Scripting Extensions] 179 Digits ::= [0-9]+ 180 CommentContents ::= ( Char This section contains XQuery SX specific constraints on the EBNF productions, which are required to parse legal sentences. The notes below are referenced from the right side of the production, with the notation: /* gn: <id> */ Constraint: sx-reserved-function-names XQuery SX adds the term "while" to the list of names in Section A.3 Reserved Function Names XQ Note: This is a backwards incompatibility with [XQuery 1.0] [XML Syntax for XQuery 1.0] [XQuery 1.0] [XQuery Scripting Requirements] [A EBNF for XQuery 1.0 Grammar with Scripting Extensions] The XML Schema specified in this appendix accomplishes its integration by importing the XML Schema defined for XQueryX in [XQuery Update Facility] This section specifies the XML Schema that defines the complex types and elements for XQueryX in support of XQuery Scripting Extension 1.0, including changes to the prolog and the addition of several new expressions. It also specifies a second XML Schema that redefines an element defined in XQueryX 1.0. Copies of these two schemata can be found at http://www.w3.org/2008/xquery-sx-10/xquery-sx-10-xqueryx.xsd http://www.w3.org/2008/xquery-sx-10/xquery-sx-10-xqueryx-redef.xsd <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xqx="http://www.w3.org/2005/XQueryX" xmlns:xqxuf="http://www.w3.org/2007/xquery-update-10" xmlns:xqxsx="http://www.w3.org/2008/xquery-sx-10" targetNamespace="http://www.w3.org/2008/xquery-sx-10" elementFormDefault="qualified" attributeFormDefault="unqualified">

<!-- Initial creation 2008-03-01: Jim Melton --> <!-- Added FunctionDecl redefinition 2008-03-11: Jim Melton --> <!-- Updated to new WD grammar 2008-11-25: Jim Melton --> <!-- Reviewed, cleaned, corrections 2009-08-17: Jim Melton --> <!-- Updated to recent grammar changes 2010-02-15: Jim Melton --> <xsd:import namespace="http://www.w3.org/2007/xquery-update-10" schemaLocation="http://www.w3.org/2008/xquery-sx-10/xquery-sx-10-xqueryx-redef.xsd"/> <xsd:import namespace="http://www.w3.org/2005/XQueryX"/>

<!-- Declare new type for constant declarations --> <!-- Corresponds to the following grammar productions: --> <!-- VarDecl ::= "declare" ([un]assignable variable) --> <!-- "$" QName TypeDeclaration? --> <!-- ((":=" ExprSingle) | "external") --> <xsd:complexType name="constDecl"> <xsd:sequence> <xsd:element name="constName" type="xqx:QName"/> <xsd:element ref="xqx:typeDeclaration" minOccurs="0"/> <xsd:choice> <xsd:element name="varValue" type="xqx:exprWrapper"/> <xsd:element name="external" type="xqx:emptyContent"/> </xsd:choice> </xsd:sequence> </xsd:complexType>

<xsd:element name="constDecl" type="xqxsx:constDecl" substitutionGroup="xqx:prologPartTwoItem"/>

<!-- Create substitution grp for scripting extension exprs --> <xsd:complexType name="expr"> <xsd:complexContent> <xsd:extension base="xqxuf:expr"/> </xsd:complexContent> </xsd:complexType>

<!-- Make scripting extension subst grp part of expr grp --> <xsd:element name="expr" type="xqxsx:expr" abstract="true" substitutionGroup="xqxuf:expr"/>

<!-- AssignmentExpr: --> <!-- AssignmentExpr ::= "$" VarName ":=" ExprSingle --> <xsd:complexType name="assignmentExpr"> <xsd:complexContent> <xsd:extension base="xqxsx:expr"> <xsd:sequence> <xsd:element ref="xqx:positionalVariableBinding"/> <xsd:element name="assignedExpr" type="xqx:exprWrapper"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType>

<xsd:element name="assignmentExpr" type="xqxsx:assignmentExpr" substitutionGroup="xqxsx:expr"/>

<!-- Block (1 of 3): --> <!-- BlockExpr ::= "block" Block --> <!-- Block ::= "{" BlockDecls BlockBody "}" --> <!-- BlockDecls ::= (BlockVarDecl ";")* --> <xsd:complexType name="block"> <xsd:complexContent> <xsd:extension base="xqxsx:expr"> <xsd:sequence> <xsd:element ref="xqxsx:blockVarDecl" minOccurs="0" maxOccurs="unbounded"/> <xsd:element ref="xqxsx:blockBody"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType>

<xsd:element name="block" type="xqxsx:block" substitutionGroup="xqxsx:expr"/>

<!-- Block (2 of 3): --> <!-- BlockVarDecl ::= --> <!-- "declare" "$" VarName TypeDeclaration? --> <!-- (":=" ExprSingle)? --> <!-- ("," "$" VarName TypeDeclaration? --> <!-- (":=" ExprSingle)? )* --> <xsd:complexType name="blockVarDecl"> <xsd:sequence minOccurs="1" maxOccurs="unbounded"> <xsd:element name="varName" type="xqx:QName"/> <xsd:element ref="xqx:typeDeclaration" minOccurs="0"/> <xsd:element name="varValue" type="xqx:exprWrapper" minOccurs="0"/> </xsd:sequence> </xsd:complexType>

<xsd:element name="blockVarDecl" type="xqxsx:blockVarDecl"/>

<!-- Block (3 of 3): --> <!-- BlockBody ::= Expr --> <xsd:complexType name="blockBody"> <xsd:sequence> <xsd:element ref="xqxsx:applyExpr"/> </xsd:sequence> </xsd:complexType>

<xsd:element name="blockBody" type="xqxsx:blockBody"/>

<!-- ExitExpr: --> <!-- ExitExpr ::= "exit" "returning" ExprSingle --> <xsd:complexType name="exitExpr"> <xsd:complexContent> <xsd:extension base="xqx:expr"> <xsd:sequence> <xsd:element ref="xqx:expr"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType>

<xsd:element name="exitExpr" type="xqxsx:exitExpr" substitutionGroup="xqx:expr"/>

<!-- WhileExpr: --> <!-- WhileExpr ::= "while" "(" ExprSingle ")" WhileBody --> <!-- WhileBody ::= Block --> <xsd:complexType name="whileExpr"> <xsd:complexContent> <xsd:extension base="xqxsx:expr"> <xsd:sequence> <xsd:element name="whileTest" type="xqx:exprWrapper"/> <xsd:element ref="xqxsx:block"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType>

<xsd:element name="whileExpr" type="xqxsx:whileExpr" substitutionGroup="xqxsx:expr"/>

<!-- ApplyExpr: --> <!-- ApplyExpr ::= (ConcatExpr ";")+ --> <xsd:complexType name="applyExpr"> <xsd:complexContent> <xsd:extension base="xqxsx:expr"> <xsd:sequence> <xsd:element name="concatExpr" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element ref="xqx:expr" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType>

<xsd:element name="applyExpr" type="xqxsx:applyExpr" substitutionGroup="xqxsx:expr"/>

</xsd:schema>

<?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xqx="http://www.w3.org/2005/XQueryX" xmlns:xqxuf="http://www.w3.org/2007/xquery-update-10" targetNamespace="http://www.w3.org/2007/xquery-update-10" elementFormDefault="qualified" attributeFormDefault="qualified">

<!-- Redefine one or more components of the XQueryX XML Schema --> <!-- The redefinition starts with XQuery Update Facility 1.0 --> <!-- XQueryX instead of XQueryX 1.0 --> <xsd:redefine schemaLocation="http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsd">

<!-- Redefine the functionDecl complex type --> <xsd:complexType name="functionDecl"> <xsd:complexContent> <xsd:extension base="functionDecl"> <xsd:attribute name="simpleFunction" type="xsd:boolean" default="true"/> <xsd:attribute name="updatingFunction" type="xsd:boolean" default="false"/> <xsd:attribute name="sequentialFunction" type="xsd:boolean" default="false"/> </xsd:extension> </xsd:complexContent> </xsd:complexType>

</xsd:redefine>

</xsd:schema> This section specifies the XSLT stylesheet that defines the semantics of XQueryX in support of XQuery Scripting Extension 1.0. It imports the XSLT stylesheet defined in [XQuery Update Facility] http://www.w3.org/2008/xquery-sx-10/xquery-sx-10-xqueryx.xsl <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xqx="http://www.w3.org/2005/XQueryX" xmlns:xqxuf="http://www.w3.org/2007/xquery-update-10" xmlns:xqxsx="http://www.w3.org/2008/xquery-sx-10">

<!-- Initial creation 2008-03-01: Jim Melton --> <!-- Reviewed, cleaned, corrections 2009-08-17: Jim Melton --> <!-- Updated to recent grammar changes 2010-02-15: Jim Melton -->

<xsl:import href="http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsl"/>

<!-- constDecl --> <!-- 2010-02-15: "constant" is now "unassignable variable" --> <xsl:template match="xqxsx:constDecl"> <xsl:value-of select="$NEWLINE"/> <xsl:text>declare unassignable variable </xsl:text> <xsl:apply-templates/> </xsl:template>

<xsl:template match="xqxsx:constName"> <xsl:apply-templates/> </xsl:template>

<!-- Over-ride the template for varDecl in XQueryX.xsd --> <!-- 2010-02-15: "variable" is now "assignable variable" --> <xsl:template match="xqx:varDecl" priority="200"> <xsl:text>declare assignable variable </xsl:text> <xsl:value-of select="$DOLLAR"/> <xsl:apply-templates select="xqx:varName"/> <xsl:apply-templates select="xqx:typeDeclaration"/> <xsl:if test="xqx:external"> <xsl:text> external </xsl:text> </xsl:if> <xsl:if test="xqx:varValue"> <xsl:value-of select="$ASSIGN"/> <xsl:apply-templates select="xqx:varValue"/> </xsl:if> </xsl:template>

<!-- assignmentExpr --> <!-- 2010-02-15: Remove 'set' keyword --> <xsl:template match="xqxsx:assignmentExpr"> <xsl:value-of select="$NEWLINE"/> <xsl:apply-templates select="xqx:positionalVariableBinding"/> <xsl:text> := </xsl:text> <xsl:apply-templates/> </xsl:template>

<xsl:template match="xqxsx:assignedExpr"> <xsl:apply-templates/> </xsl:template>

<!-- block --> <!-- 2010-02-15: Added 'block' keyword --> <xsl:template match="xqxsx:block"> <xsl:value-of select="$NEWLINE"/> <xsl:text>block </xsl:text> <xsl:value-of select="$LBRACE"/> <xsl:value-of select="$SPACE"/> <xsl:apply-templates/> <xsl:value-of select="$SPACE"/> <xsl:value-of select="$RBRACE"/> <xsl:value-of select="$SPACE"/> </xsl:template>

<!-- blockVarDecl --> <xsl:template match="xqxsx:blockVarDecl[position()=1 and position()=last()]"> <xsl:text>declare </xsl:text> <xsl:apply-templates select="xqxsx:varName"/> <xsl:if test="xqx:typeDeclaration"> <xsl:apply-templates select="xqx:typeDeclaration"/> </xsl:if> <xsl:if test="xqxsx:varValue"> <xsl:text> := </xsl:text> <xsl:apply-templates select="xqxsx:varValue"/> </xsl:if> <xsl:value-of select="$SEMICOLON"/> </xsl:template>

<xsl:template match="xqxsx:blockVarDecl[position()=1 and position()!=last()]"> <xsl:text>declare </xsl:text> <xsl:apply-templates select="xqxsx:varName"/> <xsl:if test="xqx:typeDeclaration"> <xsl:apply-templates select="xqx:typeDeclaration"/> </xsl:if> <xsl:if test="xqxsx:varValue"> <xsl:text> := </xsl:text> <xsl:apply-templates select="xqxsx:varValue"/> </xsl:if> </xsl:template>

<xsl:template match="xqxsx:blockVarDecl[position()>1 and position()&lt;last()]"> <xsl:value-of select="$COMMA"/> <xsl:value-of select="$NEWLINE"/> <xsl:apply-templates select="xqxsx:varName"/> <xsl:if test="xqx:typeDeclaration"> <xsl:apply-templates select="xqx:typeDeclaration"/> </xsl:if> <xsl:if test="xqxsx:varValue"> <xsl:text> := </xsl:text> <xsl:apply-templates select="xqxsx:varValue"/> </xsl:if> </xsl:template>

<xsl:template match="xqxsx:blockVarDecl[position()>1 and position()=last()]"> <xsl:value-of select="$COMMA"/> <xsl:value-of select="$NEWLINE"/> <xsl:apply-templates select="xqxsx:varName"/> <xsl:if test="xqx:typeDeclaration"> <xsl:apply-templates select="xqx:typeDeclaration"/> </xsl:if> <xsl:if test="xqxsx:varValue"> <xsl:text> := </xsl:text> <xsl:apply-templates select="xqxsx:varValue"/> </xsl:if> <xsl:value-of select="$SEMICOLON"/> </xsl:template>

<xsl:template match="xqxsx:varName"> <xsl:apply-templates/> </xsl:template>

<xsl:template match="xqxsx:varValue"> <xsl:apply-templates/> </xsl:template>

<!-- blockBody --> <xsl:template match="xqxsx:blockBody"> <xsl:apply-templates/> </xsl:template>

<xsl:template match="xqxsx:blockExpr"> <xsl:apply-templates/> </xsl:template>

<!-- exitExpr --> <xsl:template match="xqxsx:exitExpr"> <xsl:value-of select="$NEWLINE"/> <xsl:text>exit returning </xsl:text> <xsl:apply-templates/> </xsl:template>

<!-- whileExpr --> <xsl:template match="xqxsx:whileExpr"> <xsl:value-of select="$NEWLINE"/> <xsl:text>while </xsl:text> <xsl:value-of select="$LPAREN"/> <xsl:value-of select="$SPACE"/> <xsl:apply-templates select="xqxsx:whileTest"/> <xsl:value-of select="$SPACE"/> <xsl:value-of select="$RPAREN"/> <xsl:value-of select="$NEWLINE"/> <xsl:apply-templates select="xqxsx:block"/> <xsl:value-of select="$NEWLINE"/> </xsl:template>

<xsl:template match="xqxsx:whileTest"> <xsl:apply-templates/> </xsl:template>

<!-- applyExpr --> <xsl:template match="xqxsx:applyExpr"> <xsl:value-of select="$NEWLINE"/> <xsl:apply-templates select="xqxsx:concatExpr"/> <xsl:value-of select="$NEWLINE"/> </xsl:template>

<xsl:template match="xqxsx:concatExpr"> <xsl:apply-templates/> <xsl:value-of select="$SEMICOLON"/> </xsl:template>

<!-- Over-ride the template for functionDecl in XQuery --> <!-- Update Facility xquery-update-10-xqueryx.xsl --> <xsl:template match="xqx:functionDecl" priority="200"> <xsl:text>declare </xsl:text> <xsl:choose> <xsl:when test="@xqx:updatingFunction and @xqx:updatingFunction = 'true'"> <xsl:text>updating </xsl:text> </xsl:when> <xsl:when test="@xqx:sequentialFunction and @xqx:sequentialFunction = 'true'"> <xsl:text>sequential </xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>simple </xsl:text> </xsl:otherwise> </xsl:choose> <xsl:text>function </xsl:text> <xsl:apply-templates select="xqx:functionName"/> <xsl:apply-templates select="xqx:paramList"/> <xsl:apply-templates select="xqx:typeDeclaration"/> <xsl:apply-templates select="xqx:functionBody"/> <xsl:if test="xqx:externalDefinition"> <xsl:text> external </xsl:text> </xsl:if> </xsl:template>

</xsl:stylesheet> The following example is based on the data and queries in the use cases in [XQuery Scripting Use Cases] [XQuery Scripting Use Cases] [B.2 Stylesheet] a Comparison of the results of the Scripting Extension XQueryX-to-XQuery Scripting Extension transformation given in this document with the XQuery Scripting Extension solutions in [XQuery Scripting Use Cases] The XQuery Scripting Extension Use Cases solution given for each example is provided only to assist readers of this document in understanding the Scripting Extension XQueryX solution. There is no intent to imply that this document specifies a "compilation" or "transformation" of XQuery Scripting Extension syntax into Scripting Extension 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 Scripting Extension XQueryX documents and XQuery Scripting Extension expressions for readability. That additional white space is not produced by the Scripting Extension XQueryX-to-XQuery Scripting Extension transformation. This example is based on query "Q2" from [XQuery Scripting Use Cases] let $uid := doc("users.xml")/users/user_tuple[name = "Roger Smith"]/userid let $topbid := max(doc("bids.xml")/bids/bid_tuple[itemno = 1007]/bid) let $newbid := $topbid * 1.1 return if($newbid <= 240) then block { insert nodes <bid_tuple> <userid>{ data($uid) }</userid> <itemno>1002</itemno> <bid>{ $newbid }</bid> <bid_date>1999-03-03</bid_date> </bid_tuple> into doc("bids.xml")/bids; exit returning <new_bid>{ $newbid }</new_bid>; } else block { exit returning <top_bid>{ $topbid }</top_bid>; } <!-- let $uid := doc("users.xml")/users/user_tuple[name = "Roger Smith"]/userid let $topbid := max(doc("bids.xml")/bids/bid_tuple[itemno = 1007]/bid) let $newbid := $topbid * 1.1 return if($newbid <= 240) then { insert nodes <bid_tuple> <userid>{ data($uid) }</userid> <itemno>1002</itemno> <bid>{ $newbid }</bid> <bid_date>1999-03-03</bid_date> </bid_tuple> into doc("bids.xml")/bids; exit returning <new_bid>{ $newbid }</new_bid>; } else { exit returning <top_bid>{ $topbid }</top_bid>; } --> <xqx:module xmlns:xqx="http://www.w3.org/2005/XQueryX" xmlns:xqxuf="http://www.w3.org/2007/xquery-update-10" xmlns:xqxsx="http://www.w3.org/2008/xquery-sx-10" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2005/XQueryX http://www.w3.org/2005/XQueryX/xqueryx.xsd http://www.w3.org/2007/xquery-update-10 http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsd http://www.w3.org/2008/xquery-sx-10 http://www.w3.org/2008/xquery-sx-10/xquery-sx-10-xqueryx.xsd">

<xqx:mainModule> <xqx:queryBody> <xqx:flworExpr> <!-- let $uid := doc("users.xml")/users/user_tuple[name = "Roger Smith"]/userid --> <xqx:letClause> <xqx:letClauseItem> <xqx:typedVariableBinding> <xqx:varName>uid</xqx:varName> </xqx:typedVariableBinding> <xqx:letExpr> <xqx:pathExpr> <xqx:stepExpr> <xqx:filterExpr> <xqx:functionCallExpr> <xqx:functionName xqx:prefix="fn">doc</xqx:functionName> <xqx:arguments> <xqx:stringConstantExpr> <xqx:value>users.xml</xqx:value> </xqx:stringConstantExpr> </xqx:arguments> </xqx:functionCallExpr> </xqx:filterExpr> </xqx:stepExpr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:nameTest>users</xqx:nameTest> </xqx:stepExpr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:nameTest>user-tuple</xqx:nameTest> <xqx:predicates> <xqx:equalOp> <xqx:firstOperand> <xqx:pathExpr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:nameTest>name</xqx:nameTest> </xqx:stepExpr> </xqx:pathExpr> </xqx:firstOperand> <xqx:secondOperand> <xqx:stringConstantExpr> <xqx:value>Roger Smith</xqx:value> </xqx:stringConstantExpr> </xqx:secondOperand> </xqx:equalOp> </xqx:predicates> </xqx:stepExpr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:nameTest>userid</xqx:nameTest> </xqx:stepExpr> </xqx:pathExpr> </xqx:letExpr> </xqx:letClauseItem> </xqx:letClause> <!-- let $topbid := max(doc("bids.xml")/bids/bid_tuple[itemno = 1007]/bid) --> <xqx:letClause> <xqx:letClauseItem> <xqx:typedVariableBinding> <xqx:varName>topbid</xqx:varName> </xqx:typedVariableBinding> <xqx:letExpr> <xqx:pathExpr> <xqx:stepExpr> <xqx:filterExpr> <xqx:functionCallExpr> <xqx:functionName xqx:prefix="fn">max</xqx:functionName> <xqx:arguments> <xqx:pathExpr> <xqx:stepExpr> <xqx:filterExpr> <xqx:functionCallExpr> <xqx:functionName xqx:prefix="fn">doc</xqx:functionName> <xqx:arguments> <xqx:stringConstantExpr> <xqx:value>bids.xml</xqx:value> </xqx:stringConstantExpr> </xqx:arguments> </xqx:functionCallExpr> </xqx:filterExpr> </xqx:stepExpr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:nameTest>bids</xqx:nameTest> </xqx:stepExpr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:nameTest>bid-tuple</xqx:nameTest> <xqx:predicates> <xqx:equalOp> <xqx:firstOperand> <xqx:pathExpr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:nameTest>itemno</xqx:nameTest> </xqx:stepExpr> </xqx:pathExpr> </xqx:firstOperand> <xqx:secondOperand> <xqx:integerConstantExpr> <xqx:value>1007</xqx:value> </xqx:integerConstantExpr> </xqx:secondOperand> </xqx:equalOp> </xqx:predicates> </xqx:stepExpr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:nameTest>bid</xqx:nameTest> </xqx:stepExpr> </xqx:pathExpr> </xqx:arguments> </xqx:functionCallExpr> </xqx:filterExpr> </xqx:stepExpr> </xqx:pathExpr> </xqx:letExpr> </xqx:letClauseItem> </xqx:letClause> <!-- let $newbid := $topbid * 1.1 --> <xqx:letClause> <xqx:letClauseItem> <xqx:typedVariableBinding> <xqx:varName>newbid</xqx:varName> </xqx:typedVariableBinding> <xqx:letExpr> <xqx:multiplyOp> <xqx:firstOperand> <xqx:varRef> <xqx:name>topbid</xqx:name> </xqx:varRef> </xqx:firstOperand> <xqx:secondOperand> <xqx:decimalConstantExpr> <xqx:value>1.1</xqx:value> </xqx:decimalConstantExpr> </xqx:secondOperand> </xqx:multiplyOp> </xqx:letExpr> </xqx:letClauseItem> </xqx:letClause> <!-- return --> <xqx:returnClause> <!-- if($newbid <= 240) --> <xqx:ifThenElseExpr> <xqx:ifClause> <xqx:lessThanOrEqualOp> <xqx:firstOperand> <xqx:varRef> <xqx:name>newbid</xqx:name> </xqx:varRef> </xqx:firstOperand> <xqx:secondOperand> <xqx:integerConstantExpr> <xqx:value>240</xqx:value> </xqx:integerConstantExpr> </xqx:secondOperand> </xqx:lessThanOrEqualOp> </xqx:ifClause> <!-- then { --> <xqx:thenClause> <xqxsx:block> <xqxsx:blockBody> <xqxsx:applyExpr> <xqxsx:concatExpr> <!-- insert nodes --> <xqxuf:insertExpr> <xqxuf:sourceExpr> <!-- <bid_tuple> --> <xqx:elementConstructor> <xqx:tagName>bid_tuple</xqx:tagName> <xqx:elementContent> <!-- <userid>{ data($uid) }</userid> --> <xqx:elementConstructor> <xqx:tagName>userid</xqx:tagName> <xqx:elementContent> <xqx:functionCallExpr> <xqx:functionName xqx:prefix="fn">data</xqx:functionName> <xqx:arguments> <xqx:varRef> <xqx:name>uid</xqx:name> </xqx:varRef> </xqx:arguments> </xqx:functionCallExpr> </xqx:elementContent> </xqx:elementConstructor> <!-- <itemno>1002</itemno> --> <xqx:elementConstructor> <xqx:tagName>itemno</xqx:tagName> <xqx:elementContent> <xqx:integerConstantExpr> <xqx:value>1002</xqx:value> </xqx:integerConstantExpr> </xqx:elementContent> </xqx:elementConstructor> <!-- <bid>{ $newbid }</bid> --> <xqx:elementConstructor> <xqx:tagName>bid</xqx:tagName> <xqx:elementContent> <xqx:varRef> <xqx:name>newbid</xqx:name> </xqx:varRef> </xqx:elementContent> </xqx:elementConstructor> <!-- <bid_date>1999-03-03</bid_date> --> <xqx:elementConstructor> <xqx:tagName>bid_date</xqx:tagName> <xqx:elementContent> <xqx:stringConstantExpr> <xqx:value>1999-03-03</xqx:value> </xqx:stringConstantExpr> </xqx:elementContent> </xqx:elementConstructor> </xqx:elementContent> </xqx:elementConstructor> </xqxuf:sourceExpr> <!-- into doc("bids.xml")/bids; --> <xqxuf:insertInto/> <xqxuf:targetExpr> <xqx:pathExpr> <xqx:stepExpr> <xqx:filterExpr> <xqx:functionCallExpr> <xqx:functionName xqx:prefix="fn">doc</xqx:functionName> <xqx:arguments> <xqx:stringConstantExpr> <xqx:value>bids.xml</xqx:value> </xqx:stringConstantExpr> </xqx:arguments> </xqx:functionCallExpr> </xqx:filterExpr> </xqx:stepExpr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:nameTest>bids</xqx:nameTest> </xqx:stepExpr> </xqx:pathExpr> </xqxuf:targetExpr> </xqxuf:insertExpr> </xqxsx:concatExpr> <!-- exit returning <new_bid>{ $newbid }</new_bid>; --> <xqxsx:concatExpr> <xqxsx:exitExpr> <xqx:elementConstructor> <xqx:tagName>new_bid</xqx:tagName> <xqx:elementContent> <xqx:varRef> <xqx:name>newbid</xqx:name> </xqx:varRef> </xqx:elementContent> </xqx:elementConstructor> </xqxsx:exitExpr> </xqxsx:concatExpr> </xqxsx:applyExpr> </xqxsx:blockBody> </xqxsx:block> </xqx:thenClause> <!-- } else { --> <xqx:elseClause> <!-- exit returning <top_bid>{ $topbid }</top_bid>; --> <xqxsx:block> <xqxsx:blockBody> <xqxsx:applyExpr> <xqxsx:concatExpr> <xqxsx:exitExpr> <xqx:elementConstructor> <xqx:tagName>top_bid</xqx:tagName> <xqx:elementContent> <xqx:varRef> <xqx:name>topbid</xqx:name> </xqx:varRef> </xqx:elementContent> </xqx:elementConstructor> </xqxsx:exitExpr> </xqxsx:concatExpr> </xqxsx:applyExpr> </xqxsx:blockBody> </xqxsx:block> </xqx:elseClause> </xqx:ifThenElseExpr> </xqx:returnClause> <!-- } --> </xqx:flworExpr> </xqx:queryBody> </xqx:mainModule> </xqx:module> Application of the stylesheet in [B.2 Stylesheet] ( let $uid:=fn:doc("users.xml")/child::users/ child::user-tuple[(child::name = "Roger Smith")]/ child::userid let $topbid:=fn:max(fn:doc("bids.xml")/ child::bids/child::bid-tuple[(child::itemno = 1007)]/ child::bid) let $newbid:=($topbid*1.1) return ( if (($newbid <= 240)) then block { insert nodes <bid_tuple> <userid>{fn:data($uid)}</userid> <itemno>{1002}</itemno> <bid>{$newbid}</bid> <bid_date>{"1999-03-03"}</bid_date> </bid_tuple> into fn:doc("bids.xml")/child::bids; exit returning <new_bid>{$newbid}</new_bid>; } else block { exit returning <top_bid>{$topbid}</top_bid>; } ) ) The following items in this specification are implementation-defined: The effects of snapshot semantics fn:put fn:doc fn:doc-available fn:collection snapshot The mechanism (if any) by which the XQuery environment exchanges parameters and results with an external function. XQuery 1.0: An XML Query Language XML Syntax for XQuery 1.0 XQuery 1.0 and XPath 2.0 Data Model (XDM) XQuery 1.0 and XPath 2.0 Functions and Operators XQuery Update Facility 1.0 XQuery Scripting Extension 1.0 Requirements XQuery Scripting Extension 1.0 Use Cases XQuery 1.1: An XML Query Language It is a static error to mix both updating sequential It is a dynamic error if, after applying a pending update list (using upd:applyUpdates It is an dynamic error for an external sequential function to return a non-empty pending update list It is a static error if two or more variables declared in the same block expression have the same expanded QName. A reference to a variable, other than on the left-hand side of an assignment expression, is an error if the variable has no value in variable values The variable on the left-hand side of an assignment must have been declared in one of the following ways: By a block variable declaration As a parameter to a sequential function By a variable declaration in the Prolog declared as assignable It is a static error if the body of a function violates the category rules for it's declared category. A static error is raised if the value for a xqsx:query-mode sequential simple It is a static error for an updating sequential expression As the initializing expression of a prolog variable. As a StepExpr in a RelativePathExpr when query mode simple As the primary expression or a predicate expression of a FilterExpr or AxisStep when query mode simple In the for let where order by query mode simple In a quantified expression clause or as the satisfies expression of a quantified expression when query mode simple An XDM instance [XQuery Data Model] XQSX XQUF [XQuery Update Facility] An apply expression Prolog variables declared as assignable [5.3 Assignment Expression] XQSX evaluation order The expression on the right-hand side of a block variable declaration is called an initializing expression A pending update list [XQuery Update Facility] The query mode updating sequential expressions sequential simple A sequential expression A sequential function sequential A simple expression updating expression sequential expression A simple function updating sequential simple function simple A snapshot XDM instance The expression enclosed in the parentheses of a while expression is called a test expression An updating expression pending update list An updating function updating This log records the substantive changes that have been made to this document. Minor editorial changes are not included in this log. This document was built from files checked in on $Date: 2014-09-07 02:38:15 $. Changed "exit with" to "exit returning" Relaxed restrictions on where sequential expressions can occur. The type of a block variable is never inferred from it's initializing expression. Removed the "set" keyword from an assignment expression. Changed "variable"/"constant" to "unassignable variable" and "assignable variable". Made execution scope and snapshot scope analogous, so stable functions can change value in subsequent snapshots. Added query mode to the static context, along with an option and pragma to change it. Added error codes for all error conditions. Relaxed the restrictions on where updating expressions can occur to a superset of those allowed by [XQuery Update Facility] Re-check the SequenceType of bound variables after upd:applyUpdates is invoked. Added the "block" keyword to the grammer for block expressions. Removed the break and continue expressions. Added the semi-colon (apply) expression to apply updates, removing the semi-colon separated list from block expressions. Added the ability to set the value of parameters to sequential functions.

Related documents

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