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
at http://www.w3.org/TR/.

This is a Proposed Recommendation as described in the Process Document.
This document will remain a Proposed Recommendation until 25 February 2014.
Advisory Committee Representatives should consult their
WBS questionnaires.
It was developed by the W3C XML Query Working Group,
which is part of the XML Activity.
The Working Group expects to advance this specification to Recommendation Status.

This Proposed Recommendation does not differ
from the Last Call Working Draft published on 01 October 2013 in any
substantive respect.
Please note that this Proposed Recommendation of XQueryX 3.0 represents the
second version of
a previous W3C Recommendation.

A Test Suite has been created for this document.
Implementors are encouraged to run this test suite and report their results.
The Test Suite can be found at http://dev.w3.org/2011/QT3-test-suite/.
An implementation report is available at
http://dev.w3.org/2011/QT3-test-suite/ReportingResults/.

This document incorporates changes made against the Candidate Recommendation of 08 January 2013.
Changes to this document since the Candidate Recommendation are detailed in
.

Please report errors in this document using W3C's
public Bugzilla system
(instructions can be found at
http://www.w3.org/XML/2005/04/qt-bugzilla).
If access to that system is not feasible, you may send your comments
to the W3C XSLT/XPath/XQuery public comments mailing list,
public-qt-comments@w3.org.
It will be very helpful if you include the string
“[XQX30]”
in the subject line of your report, whether made in Bugzilla or in email.
Please use multiple Bugzilla entries (or, if necessary, multiple email messages)
if you have more than one comment to make.
Archives of the comments and responses are available at
http://lists.w3.org/Archives/Public/public-qt-comments/.

Publication as a Proposed Recommendation
does not imply endorsement by the W3C Membership.
This is a draft document and may be updated, replaced or obsoleted
by other documents at any time.
It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the
5 February 2004
W3C Patent Policy.
W3C maintains a
public list of any patent disclosures
made in connection with the deliverables of the group;
that page also includes instructions for disclosing a patent.
An individual who has actual knowledge of a patent
which the individual believes contains
Essential Claim(s)
must disclose the information in accordance with
section 6 of the W3C Patent Policy.

English

This is the Proposed Recommendation of this spec.

This is the fourth WD of this spec.

This is the Last Call Working Draft of this specification.
It is aligned with the XQuery grammar as published in .

Introduction

The
states that 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:

Parser Reuse. In heterogeneous environments, a
variety of systems may be used to execute a query. One parser can generate XQueryX
for all of these systems.

Queries on Queries. Because XQueryX is represented in XML, queries
can be queried and can be transformed into new queries. For instance, a query can
be performed against a set of XQueryX queries to determine which queries use
FLWOR expressions to range over a set of invoices.

Generating Queries. In some XML-oriented programming
environments, it may be more convenient to build a query in its XQueryX
representation than in the corresponding XQuery representation, since ordinary
XML tools can be used.

Embedding Queries in XML. XQueryX can be embedded
directly in an XML document.

This version of XQueryX is fully compatible with .
It differs from that earlier version of the language by the addition of new XML Schema
definitions and XSLT stylesheet templates. All queries expressed in the syntax defined
by continue to be valid, with the same meaning, when processed
by an implementation of this version of XQueryX.

The most recent versions of the XQueryX XML Schema and the XQueryX XSLT stylesheet
are available at
http://www.w3.org/2014/01/XQueryX/xqueryx.xsd
and
http://www.w3.org/2014/01/XQueryX/xqueryx.xsl,
respectively.

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 .

Mapping the XQuery Syntax

XQueryX is an XML representation of the abstract syntax found in
Appendix A of .
The XQueryX syntax is defined by the XQueryX Schema,
which is specified in .
The XQueryX semantics are defined by a stylesheet that maps
an instance of XQueryX to an instance of XQuery;
see .

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.

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.

Examples from the XML Query Use Cases in XML Syntax

Three of following examples are based on the data and queries in the XMP
(Experiences and Exemplars) use case in
,
while a fourth example is based on the data and queries in the
NS (Queries Using Namespaces) use case.
For each example, we show the English description of the query,
the XQuery solution given in ,
an XQueryX solution, and the XQuery that results from applying the XQueryX-to-XQuery transformation
defined by the stylesheet in to the XQueryX solution.
That produced XQuery is presented only as a sanity-check —
the intent of the stylesheet is not to create the identical
XQuery expression given in ,
but to produce a valid
XQuery expression with the same semantics.
The semantics of the XQueryX solution are determined by the semantics of the XQuery expression that
results from that transformation. The "correctness" of that transformation is determined by
asking the following the question:
Can some XQueryX processor QX process some XQueryX document D1 to produce results R1,
after which the stylesheet is used to translate D1 into an XQuery expression E1 that,
when processed by some XQuery processor Q, produces results R2 that are equivalent
(under some meaningful definition of "equivalent") to results R1?

Comparison of the results of the XQueryX-to-XQuery transformation given in this document
with the XQuery solutions in the
may be helpful in evaluating
the correctness of the XQueryX solution in each example.

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.

Example 1

Here is Q1 from the ,
use case XMP (Experiences and Exemplars): "List books published by Addison-Wesley after 1991,
including their year and title."

Here is Q4 from the ,
use case XMP (Experiences and Exemplars): "For each author in the bibliography, list the
author's name and the titles of all books by that author, grouped inside a
"result" element."

In this section, the following terms are used to indicate the
requirement levels defined in .
[Definition: MUST means that the item is an absolute requirement of the specification.]
[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.]
[Definition: MAY means that an item is truly optional.]

An XQueryX processor that claims to conform to this specification MUST
implement the XQueryX syntax as defined in of this
specification and include a claim of Minimal Conformance as defined in
,
.
In addition to a claim of Minimal Conformance, it MAY claim conformance to
one or more optional features defined in
,
.

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
.

Introduction

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
XQueryX syntax.

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 public-qt-comments@w3.org,
a public mailing list with archives at
http://lists.w3.org/Archives/Public/public-qt-comments.

Registration of MIME Media Type application/xquery+xml

MIME media type name: application

MIME subtype name: xquery+xml

Required parameters: none

Optional parameters: charset

This parameter has identical semantics to the
charset parameter of the application/xml
media type as specified in [RFC 3023].

Encoding Considerations

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.

Security Considerations

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 file-exists();
a doc() function also allows local filesystem probes as well as
access to any URI-defined resource accessible from the system
evaluating the XQuery expression.

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.

Interoperability Considerations

See .

Published specification

This media type registration is for XQueryX documents as described
by the XQueryX 3.0 specification, which is located at
http://www.w3.org/TR/xqueryx-30/.
It is also appropriate to use this media type with later versions of
the XQueryX language.

Applications That Use This Media Type

The public XQuery Web page
lists more than two dozen implementations of the XQuery language,
both proprietary and open source. Some of these are known to
support XQueryX.

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.

Additional InformationRecognizing XQuery Files ("Magic Numbers")

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.

File Extensions

The most common file extension in use for XQueryX is
.xqx.

Macintosh File Type Code(s)

The appropriate Macintosh file type code is TEXT.

Person and Email Address to Contact For Further Information

Jim Melton, Oracle Corp.,
jim.melton@oracle.com

Intended Usage

COMMON

Restrictions on usage

The intended usage of this media type is for interchange
of XQueryX expressions.

Author/Change Controller

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.

Fragment Identifiers

For documents labeled as "application/xquery+xml",
the fragment identifier notation is exactly that for
"application/xml", as specified in [RFC 3023].

Change log

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.

Substantive changes

In the
Proposed Recommendation
of
30 January 2014,
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 changes that have been applied.

Change

Bugzilla

Category

Description

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.

[XQuery 1.1] Requirement: validation by type

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.

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)

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

