The XML Query Language MAY have
more than one syntax binding. One query language syntax MUST be convenient for
humans to read and write. One query language syntax MUST be expressed in XML in
a way that reflects the underlying structure of the query.
XQueryX is an XML representation of an XQuery. It was created by mapping the productions of the XQuery grammar into XML productions. The result is not particularly convenient for humans to read and write, but it is easy for programs to parse, and because XQueryX is represented in XML, standard XML tools can be used to create, interpret, or modify queries.
In this document, examples and material labeled as
Note are provided for
explanatory purposes and are not normative.
Because the two syntaxes are merely different grammars that express the
same query semantics, they share all aspects of an XQuery processing system
except for the component that recognizes and translates the source representation
of a query (that is, the parser).
The aspects that are shared include both the static context and
the dynamic context that are defined in
There are several environments in which XQueryX may be useful:
This version of XQueryX is fully compatible with
The most recent versions of the XQueryX XML Schema and the XQueryX XSLT stylesheet
are available at
The locations at which the current versions of the XML Schema and XSLT stylesheet are located during development of this specification will vary with each Working Draft and Candidate Recommendation of the spec that is published. The namespace target URI is identical to that used for XQueryX 1.0.
XQueryX is an XML representation of the abstract syntax found in
Appendix A of
The main data structure in the XQueryX Schema is the set of types that describe expressions. We have chosen to model expressions using substitution groups, with an "expr" abstract base class and a number of intermediate abstract classes.
Consider the following productions from the abstract syntax:
Those productions do not represent the entire FLWOR expression, so some of the BNF non-terminal names are not resolved in the example abstract syntax.
The following XQueryX Schema definitions reflect the structure of those productions from that abstract syntax:
Since XQuery uses the expression production liberally to allow expressions to be flexibly combined, XQueryX uses the exprWrapper type in embedded contexts to allow all expression types to occur.
Three of following examples are based on the data and queries in the XMP
(Experiences and Exemplars) use case in
Comparison of the results of the XQueryX-to-XQuery transformation given in this document
with the XQuery solutions in the
The XQuery Use Cases solution given for each example is provided only to assist readers of this document in understanding the XQueryX solution. There is no intent to imply that this document specifies a "compilation" or "transformation" of XQuery syntax into XQueryX syntax.
In the following examples, 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 XQueryX documents and XQuery expressions for readability. That additional white space is not produced by the XQueryX-to-XQuery transformation.
Here is Q1 from the
Application of the stylesheet in
For comparison, here is the abstract parse tree corresponding to the
XQuery for Example 1, as produced by the XQuery grammar applets found at
Here is Q4 from the
Application of the stylesheet in
Here is Q7 from the
Application of the stylesheet in
Here is Q8 from the
Application of the stylesheet in
Here is the XML Schema against which XQueryX documents must be valid.
This section defines the conformance criteria for an XQueryX processor
(see Figure 1, "Processing Model Overview", in
In this section, the following terms are used to indicate the
requirement levels defined in
An XQueryX processor that claims to conform to this specification MUST
implement the XQueryX syntax as defined in
The following stylesheet converts from XQueryX syntax to XML Query syntax.
Note the intent of the stylesheet is to produce
This Appendix specifies the media type for XQueryX Version 3.0. XQueryX is
the XML syntax of a language, XQuery, for querying over
data from XML data sources, as specified in
Specification of media types is described in
This document, together with its normative references, defines the
XML syntax for the XML Query language XQuery Version 3.0.
This Appendix specifies the
application/xquery+xml media type,
which is intended to be used for transmitting queries expressed in the
This media type is being submitted to the IESG for review, approval, and registration with IANA.
This document was prepared by members of the W3C XML Query Working
Group. Please send comments to email@example.com,
a public mailing list with archives at
MIME media type name:
MIME subtype name:
Required parameters: none
This parameter has identical semantics to the
charset parameter of the
media type as specified in [RFC 3023].
By virtue of XSLT content being XML, it has the same considerations
when sent as "
application/xquery+xml" as does XML.
See [RFC 3023], section 3.2.
Queries written in XQuery may cause arbitrary URIs or IRIs to be dereferenced.
Therefore, the security issues of [RFC3987] Section 8 should be considered.
In addition, the contents of resources identified by
file: URIs can in
some cases be accessed, processed and returned as results.
XQuery expressions can invoke any of the functions defined in
XQuery 1.0 and XPath 2.0 Functions and Operators, including
doc() function also allows local filesystem probes as well as
access to any URI-defined resource accessible from the system
evaluating the XQuery expression.
XQuery is a full declarative programming language, and supports user-defined functions, external function libraries (modules) referenced by URI, and system-specific "native" functions.
Arbitrary recursion is possible, as is arbitrarily large memory usage, and implementations may place limits on CPU and memory usage, as well as restricting access to system-defined functions.
The XML Query Working group is working on a facility to allow XQuery expressions to be used to create and update persistent data. Untrusted queries should not be given write access to data.
Furthermore, because the XQuery language permits extensions, it is possible that application/xquery may describe content that has security implications beyond those described here.
This media type registration is for XQueryX documents as described
by the XQueryX 3.0 specification, which is located at
This new media type is being registered to allow for deployment of XQueryX on the World Wide Web.
There is no experimental, vendor specific, or personal tree predecessor to "application/xquery+xml", reflecting the fact that no applications currently recognize it. This new type is being registered in order to allow for the expected deployment of XQueryX 3.0 on the World Wide Web, as a first class XML application.
Although no byte sequences can be counted on to consistently identify XQueryX, XQueryX documents will have the sequence "http://www.w3.org/2005/XQueryX" to identify the XQueryX namespace. This sequence will normally be found in a namespace attribute of the first element in the document.
The most common file extension in use for XQueryX is
The appropriate Macintosh file type code is
Jim Melton, Oracle Corp.,
The intended usage of this media type is for interchange of XQueryX expressions.
XQuery was produced by, and is maintained by, the World Wide Web Consortium's XML Query Working Group. The W3C has change control over this specification.
For documents labeled as "
the fragment identifier notation is exactly that for
application/xml", as specified in [RFC 3023].
This appendix lists the changes that have been made to this specification since the publication of the XQueryX 1.0 Recommendation on 23 January 2007.
In the Working Draft of 14 June 2011, the following substantive changes have been made relative to XQueryX 1.0. The changes made to this document are described below. The rationale for each change is explained in the corresponding Bugzilla database entry (if any). The following table summarizes the errata that have been applied.
|Group By clause in FLWOR expression.||None.||Substantive.||A new clause was added to the FLWOR expression to allow query writers to cause groups of tuples to be created based on the values of some expression.|
|Window clause in FLWOR expression.||None.||Substantive.||A new clause was added to the FLWOR expression to allow query writers to create sliding and tumbling windows of tuples based on a number of criteria.|
|Simplification of FLWOR expression.||None.||Substantive.||The syntax of the FLWOR expression was considerably relaxed, permitting most clauses (other than the return clause) to be used at almost any position (only a few clauses are allowed to be the first clause) within a FLWOR expression.|
|Outer for supported in FLWOR expressions.||None.||Substantive.||The syntax of the for clause in FLWOR expressions was extended to allow the use of "outer for".|
|Count clause in FLWOR expression.||None.||Substantive.||A new clause was added to the FLWOR expression to allow query writers to capture the total number of items that are returned by a (portion of a) FLWOR expression.|
|Declaration of decimal number formats.||None.||Substantive.||A new option was added to the query prologue, allowing query authors to specify a named (or an unnamed default) format for decimal numbers. This allows the specification of such items as the decimal separator, the minus sign, the percent and per mille signs, and even the class of Unicode digits.|
|Query version and encoding declaration.||None.||Substantive.||Allows specification of either or both of the version of XQuery to which a query adheres and the encoding of the query (e.g., UTF8, ISO8859-1).|
|Enhanced validation expression.||
||Substantive.||Permits query authors to validate an expression against a specified XML Schema type.|
|Nondeterministic external functions.||None.||Substantive.||Functions declared to be external functions can also be specified to be deterministic or nondeterministic.|
|Syntax used to provide default value for external variables.||None.||Minor.||The declaration of external variables now uses ":=" to indicate the default value given to such variables, instead of the keyword "default".|
|Try/catch for error handling.||None.||Substantive.||A try/catch facility is provided that allows query authors to control how errors are handled when raised by evaluation of queries.|
|Context item declaration.||None.||Substantive.||It is now possible to declare both the type of and the default initial value of the context item of a query, and to specify whether its value may be provided by the external environment.|
|Computed namespace constructor.||None.||Substantive.||Added new complex type and element to XQueryX schema, and new template to XQueryX stylesheet, in support of computed namespace constructors in XQuery 1.1.|
|Generate proper syntax for variable names in positional variable bindings.||
||Substantive.||Modified XQueryX stylesheet template to correctly generate a "$" preceding the variable name.|
|Allow positional variable bindings to be optional in window variables.||
||Substantive.||Modified XQueryX schema to add minOccurs="0" on element positionalVariableBinding in windowVars complex type definition.|
|XQueryX syntax must allow wildcards in the try/catch error list.||
||Substantive.||In XQueryX schema, modified catchErrorList complex type definition to allow a choice between a nameText (essentially a QName) and a Wildcard. In XQueryX stylesheet, modified catchErrorList template to support Wildcard as well as nameText.|
|Private functions.||None.||Substantive.||In XQueryX schema, added new attribute "private" in functionDecl complex type. In XQUeryX stylesheet, template for functionDecl, added support for @private (generate "private" for private functions and "public" for others)|
|Replace "outer for" with "allowing empty".||None.||Substantive.||In XQueryX schema, forClause complex type, delete attribute "outer"; in forClauseItem complex type, add new element allowingEmpty. In XQueryX stylesheet template for forClause, remove generation of "outer"; in template for forClauseItem, generate "allowing empty".|
|Higher-order functions.||None.||Substantive.||Made changes to XQueryX schema and stylesheet corresponding to new higher-order function syntax in XQuery 1.1.|
|New "switch" expression ("value switch", analogous to typeswitch).||None.||Substantive.||Made changes to XQueryX schema and stylesheet corresponding to new switch syntax in XQuery 3.0.|
|Support for partial function application.||None.||Substantive.||Made changes to XQueryX schema and stylesheet to support the partial function application capability of XQuery 3.0.|
|XML Schema and XSLT Stylesheet||
||Substantive.||Eliminated the possibility of defining three "error variables" as part of the catch clause; those variables (and others) are now implicitly defined, and may be used without explicit definition. At the same time, fixed a bug in the schema and stylesheet that recognized and produced invalid syntax for the validation expression.|
The Working Draft of 14 June 2011, contains the following incompatibilities with XQueryX 1.0. The changes made to this document are described below. The rationale for each change is explained in the corresponding Bugzilla database entry (if any). The following table summarizes the errata that have been applied.
In the Working Draft of 14 June 2011, the following editorial changes have been made relative to XQueryX 1.0. The changes made to this document are described below. The rationale for each change is explained in the corresponding Bugzilla database entry (if any). The following table summarizes the errata that have been applied.
||Editorial.||The published XQueryX 1.0 schema defined many elements using anonymous complex types. That made it infeasible to extend the content model of those elements in other specifications that define XQueryX extensions corresponding perhaps to XQuery extensions. While conceptually simple, a number of changes were required to ensure that all elements are defined using named complex types.|
|Erratum XQX.E2 and Erratum XQX.E3||
||Editorial.||The XQueryX solution to Example 4 incorrectly contained an <xqx:parenthesizedExpr> element. That element was changed to an <xqx:sequenceExpr> element. The XSLT stylesheet in Appendix B contained a template for the transformation of <xqx:parenthesizedExpr> elements that was unnecessary and confusing; that template was deleted.|
||Editorial.||The XQueryX 1.0 Recommendation linked to an obsolete version of the XQuery 1.0 grammar applet. The proper link has now been used.|
||Editorial.||The XSLT stylsheet in Appendix B contained a template for the transformation of <xqx:namespaceDeclaration> elements that failed to correctly "escape" curly braces in the same manner as does the template for the transformation of <xqx:attributeConstructor> elements. That template has been corrected.|
Added text in |
|This appendix.||None.||Editorial.||Reorganized this appendix to more clearly distinguish between substantive and editorial changes and to clearly identify incompatibilities with the previous Recommendation.|
|Version number.||None.||Editorial.||Changed the version number of the spec from 1.1 to 3.0.|