lack of syntactic symmetry
between the control flow expressions

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.

XML Schema and XSLT Stylesheet

None.

Substantive.

Added support for the string concatenation operator ("||").

XML Schema and XSLT Stylesheet

None.

Substantive.

Added support for the simple mapping operator ("!").

XML Schema and XSLT Stylesheet

None.

Substantive.

Added support for the sequenceTypeUnion in the typeswitch expression.

XML Schema and XSLT Stylesheet

None.

Substantive.

Added support for the annotations on inline functions.

XML Schema and XSLT Stylesheet

None.

Substantive.

Added support for new group-by syntax.

XML Schema and XSLT Stylesheet

None.

Substantive.

Replaced the element named "literalFunctionItemExpr" with an identical element named "namedFunctionRef";
Replaced the element named "inlineFunctionItemExpr" with an identical element named "inlineFunctionExpr"

XML Schema and XSLT Stylesheet

Precedence of the Simple Map Operator

Substantive

Removed the element mapStepExpr and added an element simpleMapExpr, thus changing the precedence
of the simple map operator (!).

XSLT Stylesheet

missing parens for try/catch expression

Substantive

Generate parentheses that surround the XQuery code generated for a tryCatchExpr.

XML Schema and XSLT Stylesheet

Annotation in FunctionTest in XQueryX (member-only message)

Substantive

Provide support for (annotation) assertions in function tests.

XML Schema and XSLT Stylesheet

[APPLET] encoding becomes version in version declaration

Substantive

Require that a <versionDecl> element contain a <version> element, an <encoding> element, or both.
Use the <encoding> element to determine the actual encoding of the generated XQuery output.

XML Schema and XSLT Stylesheet

Annotation arguments

Substantive

Align with XQuery by restricting the operands of annotations to be literals, not expressions

XML Schema and XSLT Stylesheet

decimalFormatDecl

Substantive

Modify the manner in which XQueryX indicates that a declared decimal format is determined to be the default decimal format declaration.

XML Schema and XSLT Stylesheet

contextItemDecl

Substantive

Restrict the declared type of the context item to items, instead of sequence types in general

XML Schema and XSLT Stylesheet

functionDecl

Substantive

XQuery no longer has the ability to declare functions to be deterministic/non-deterministic, nor to declare them to
be public/private by the use of ordinary keyword syntax (instead, annotations are used for declaring them public/private)

In the
Proposed Recommendation
of
30 January 2014,
the following substantive changes have been made relative to the preceding stage of this document,
the Candidate Recommendation of 08 January 2013.
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 changes that have been applied.

Change

Bugzilla

Category

Description

XML Schema and XSLT Stylesheet

This row and all following rows were added after the previously-published draft.

[XQX30] simpleMapExpr

Substantive

The schema definition of simpleMapExpr has been extended to permit a string of
simpleMapExprs that cascade on one another. Although this was possible with the
previous definition of simpleMapExpr, the XQueryX syntax to do so was lengthy,
tedious, and not altogether intuitive. The stylesheet rendering of simpleMapExpr
into XQuery syntax has been correspondingly modified as well.

Incompatibilities

The
Proposed Recommendation
of
30 January 2014,
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 changes that have been applied.

Change

Bugzilla

Category

Description

(none)

—

—

—

Editorial changes

In the
Proposed Recommendation
of
30 January 2014,
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 changes that have been applied.

Change

Bugzilla

Category

Description

Erratum XQX.E1

Arguably incorrect element definition in XQueryX's Schema.

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

Removed element xqx:parenthesizedExpr used in example.

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.

Erratum XQX.E4

Bug in XQueryX applet

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.

Erratum XQX.E5

Problem with {{ and }} in a Namespace Declaration Attribute

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.

Introduction.

[XQX] non-normative notes

Editorial.

Added text in to clarify that Notes are non-normative.

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.

Introduction.

section 1: schema and stylesheet URLs

Editorial.

Corrected the URI of the XQueryX schema document and stylesheet.

Introduction.

section 1: version typo

Editorial.

Corrected the version number of the previous version of XQueryX. Also removed normative reference to "this"
document and replaced it with a reference to the XQueryX 1.0 document.

XML Schema and XSLT Stylesheet

(W3C confidential email)

Editorial.

Changed the stylesheet XSLT version number to 2.0, reflecting the new use of the xsl:result-document element
to control the character encoding of the generated XQuery query.