W3C

XML Syntax for XQuery 1.0 (XQueryX)

W3C Working Draft 4 April 2005

This version:
http://www.w3.org/TR/2005/WD-xqueryx-20050404
Latest version:
http://www.w3.org/TR/xqueryx
Previous version:
http://www.w3.org/TR/2005/WD-xqueryx-20050211
Editors:
Jim Melton, Oracle <jim.melton@oracle.com>
Subramanian Muralidhar, Microsoft <smurali@microsoft.com>

Abstract

This document presents an XML Syntax for [XQuery 1.0: An XML Query Language].

Status of this Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current 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 Public Working Draft for review by W3C Members and other interested parties. Publication as a Working Draft 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 through the efforts of the W3C XML Query Working Group (part of the W3C XML Activity). It is designed to be read in conjunction with the following documents: [XQuery 1.0: An XML Query Language] and [XQuery 1.0 Formal Semantics].

This document specifies an XML syntax for XQuery. The XML Query WG is supplying this document as the resolution of XQuery Issue 153. The XML Query WG anticipates that XQueryX will be an optional conformance feature for XQuery 1.0. The WG invites feedback on the approaches for representing XQuery 1.0 in XML in this Working Draft.

This working draft incorporates a number of changes made in response to comments received against the previous working draft and changes made to resolve a number of open issues. These changes include realigning the XQueryX schema with the current XQuery grammar, adoption of more uniform naming conventions in the schema, revising the definition of the type exprList to be a sequence of "expr" (and not of exprWrapper), revising the definition of sequenceExpr to be an explicit sequence of "expr" (and not a single element of type "exprList"), to rename the child element "parameters" of functionCallExpr to "arguments" and the child element "parameters" of operatorExpr to "arguments", to eliminate the use of elements "exprList" and "exprWrapper", and to add a new element "xqx:xquery" to represent the trivial embedding.

This is a Last Call Working Draft. Comments on this document are due on 13 May 2005. Comments should be entered into the last-call issue tracking system for this specification (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 mailing list public-qt-comments@w3.org. (archived at http://lists.w3.org/Archives/Public/public-qt-comments/) with “[XQueryX]” at the beginning of the subject field.

The patent policy for this document is specified in 5 February 2004 W3C Patent Policy. Patent disclosures relevant to this specification may be found on the XML Query Working Group's patent disclosure page. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) with respect to this specification should disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1 Introduction
2 Mapping the XQuery Syntax
3 Examples from the XML Query Use Cases in XML Syntax
    3.1 Example 1
        3.1.1 Solution in XQuery:
        3.1.2 The Same Solution in XQueryX:
        3.1.3 Test:
        3.1.4 Corresponding Grammar Abstract Parse Tree
    3.2 Example 2
        3.2.1 Solution in XQuery:
        3.2.2 The same solution in XQueryX:
        3.2.3 Test:
    3.3 Example 3
        3.3.1 Solution in XQuery:
        3.3.2 The same solution in XQueryX:
        3.3.3 Test:
4 An XML Schema for the XQuery XML Syntax
5 A Trivial Embedding of XQuery

Appendices

A References
B Transforming XQueryX to XQuery
C The application/xquery+xml Media Type (Non-Normative)
    C.1 Introduction
    C.2 Registration of MIME Media Type application/xquery+xml
        C.2.1 Encoding Considerations
        C.2.2 Fragment Identifiers
        C.2.3 Restrictions on usage
        C.2.4 Security Considerations
        C.2.5 Interoperability Considerations
        C.2.6 Applications That Use This Media Type
        C.2.7 Additional Information
            C.2.7.1 Recognizing XQuery Files ("Magic Numbers")
            C.2.7.2 File Extensions
            C.2.7.3 Macintosh File Type Code(s)
        C.2.8 Person and Email Address to Contact For Further Information
        C.2.9 Intended Usage
        C.2.10 Author/Change Controller
D XQueryX Issues (Non-Normative)
    D.1 XQueryX Issue Summary
    D.2 XQueryX Issues


1 Introduction

The [XML Query 1.0 Requirements] 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.

There are several environments in which XQueryX may be useful:

2 Mapping the XQuery Syntax

XQueryX is an XML representation of the abstract syntax found in Appendix A of the [XQuery 1.0: An XML Query Language]. The XQueryX syntax is defined by the XQueryX Schema; see 4 An XML Schema for the XQuery XML Syntax. The XQueryX semantics are defined by a stylesheet that maps an instance of XQueryX to an instance of XQuery; see B Transforming XQueryX to XQuery.

The main data structure in the XQueryX Schema is the set of types that describe expressions. We have chosen to model expressions as an inheritance hierarchy, with an "expr" abstract base class. An alternate approach could be to use groups instead of inheritance hierarchies. This specification does not provide any such alternate approach.

Consider the following productions from the abstract syntax:


FLWORExpr               ::=    (ForClause  | LetClause)+ WhereClause? OrderByClause? "return" 
                                        ExprSingle 
ForClause               ::=    <"for" "$"> VarName TypeDeclaration? PositionalVar? "in" 
                                        ExprSingle ("," "$" VarName TypeDeclaration? PositionalVar? 
                                        "in" ExprSingle)* 
LetClause               ::=    <"let" "$"> VarName TypeDeclaration? ":=" 
                                        ExprSingle ("," "$" VarName TypeDeclaration? ":=" ExprSingle)*
WhereClause             ::=    "where" ExprSingle

The following XQueryX Schema definitions reflect the structure of the above productions:


  
<!-- The base class -->
  <xsd:complexType name="expr"/>
  <xsd:element name="expr" type="expr"/>
  
  <!-- Simple wrapper class -->
  <xsd:complexType name="exprWrapper">
    <xsd:sequence>
      <xsd:element ref="expr"/>
    </xsd:sequence>
  </xsd:complexType>
  
  <xsd:complexType name="flworExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:choice maxOccurs="unbounded">
            <xsd:element ref="forClause"/>
            <xsd:element ref="letClause"/>
          </xsd:choice>
          <xsd:element name="whereClause" minOccurs="0"/>
          <xsd:element name="orderByClause" minOccurs="0"/>
          <xsd:element name="returnClause"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:element name="forClauseItem">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="typedVariableBinding"/>
        <xsd:element ref="positionalVariableBinding" minOccurs="0"/>
        <xsd:element name="forExpr" type="exprWrapper"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="forClause">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="forClauseItem" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="letClauseItem">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="typedVariableBinding"/>
        <xsd:element name="letExpr" type="exprWrapper"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="letClause">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="letClauseItem" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="whereClause" type="exprWrapper"/>
  <xsd:element name="returnClause" type="exprWrapper"/>
  

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.

3 Examples from the XML Query Use Cases in XML Syntax

The following examples are based on the data and queries in the XMP (Experiences and Exemplars) use case in [XML Query Use Cases]. For each example we show the English description of the query, the XQuery solution, the same solution in XQueryX, and the XQuery result of the XQueryX-to-XQuery transformation. The latter is a result of applying the stylesheet in B Transforming XQueryX to XQuery to the XQueryX. It is presented as a sanity-check - the intent of the stylesheet is not to create the identical XQuery that was initially compiled into the given XQueryX, but to produce a valid XQuery with the same semantics.

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. XQueryX is not designed as a convenient syntax for humans to read and write, but instead as a language that is convenient for machine production and modification. The representation is thus oriented toward the use of software that generates XQueries.

3.1 Example 1

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

3.1.1 Solution in XQuery:

<bib>
 {
  for $b in doc("http://bstore1.example.com/bib.xml")/bib/book
  where $b/publisher = "Addison-Wesley" and $b/@year > 1991
  return
    <book year="{ $b/@year }">
     { $b/title }
    </book>
 }
</bib>

3.1.2 The Same Solution in XQueryX:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xqueryx.xsl"?>
<xqx:module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xqx="http://www.w3.org/2005/04/XQueryX" 
      xsi:schemaLocation="http://www.w3.org/2005/04/XQueryX/xqueryx.xsd">
  <xqx:mainModule>
    <xqx:queryBody>
      <xqx:expr xsi:type="xqx:elementConstructor">
        <xqx:tagName>bib</xqx:tagName>
        <xqx:elementContent>
          <xqx:expr xsi:type="xqx:flworExpr">
            <xqx:forClause>
              <xqx:forClauseItem>
                <xqx:typedVariableBinding>
                  <xqx:varName>b</xqx:varName>
                </xqx:typedVariableBinding>
                <xqx:forExpr>
                  <xqx:expr xsi:type="xqx:pathExpr">
                    <xqx:argExpr>
                    <xqx:expr xsi:type="xqx:functionCallExpr">
                      <xqx:functionName>doc</xqx:functionName>
                      <xqx:arguments>
                        <xqx:expr xsi:type="xqx:stringConstantExpr">
                          <xqx:value>http://bstore1.example.com/bib.xml</xqx:value>
                        </xqx:expr>
                      </xqx:arguments>
                    </xqx:expr>
                    </xqx:argExpr>
                    <xqx:stepExpr>
                      <xqx:xpathAxis>child</xqx:xpathAxis>
                      <xqx:nameTest>bib</xqx:nameTest>
                    </xqx:stepExpr>
                    <xqx:stepExpr>
                      <xqx:xpathAxis>child</xqx:xpathAxis>
                      <xqx:nameTest>book</xqx:nameTest>
                    </xqx:stepExpr>
                  </xqx:expr>
                </xqx:forExpr>
              </xqx:forClauseItem>
            </xqx:forClause>
            <xqx:whereClause>
              <xqx:expr xsi:type="xqx:operatorExpr">
                <xqx:infixOp/>
                <xqx:opType>and</xqx:opType>
                <xqx:arguments>
                    <xqx:expr xsi:type="xqx:operatorExpr">
                      <xqx:infixOp/>
                      <xqx:opType>=</xqx:opType>
                      <xqx:arguments>
                          <xqx:expr xsi:type="xqx:pathExpr">
                            <xqx:argExpr>
                              <xqx:expr xsi:type="xqx:varRef">
                                <xqx:name>b</xqx:name>
                              </xqx:expr>
                            </xqx:argExpr>
                            <xqx:stepExpr>
                              <xqx:xpathAxis>child</xqx:xpathAxis>
                              <xqx:nameTest>publisher</xqx:nameTest>
                            </xqx:stepExpr>
                          </xqx:expr>
                          <xqx:expr xsi:type="xqx:stringConstantExpr">
                            <xqx:value>Addison-Wesley</xqx:value>
                          </xqx:expr>
                      </xqx:arguments>
                    </xqx:expr>
                    <xqx:expr xsi:type="xqx:operatorExpr">
                      <xqx:infixOp/>
                      <xqx:opType>&gt;</xqx:opType>
                      <xqx:arguments>
                          <xqx:expr xsi:type="xqx:pathExpr">
                            <xqx:argExpr>
                              <xqx:expr xsi:type="xqx:varRef">
                                <xqx:name>b</xqx:name>
                              </xqx:expr>
                            </xqx:argExpr>
                            <xqx:stepExpr>
                              <xqx:xpathAxis>attribute</xqx:xpathAxis>
                              <xqx:nameTest>year</xqx:nameTest>
                            </xqx:stepExpr>
                          </xqx:expr>
                          <xqx:expr xsi:type="xqx:integerConstantExpr">
                            <xqx:value>1991</xqx:value>
                          </xqx:expr>
                      </xqx:arguments>
                    </xqx:expr>
                </xqx:arguments>
              </xqx:expr>
            </xqx:whereClause>
            <xqx:returnClause>
              <xqx:expr xsi:type="xqx:elementConstructor">
                <xqx:tagName>book</xqx:tagName>
                <xqx:attributeList>
                  <xqx:attributeConstructor>
                    <xqx:attributeName>year</xqx:attributeName>
                    <xqx:attributeValueExpr>
                      <xqx:expr xsi:type="xqx:pathExpr">
                        <xqx:argExpr>
                          <xqx:expr xsi:type="xqx:varRef">
                            <xqx:name>b</xqx:name>
                          </xqx:expr>
                        </xqx:argExpr>
                        <xqx:stepExpr>
                          <xqx:xpathAxis>attribute</xqx:xpathAxis>
                          <xqx:nameTest>year</xqx:nameTest>
                        </xqx:stepExpr>
                      </xqx:expr>
                    </xqx:attributeValueExpr>
                  </xqx:attributeConstructor>
                </xqx:attributeList>
                <xqx:elementContent>
                    <xqx:expr xsi:type="xqx:pathExpr">
                      <xqx:argExpr>
                        <xqx:expr xsi:type="xqx:varRef">
                          <xqx:name>b</xqx:name>
                        </xqx:expr>
                      </xqx:argExpr>
                      <xqx:stepExpr>
                        <xqx:xpathAxis>child</xqx:xpathAxis>
                        <xqx:nameTest>title</xqx:nameTest>
                      </xqx:stepExpr>
                    </xqx:expr>
                </xqx:elementContent>
              </xqx:expr>
            </xqx:returnClause>
          </xqx:expr>
        </xqx:elementContent>
      </xqx:expr>
    </xqx:queryBody>
  </xqx:mainModule>
</xqx:module>

3.1.3 Test:

Applying the stylesheet in B Transforming XQueryX to XQuery to the XQueryX solution, we get:

<bib>{
 for $b in doc("http://bstore1.example.com/bib.xml")/child::bib/child::book
 where (($b/child::publisher = "Addison-Wesley") and ($b/attribute::year > 1991))
 return <book year="{$b/attribute::year}">{$b/child::title}</book>
}</bib>

3.1.4 Corresponding Grammar Abstract Parse Tree

For comparison, here is the abstract parse tree corresponding to the XQuery for Example 1, as produced by the XQuery grammar applets found at http://www.w3.org/2004/08/applets/xqueryApplet.html.

XPath2
  QueryList
   Module
     MainModule
      Prolog
      QueryBody
        Expr
         PathExpr
           Constructor
            DirectConstructor
              DirElemConstructor
               StartTagOpenRoot <
               TagQName bib
               DirAttributeList
               StartTagClose >
               DirElemContent
                 ElementContentChar 

               DirElemContent
                 ElementContentChar 
               DirElemContent
                 CommonContent
                  EnclosedExpr
                    Lbrace {
                    Expr
                     FLWORExpr
                       VarName b
                       In in
                       PathExpr
                        FunctionCall
                          QNameLpar doc(
                          PathExpr
                           StringLiteral "http://bstore1.example.com/bib.xml"
                        StepExpr
                          NodeTest
                           NameTest
                             QName bib
                        StepExpr
                          NodeTest
                           NameTest
                             QName book
                       WhereClause
                        Where where
                        AndExpr and
                          ComparisonExpr =
                           PathExpr
                             VarName b
                             StepExpr
                              NodeTest
                                NameTest
                                 QName publisher
                           PathExpr
                             StringLiteral "Addison-Wesley"
                          ComparisonExpr >
                           PathExpr
                             VarName b
                             StepExpr
                              At @
                              NodeTest
                                NameTest
                                 QName year
                           PathExpr
                             IntegerLiteral 1991
                       PathExpr
                        Constructor
                          DirectConstructor
                           DirElemConstructor
                             StartTagOpenRoot <
                             TagQName book
                             DirAttributeList
                              S 
                              TagQName year
                              ValueIndicator =
                              DirAttributeValue
                                OpenQuot "
                                QuotAttrValueContent
                                 CommonContent
                                   EnclosedExpr
                                    Lbrace {
                                    Expr
                                      PathExpr
                                       VarName b
                                       StepExpr
                                         At @
                                         NodeTest
                                          NameTest
                                            QName year
                                    Rbrace }
                                CloseQuot "
                             StartTagClose >
                             DirElemContent
                              ElementContentChar 
                             DirElemContent
                              ElementContentChar 
                             DirElemContent
                              ElementContentChar 
                             DirElemContent
                              ElementContentChar 
                             DirElemContent
                              ElementContentChar 
                             DirElemContent
                              ElementContentChar 
                             DirElemContent
                              CommonContent
                                EnclosedExpr
                                 Lbrace {
                                 Expr
                                   PathExpr
                                    VarName b
                                    StepExpr
                                      NodeTest
                                       NameTest
                                         QName title
                                 Rbrace }
                             DirElemContent
                              ElementContentChar 
                             DirElemContent
                              ElementContentChar 
                             DirElemContent
                              ElementContentChar 
                             DirElemContent
                              ElementContentChar 
                             DirElemContent
                              ElementContentChar 
                             EndTagOpen </
                             TagQName book
                             EndTagClose >
                    Rbrace }
               DirElemContent
                 ElementContentChar 
               EndTagOpen </
               TagQName bib
               EndTagClose >

3.2 Example 2

Here is Q4 from the [XML Query Use Cases], 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."

3.2.1 Solution in XQuery:

<results>
  {
    let $a := doc("http://bstore1.example.com/bib/bib.xml")//author
    for $last in distinct-values($a/last),
        $first in distinct-values($a[last=$last]/first)
    order by $last, $first
    return
        <result>
            <author>
               <last>{ $last }</last>
               <first>{ $first }</first>
            </author>
            {
                for $b in doc("http://bstore1.example.com/bib.xml")/bib/book
                where some $ba in $b/author 
                      satisfies ($ba/last = $last and $ba/first=$first)
                return $b/title
            }
        </result>
  }
</results> 

3.2.2 The same solution in XQueryX:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xqueryx.xsl"?>
<xqx:module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xqx="http://www.w3.org/2005/04/XQueryX" 
    xsi:schemaLocation="http://www.w3.org/2005/04/XQueryX/xqueryx.xsd">
  <xqx:mainModule>
    <xqx:queryBody>
      <xqx:expr xsi:type="xqx:elementConstructor">
        <xqx:tagName>results</xqx:tagName>
        <xqx:elementContent>
          <xqx:expr xsi:type="xqx:flworExpr">
            <xqx:letClause>
              <xqx:letClauseItem>
                <xqx:typedVariableBinding>
                  <xqx:varName>a</xqx:varName>
                </xqx:typedVariableBinding>
                <xqx:letExpr>
                  <xqx:expr xsi:type="xqx:pathExpr">
                    <xqx:argExpr>
                      <xqx:expr xsi:type="xqx:functionCallExpr">
                        <xqx:functionName>doc</xqx:functionName>
                        <xqx:arguments>
                            <xqx:expr xsi:type="xqx:stringConstantExpr">
              <xqx:value>http://bstore1.example.com/bib/bib.xml</xqx:value>
                            </xqx:expr>
                        </xqx:arguments>
                      </xqx:expr>
                    </xqx:argExpr>
                    <xqx:stepExpr>
                      <xqx:xpathAxis>descendant-or-self</xqx:xpathAxis>
                      <xqx:nameTest>author</xqx:nameTest>
                    </xqx:stepExpr>
                  </xqx:expr>
                </xqx:letExpr>
              </xqx:letClauseItem>
            </xqx:letClause>
            <xqx:forClause>
              <xqx:forClauseItem>
                <xqx:typedVariableBinding>
                  <xqx:varName>last</xqx:varName>
                </xqx:typedVariableBinding>
                <xqx:forExpr>
                  <xqx:expr xsi:type="xqx:functionCallExpr">
                    <xqx:functionName>distinct-values</xqx:functionName>
                    <xqx:arguments>
                        <xqx:expr xsi:type="xqx:pathExpr">
                          <xqx:argExpr>
                            <xqx:expr xsi:type="xqx:varRef">
                              <xqx:name>a</xqx:name>
                            </xqx:expr>
                          </xqx:argExpr>
                          <xqx:stepExpr>
                            <xqx:xpathAxis>child</xqx:xpathAxis>
                            <xqx:nameTest>last</xqx:nameTest>
                          </xqx:stepExpr>
                        </xqx:expr>
                    </xqx:arguments>
                  </xqx:expr>
                </xqx:forExpr>
              </xqx:forClauseItem>
              <xqx:forClauseItem>
                <xqx:typedVariableBinding>
                  <xqx:varName>first</xqx:varName>
                </xqx:typedVariableBinding>
                <xqx:forExpr>
                  <xqx:expr xsi:type="xqx:functionCallExpr">
                    <xqx:functionName>distinct-values</xqx:functionName>
                    <xqx:arguments>
                        <xqx:expr xsi:type="xqx:pathExpr">
                          <xqx:argExpr>
                            <xqx:expr xsi:type="xqx:varRef">
                              <xqx:name>a</xqx:name>
                            </xqx:expr>
                          </xqx:argExpr>
                          <xqx:predicates>
                              <xqx:expr xsi:type="xqx:operatorExpr">
                                <xqx:infixOp/>
                                <xqx:opType>=</xqx:opType>
                                <xqx:arguments>
                                    <xqx:expr xsi:type="xqx:pathExpr">
                                      <xqx:argExpr>
                                        <xqx:expr xsi:type="xqx:contextItemExpr"/>
                                      </xqx:argExpr>
                                      <xqx:stepExpr>
                                        <xqx:xpathAxis>child</xqx:xpathAxis>
                                        <xqx:nameTest>last</xqx:nameTest>
                                      </xqx:stepExpr>
                                    </xqx:expr>
                                    <xqx:expr xsi:type="xqx:varRef">
                                      <xqx:name>last</xqx:name>
                                    </xqx:expr>
                                </xqx:arguments>
                              </xqx:expr>
                          </xqx:predicates>
                          <xqx:stepExpr>
                            <xqx:xpathAxis>child</xqx:xpathAxis>
                            <xqx:nameTest>first</xqx:nameTest>
                          </xqx:stepExpr>
                        </xqx:expr>
                    </xqx:arguments>
                  </xqx:expr>
                </xqx:forExpr>
              </xqx:forClauseItem>
            </xqx:forClause>
            <xqx:orderByClause>
              <xqx:orderBySpec>
                <xqx:orderByExpr>
                  <xqx:expr xsi:type="xqx:varRef">
                    <xqx:name>last</xqx:name>
                  </xqx:expr>
                </xqx:orderByExpr>
              </xqx:orderBySpec>
              <xqx:orderBySpec>
                <xqx:orderByExpr>
                  <xqx:expr xsi:type="xqx:varRef">
                    <xqx:name>first</xqx:name>
                  </xqx:expr>
                </xqx:orderByExpr>
              </xqx:orderBySpec>
            </xqx:orderByClause>
            <xqx:returnClause>
              <xqx:expr xsi:type="xqx:elementConstructor">
                <xqx:tagName>result</xqx:tagName>
                <xqx:elementContent>
                    <xqx:expr xsi:type="xqx:elementConstructor">
                      <xqx:tagName>author</xqx:tagName>
                      <xqx:elementContent>
                          <xqx:expr xsi:type="xqx:elementConstructor">
                            <xqx:tagName>last</xqx:tagName>
                            <xqx:elementContent>
                              <xqx:expr xsi:type="xqx:varRef">
                                <xqx:name>last</xqx:name>
                              </xqx:expr>
                            </xqx:elementContent>
                          </xqx:expr>
                          <xqx:expr xsi:type="xqx:elementConstructor">
                            <xqx:tagName>first</xqx:tagName>
                            <xqx:elementContent>
                              <xqx:expr xsi:type="xqx:varRef">
                                <xqx:name>first</xqx:name>
                              </xqx:expr>
                            </xqx:elementContent>
                          </xqx:expr>
                      </xqx:elementContent>
                    </xqx:expr>
                    <xqx:expr xsi:type="xqx:flworExpr">
                      <xqx:forClause>
                        <xqx:forClauseItem>
                          <xqx:typedVariableBinding>
                            <xqx:varName>b</xqx:varName>
                          </xqx:typedVariableBinding>
                          <xqx:forExpr>
                            <xqx:expr xsi:type="xqx:pathExpr">
                              <xqx:argExpr>
                                <xqx:expr xsi:type="xqx:functionCallExpr">
                                  <xqx:functionName>doc</xqx:functionName>
                                  <xqx:arguments>
                                      <xqx:expr xsi:type="xqx:stringConstantExpr">
                                        <xqx:value>http://bstore1.example.com/bib.xml</xqx:value>
                                      </xqx:expr>
                                  </xqx:arguments>
                                </xqx:expr>
                              </xqx:argExpr>
                              <xqx:stepExpr>
                                <xqx:xpathAxis>child</xqx:xpathAxis>
                                <xqx:nameTest>bib</xqx:nameTest>
                              </xqx:stepExpr>
                              <xqx:stepExpr>
                                <xqx:xpathAxis>child</xqx:xpathAxis>
                                <xqx:nameTest>book</xqx:nameTest>
                              </xqx:stepExpr>
                            </xqx:expr>
                          </xqx:forExpr>
                        </xqx:forClauseItem>
                      </xqx:forClause>
                      <xqx:whereClause>
                        <xqx:expr xsi:type="xqx:quantifiedExpr">
                          <xqx:quantifier>some</xqx:quantifier>
                          <xqx:quantifiedExprInClause>
                            <xqx:typedVariableBinding>
                              <xqx:varName>ba</xqx:varName>
                            </xqx:typedVariableBinding>
                            <xqx:sourceExpr>
                              <xqx:expr xsi:type="xqx:pathExpr">
                                <xqx:argExpr>
                                  <xqx:expr xsi:type="xqx:varRef">
                                    <xqx:name>b</xqx:name>
                                  </xqx:expr>
                                </xqx:argExpr>
                                <xqx:stepExpr>
                                  <xqx:xpathAxis>child</xqx:xpathAxis>
                                  <xqx:nameTest>author</xqx:nameTest>
                                </xqx:stepExpr>
                              </xqx:expr>
                            </xqx:sourceExpr>
                          </xqx:quantifiedExprInClause>
                          <xqx:predicateExpr>
                            <xqx:expr xsi:type="xqx:operatorExpr">
                              <xqx:infixOp/>
                              <xqx:opType> and </xqx:opType>
                              <xqx:arguments>
                                  <xqx:expr xsi:type="xqx:operatorExpr">
                                    <xqx:infixOp/>
                                    <xqx:opType>=</xqx:opType>
                                    <xqx:arguments>
                                        <xqx:expr xsi:type="xqx:pathExpr">
                                          <xqx:argExpr>
                                            <xqx:expr xsi:type="xqx:varRef">
                                              <xqx:name>ba</xqx:name>
                                            </xqx:expr>
                                          </xqx:argExpr>
                                          <xqx:stepExpr>
                                            <xqx:xpathAxis>child</xqx:xpathAxis>
                                            <xqx:nameTest>last</xqx:nameTest>
                                          </xqx:stepExpr>
                                        </xqx:expr>
                                        <xqx:expr xsi:type="xqx:varRef">
                                          <xqx:name>last</xqx:name>
                                        </xqx:expr>
                                    </xqx:arguments>
                                  </xqx:expr>

                                  <xqx:expr xsi:type="xqx:operatorExpr">
                                    <xqx:infixOp/>
                                    <xqx:opType>=</xqx:opType>
                                    <xqx:arguments>
                                        <xqx:expr xsi:type="xqx:pathExpr">
                                          <xqx:argExpr>
                                            <xqx:expr xsi:type="xqx:varRef">
                                              <xqx:name>ba</xqx:name>
                                            </xqx:expr>
                                          </xqx:argExpr>
                                          <xqx:stepExpr>
                                            <xqx:xpathAxis>child</xqx:xpathAxis>
                                            <xqx:nameTest>first</xqx:nameTest>
                                          </xqx:stepExpr>
                                        </xqx:expr>
                                        <xqx:expr xsi:type="xqx:varRef">
                                          <xqx:name>first</xqx:name>
                                        </xqx:expr>
                                    </xqx:arguments>
                                  </xqx:expr>

                              </xqx:arguments>
                            </xqx:expr>
                          </xqx:predicateExpr>
                        </xqx:expr>
                      </xqx:whereClause>
                      <xqx:returnClause>
                        <xqx:expr xsi:type="xqx:pathExpr">
                          <xqx:argExpr>
                            <xqx:expr xsi:type="xqx:varRef">
                              <xqx:name>b</xqx:name>
                            </xqx:expr>
                          </xqx:argExpr>
                          <xqx:stepExpr>
                            <xqx:xpathAxis>child</xqx:xpathAxis>
                            <xqx:nameTest>title</xqx:nameTest>
                          </xqx:stepExpr>
                        </xqx:expr>
                      </xqx:returnClause>
                    </xqx:expr>
                </xqx:elementContent>
              </xqx:expr>
            </xqx:returnClause>
          </xqx:expr>
        </xqx:elementContent>
      </xqx:expr>
    </xqx:queryBody>
  </xqx:mainModule>
</xqx:module>

3.2.3 Test:

Applying the stylesheet in B Transforming XQueryX to XQuery to the XQueryX solution, we get:

<results>{
 let $a:=doc("http://bstore1.example.com/bib/bib.xml")/descendant-or-self::author
 for $last in distinct-values($a/child::last), $first in distinct-values($a[(./child::last = $last)]/child::first)
 order by $last , $first 
 return <result>{<author>{<last>{$last}</last>}{<first>{$first}</first>}</author>}{
 for $b in doc("http://bstore1.example.com/bib.xml")/child::bib/child::book
 where (some $ba in $b/child::author satisfies (($ba/child::last = $last)  and  ($ba/child::first = $first)))
 return $b/child::title
}</result>
}</results>

3.3 Example 3

Here is Q7 from the [XML Query Use Cases], use case XMP (Experiences and Exemplars): "List the titles and years of all books published by Addison-Wesley after 1991, in alphabetic order."

3.3.1 Solution in XQuery:

<bib>
  {
    for $b in doc("http://bstore1.example.com/bib.xml")//book
    where $b/publisher = "Addison-Wesley" and $b/@year > 1991
    order by $b/title
    return
        <book>
            { $b/@year }
            { $b/title }
        </book>
  }
</bib> 

3.3.2 The same solution in XQueryX:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xqueryx.xsl"?>
<xqx:module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xqx="http://www.w3.org/2005/04/XQueryX" 
      xsi:schemaLocation="http://www.w3.org/2005/04/XQueryX/xqueryx.xsd">
  <xqx:mainModule>
    <xqx:queryBody>
      <xqx:expr xsi:type="xqx:elementConstructor">
        <xqx:tagName>bib</xqx:tagName>
        <xqx:elementContent>
          <xqx:expr xsi:type="xqx:flworExpr">
            <xqx:forClause>
              <xqx:forClauseItem>
                <xqx:typedVariableBinding>
                  <xqx:varName>b</xqx:varName>
                </xqx:typedVariableBinding>
                <xqx:forExpr>
                  <xqx:expr xsi:type="xqx:pathExpr">
                    <xqx:argExpr>
                    <xqx:expr xsi:type="xqx:functionCallExpr">
                      <xqx:functionName>doc</xqx:functionName>
                      <xqx:arguments>
                          <xqx:expr xsi:type="xqx:stringConstantExpr">
                            <xqx:value>http://bstore1.example.com/bib.xml</xqx:value>
                          </xqx:expr>
                      </xqx:arguments>
                    </xqx:expr>
                    </xqx:argExpr>
                    <xqx:stepExpr>
                      <xqx:xpathAxis>descendant-or-self</xqx:xpathAxis>
                      <xqx:nameTest>book</xqx:nameTest>
                    </xqx:stepExpr>
                  </xqx:expr>
                </xqx:forExpr>
              </xqx:forClauseItem>
            </xqx:forClause>
            <xqx:whereClause>
              <xqx:expr xsi:type="xqx:operatorExpr">
                <xqx:infixOp/>
                <xqx:opType>and</xqx:opType>
                <xqx:arguments>
                    <xqx:expr xsi:type="xqx:operatorExpr">
                      <xqx:infixOp/>
                      <xqx:opType>=</xqx:opType>
                      <xqx:arguments>
                          <xqx:expr xsi:type="xqx:pathExpr">
                            <xqx:argExpr>
                              <xqx:expr xsi:type="xqx:varRef">
                                <xqx:name>b</xqx:name>
                              </xqx:expr>
                            </xqx:argExpr>
                            <xqx:stepExpr>
                              <xqx:xpathAxis>child</xqx:xpathAxis>
                              <xqx:nameTest>publisher</xqx:nameTest>
                            </xqx:stepExpr>
                          </xqx:expr>
                          <xqx:expr xsi:type="xqx:stringConstantExpr">
                            <xqx:value>Addison-Wesley</xqx:value>
                          </xqx:expr>
                      </xqx:arguments>
                    </xqx:expr>
                    <xqx:expr xsi:type="xqx:operatorExpr">
                      <xqx:infixOp/>
                      <xqx:opType>&gt;</xqx:opType>
                      <xqx:arguments>
                          <xqx:expr xsi:type="xqx:pathExpr">
                            <xqx:argExpr>
                              <xqx:expr xsi:type="xqx:varRef">
                                <xqx:name>b</xqx:name>
                              </xqx:expr>
                            </xqx:argExpr>
                            <xqx:stepExpr>
                              <xqx:xpathAxis>attribute</xqx:xpathAxis>
                              <xqx:nameTest>year</xqx:nameTest>
                            </xqx:stepExpr>
                          </xqx:expr>
                          <xqx:expr xsi:type="xqx:integerConstantExpr">
                            <xqx:value>1991</xqx:value>
                          </xqx:expr>
                      </xqx:arguments>
                    </xqx:expr>
                </xqx:arguments>
              </xqx:expr>
            </xqx:whereClause>
            <xqx:orderByClause>
              <xqx:orderBySpec>
                <xqx:orderByExpr>
                  <xqx:expr xsi:type="xqx:pathExpr">
                    <xqx:argExpr>
                      <xqx:expr xsi:type="xqx:varRef">
                        <xqx:name>b</xqx:name>
                      </xqx:expr>
                    </xqx:argExpr>
                    <xqx:stepExpr>
                      <xqx:xpathAxis>child</xqx:xpathAxis>
                      <xqx:nameTest>title</xqx:nameTest>
                    </xqx:stepExpr>
                  </xqx:expr>
                </xqx:orderByExpr>
              </xqx:orderBySpec>
            </xqx:orderByClause>
            <xqx:returnClause>
              <xqx:expr xsi:type="xqx:elementConstructor">
                <xqx:tagName>book</xqx:tagName>
                <xqx:elementContent>
                    <xqx:expr xsi:type="xqx:pathExpr">
                      <xqx:argExpr>
                        <xqx:expr xsi:type="xqx:varRef">
                          <xqx:name>b</xqx:name>
                        </xqx:expr>
                      </xqx:argExpr>
                      <xqx:stepExpr>
                        <xqx:xpathAxis>attribute</xqx:xpathAxis>
                        <xqx:nameTest>year</xqx:nameTest>
                      </xqx:stepExpr>
                    </xqx:expr>
                    <xqx:expr xsi:type="xqx:pathExpr">
                      <xqx:argExpr>
                        <xqx:expr xsi:type="xqx:varRef">
                          <xqx:name>b</xqx:name>
                        </xqx:expr>
                      </xqx:argExpr>
                      <xqx:stepExpr>
                        <xqx:xpathAxis>child</xqx:xpathAxis>
                        <xqx:nameTest>title</xqx:nameTest>
                      </xqx:stepExpr>
                    </xqx:expr>
                </xqx:elementContent>
              </xqx:expr>
            </xqx:returnClause>
          </xqx:expr>
        </xqx:elementContent>
      </xqx:expr>
    </xqx:queryBody>
  </xqx:mainModule>
</xqx:module>

3.3.3 Test:

Applying the stylesheet in B Transforming XQueryX to XQuery to the XQueryX solution, we get:

<bib>{
 for $b in doc("http://bstore1.example.com/bib.xml")/descendant-or-self::book
 where (($b/child::publisher = "Addison-Wesley") and ($b/attribute::year > 1991))
 order by $b/child::title 
 return <book>{$b/attribute::year}{$b/child::title}</book>
}</bib>

4 An XML Schema for the XQuery XML Syntax

Here is the XML Schema for the proposed syntax.

Editorial note  
In this Working Draft, the XML Schema for the XQuery XML syntax has been hand-crafted. The XML Query Working Group is working towards automatic generation of the Schema from the XQuery grammar.
<?xml version="1.0"?>
<xsd:schema xmlns="http://www.w3.org/2005/04/XQueryX" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            targetNamespace="http://www.w3.org/2005/04/XQueryX" 
            elementFormDefault="qualified" 
            attributeFormDefault="qualified">
  <!--
  Version 1.3 of the XQueryX schema.
  Authors: Jim Melton (Oracle Corp.), S. Muralidhar (Microsoft)

  Modification date: 2005-04-04
     - Minor cleanup in preparation for Last Call Working Draft

  Modification date: 2005-02-17
     - Type exprList is now a sequence of "expr" (not exprWrapper anymore)
     - sequenceExpr now has an explicit sequence of "expr";
       (was previously, a single element of type "exprList")
     - Renamed child element "parameters" of functionCallExpr to "arguments"
     - Renamed child element "parameters" of operatorExpr to "arguments"
     - Removed element "exprList"
     - Removed element "exprWrapper"
     - Removed child element "encoding" from element "xqx:versionDecl"
     - Added new element xqx:xquery (to represent the trivial embedding)

  Modification date: Feb 4, 2004
     - Bring inline with XQuery language W3C Working Draft 10/29/04
     - More uniform naming conventions
     - Some stylistic issues

  The main data structure in this schema is the set of types that describe
  expressions. We've chosen to model expressions as an inheritance 
  hierarchy, with an "expr" abstract base class.  With some significant
  difficulty, this decision could be changed to use substitution groups,
  but the benefits seem too little to justify the effort required. 
  
  All expression instances are elements with the name "expr" and the 
  type attribute set to the most-specific type.
  The different types for expressions correspond to the different kinds
  of expressions that we support - constants, variables, functions, 
  builtins, flwor expressions and so on.

  We've tried to avoid attributes as far as possible (modulo the "type" 
  attribute for expressions), and model these as elements - this is a 
  perfectly arbitrary decision, and can be reversed.

  We've attempted to create an "exprWrapper" type/element. In most embedded
  cases, we use this construct, instead of the "expr" element itself - just
  because I might want to name the element differently.  

  We've also chosen to model the set of builtin operator types as an 
  inheritance hierarchy - mainly because it tended to group things 
  nicely. I don't see a problem with making this simply a large union.
 -->

  <!-- A few helper declarations -->
  <xsd:complexType name="emptyContent"/>
  <xsd:element name="QName" type="xsd:QName"/>
  <xsd:element name="NCName" type="xsd:NCName"/>

  <!-- The base class -->
  <xsd:complexType name="expr"/>
  <xsd:element name="expr" type="expr"/>
  <!-- A list of expressions -->
  <xsd:complexType name="exprList">
    <xsd:sequence>
      <xsd:element ref="expr" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>

  <!-- Simple wrapper class -->
  <xsd:complexType name="exprWrapper">
    <xsd:sequence>
      <xsd:element ref="expr"/>
    </xsd:sequence>
  </xsd:complexType>

  <!-- constant expressions. We have 4 different subclasses for this -->
  <xsd:complexType name="constantExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="value" type="xsd:anyType"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="integerConstantExpr">
    <xsd:complexContent>
      <xsd:restriction base="constantExpr">
        <xsd:sequence>
          <xsd:element name="value" type="xsd:integer"/>
        </xsd:sequence>
      </xsd:restriction>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="decimalConstantExpr">
    <xsd:complexContent>
      <xsd:restriction base="constantExpr">
        <xsd:sequence>
          <xsd:element name="value" type="xsd:decimal"/>
        </xsd:sequence>
      </xsd:restriction>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="doubleConstantExpr">
    <xsd:complexContent>
      <xsd:restriction base="constantExpr">
        <xsd:sequence>
          <xsd:element name="value" type="xsd:double"/>
        </xsd:sequence>
      </xsd:restriction>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="stringConstantExpr">
    <xsd:complexContent>
      <xsd:restriction base="constantExpr">
        <xsd:sequence>
          <xsd:element name="value" type="xsd:string"/>
        </xsd:sequence>
      </xsd:restriction>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- Variables -->
  <xsd:complexType name="varRef">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="name" type="xsd:QName"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- root and context-item expressions -->
  <xsd:complexType name="rootExpr">
    <xsd:complexContent>
      <xsd:extension base="expr"/>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="contextItemExpr">
    <xsd:complexContent>
      <xsd:extension base="expr"/>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- Pragmas and extension expressions -->  
  <xsd:element name="pragma">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="pragmaName" type="xsd:QName"/>
        <xsd:element name="pragmaContents" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:complexType name="extensionExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element ref="pragma" maxOccurs="unbounded"/>
          <xsd:element name="argExpr" type="exprWrapper"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="functionCallExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="functionName" type="xsd:QName"/>
          <xsd:element name="arguments" type="exprList" minOccurs="0"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- Constructor functions -->
  <xsd:complexType name="constructorFunctionExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="typeName" type="xsd:QName"/>
          <xsd:element name="argExpr" type="exprWrapper"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="sequenceExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element ref="expr" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="rangeSequenceExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="startExpr" type="exprWrapper"/>
          <xsd:element name="endExpr" type="exprWrapper"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- Inheritance hierarchy for operator types -->
  <xsd:simpleType name="opTypes">
    <xsd:restriction base="xsd:string"/>
  </xsd:simpleType>
  <!-- All comparison operators -->
  <xsd:simpleType name="comparisonOpTypes">
    <xsd:restriction base="opTypes"/>
  </xsd:simpleType>
  <!-- All arithmetic operators -->
  <xsd:simpleType name="arithmeticOpTypes">
    <xsd:restriction base="opTypes">
      <xsd:enumeration value="+"/>
      <xsd:enumeration value="-"/>
      <xsd:enumeration value="div"/>
      <xsd:enumeration value="idiv"/>
      <xsd:enumeration value="mod"/>
      <xsd:enumeration value="unaryMinus"/>
      <xsd:enumeration value="unaryPlus"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="valueComparisonOpTypes">
    <xsd:restriction base="comparisonOpTypes">
      <xsd:enumeration value="eq"/>
      <xsd:enumeration value="ne"/>
      <xsd:enumeration value="gt"/>
      <xsd:enumeration value="ge"/>
      <xsd:enumeration value="lt"/>
      <xsd:enumeration value="le"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="generalComparisonOpTypes">
    <xsd:restriction base="comparisonOpTypes">
      <xsd:enumeration value="="/>
      <xsd:enumeration value="!="/>
      <xsd:enumeration value="&lt;"/>
      <xsd:enumeration value="&lt;="/>
      <xsd:enumeration value="&gt;="/>
      <xsd:enumeration value="&gt;="/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="nodeComparisonOpTypes">
    <xsd:restriction base="comparisonOpTypes">
      <xsd:enumeration value="is"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="orderComparisonOpTypes">
    <xsd:restriction base="comparisonOpTypes">
      <xsd:enumeration value="&lt;&lt;"/>
      <xsd:enumeration value="&gt;&gt;"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="logicalOpTypes">
    <xsd:restriction base="opTypes">
      <xsd:enumeration value="and"/>
      <xsd:enumeration value="or"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="miscOpTypes">
    <xsd:restriction base="opTypes">
      <xsd:enumeration value="union"/>
      <xsd:enumeration value="intersect"/>
      <xsd:enumeration value="except"/>
    </xsd:restriction>
  </xsd:simpleType>
  <!-- This class describes all builtin-operators -->
  <xsd:complexType name="operatorExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="infixOp" type="emptyContent" minOccurs="0"/>
          <xsd:element name="opType" type="opTypes"/>
          <xsd:element name="arguments" type="exprList"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- Basic typenames -->
  <xsd:element name="atomicType" type="xsd:QName"/>
  <!-- Used in castable expression -->
  <xsd:element name="singleType">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="atomicType"/>
        <xsd:element name="optional" type="emptyContent" minOccurs="0"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:group name="itemType">
    <xsd:choice>
      <xsd:element ref="atomicType"/>
      <xsd:group ref="kindTest"/>
      <xsd:element name="anyItemType" type="emptyContent"/>
    </xsd:choice>
  </xsd:group>
  <xsd:simpleType name="occurrenceIndicator">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="?"/>
      <xsd:enumeration value="*"/>
      <xsd:enumeration value="+"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:complexType name="sequenceType">
    <xsd:choice>
      <xsd:element name="voidSequenceType" type="emptyContent"/>
      <xsd:sequence>
        <xsd:group ref="itemType"/>
        <xsd:element name="occurrenceIndicator" 
                     type="occurrenceIndicator" 
                     minOccurs="0"/>
      </xsd:sequence>
    </xsd:choice>
  </xsd:complexType>
  <xsd:element name="sequenceType" type="sequenceType"/>
  <xsd:element name="typeDeclaration" type="sequenceType"/>

  <!-- Represents a "typed" variable (for clause, let clause etc) -->
  <xsd:element name="typedVariableBinding">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="varName" type="xsd:QName"/>
        <xsd:element ref="typeDeclaration" minOccurs="0"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="positionalVariableBinding" type="xsd:QName"/>
  <xsd:element name="variableBinding" type="xsd:QName"/>

  <xsd:element name="forClauseItem">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="typedVariableBinding"/>
        <xsd:element ref="positionalVariableBinding" minOccurs="0"/>
        <xsd:element name="forExpr" type="exprWrapper"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="forClause">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="forClauseItem" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="letClauseItem">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="typedVariableBinding"/>
        <xsd:element name="letExpr" type="exprWrapper"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="letClause">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="letClauseItem" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="whereClause" type="exprWrapper"/>
  <xsd:element name="returnClause" type="exprWrapper"/>
  <xsd:simpleType name="emptyOrderingMode">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="empty greatest"/>
      <xsd:enumeration value="empty least"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:simpleType name="orderingKind">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="ascending"/>
      <xsd:enumeration value="descending"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:element name="orderModifier">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="orderingKind" type="orderingKind" 
                     minOccurs="0" maxOccurs="unbounded">
        </xsd:element>
        <xsd:element name="emptyOrderingMode" type="emptyOrderingMode"
                     minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element name="collation" type="xsd:string" minOccurs="0"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="orderBySpec">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="orderByExpr" type="exprWrapper"/>
        <xsd:element ref="orderModifier" minOccurs="0"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="orderByClause">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="stable" type="emptyContent" minOccurs="0"/>
        <xsd:element ref="orderBySpec" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <!-- This is the flwor expression -->
  <xsd:complexType name="flworExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:choice maxOccurs="unbounded">
            <xsd:element ref="forClause"/>
            <xsd:element ref="letClause"/>
          </xsd:choice>
          <xsd:element ref="whereClause" minOccurs="0"/>
          <xsd:element ref="orderByClause" minOccurs="0"/>
          <xsd:element ref="returnClause"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- conditional expressions -->
  <xsd:complexType name="ifThenElseExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="ifClause" type="exprWrapper"/>
          <xsd:element name="thenClause" type="exprWrapper"/>
          <xsd:element name="elseClause" type="exprWrapper"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- The following clauses describe quantified expressions -->
  <xsd:simpleType name="quantifier">
    <xsd:restriction base="xsd:NMTOKEN">
      <xsd:enumeration value="some"/>
      <xsd:enumeration value="every"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:element name="quantifiedExprInClause">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="typedVariableBinding"/>
        <xsd:element name="sourceExpr" type="exprWrapper"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:complexType name="quantifiedExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="quantifier" type="quantifier"/>
          <xsd:element ref="quantifiedExprInClause" maxOccurs="unbounded"/>
          <xsd:element name="predicateExpr" type="exprWrapper"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- handle the typeswitch construct -->
  <xsd:complexType name="typeswitchExprCaseClause">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element ref="variableBinding" minOccurs="0"/>
          <xsd:element ref="typeDeclaration"/>
          <xsd:element name="resultExpr" type="exprWrapper"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="typeswitchExprDefaultClause">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element ref="variableBinding" minOccurs="0"/>
          <xsd:element name="resultExpr" type="exprWrapper"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="typeswitchExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="argExpr" type="exprWrapper"/>
          <xsd:element name="typeswitchExprCaseClause" 
                       type="typeswitchExprCaseClause" 
                       maxOccurs="unbounded"/>
          <xsd:element name="typeswitchExprDefaultClause"
                       type="typeswitchExprDefaultClause"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- instance-of expressions -->
  <xsd:complexType name="instanceOfExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="argExpr" type="exprWrapper"/>
          <xsd:element ref="sequenceType"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- treat-as expressions -->
  <xsd:complexType name="treatExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="argExpr" type="exprWrapper"/>
          <xsd:element ref="sequenceType"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- castable and cast expressions -->
  <xsd:complexType name="castableExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="argExpr" type="exprWrapper"/>
          <xsd:element ref="singleType"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="castExpr">
    <xsd:complexContent>
      <xsd:extension base="expr"> 
        <xsd:sequence>
          <xsd:element name="argExpr" type="exprWrapper"/>
          <xsd:element ref="singleType"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- Validate expressions -->
  <xsd:simpleType name="validationMode">
    <xsd:restriction base="xsd:NMTOKEN">
      <xsd:enumeration value="lax"/>
      <xsd:enumeration value="strict"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:complexType name="validateExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="validationMode" type="validationMode" 
                       minOccurs="0"/>
          <xsd:element name="argExpr" type="exprWrapper"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- Direct constructors. Only elementConstructor for now -->
  <!-- Note the absence of constructors corresponding to
       the directCommentConstructor and the directPIConstructor
       productions in the XQuery grammar. This is because they are
       trivially identical to the computed variants
    -->
  <!-- attributeConstructor is no longer a subclass of expr -->
  <xsd:complexType name="attributeConstructor">
    <xsd:sequence>
      <xsd:element name="attributeName" type="xsd:QName"/>
      <xsd:choice>
        <xsd:element name="attributeValueExpr" type="exprWrapper"/>
        <xsd:element name="attributeValue" type="xsd:string"/>
      </xsd:choice>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:element name="attributeList">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="attributeConstructor" 
                     type="attributeConstructor" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="elementContent" type="exprList"/>
  <xsd:complexType name="elementConstructor">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="tagName" type="xsd:QName"/>
          <xsd:element ref="attributeList" minOccurs="0"/>
          <xsd:element ref="elementContent" minOccurs="0"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- computed constructors -->
  <xsd:complexType name="computedElementConstructor">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:choice>
            <xsd:element name="tagName" type="xsd:QName"/>
            <xsd:element name="tagNameExpr" type="exprWrapper"/>
          </xsd:choice>
          <xsd:element name="contentExpr" type="exprWrapper" minOccurs="0"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="computedAttributeConstructor">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:choice>
            <xsd:element name="tagName" type="xsd:QName"/>
            <xsd:element name="tagNameExpr" type="exprWrapper"/>
          </xsd:choice>
          <xsd:element name="valueExpr" type="exprWrapper" minOccurs="0"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="computedDocumentConstructor">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="argExpr" type="exprWrapper"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="computedTextConstructor">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="argExpr" type="exprWrapper" minOccurs="0"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="computedCommentConstructor">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="argExpr" type="exprWrapper"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="computedPIConstructor">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:choice>
            <xsd:element name="piTarget" type="xsd:NCName"/>
            <xsd:element name="piTargetExpr" type="exprWrapper"/>
          </xsd:choice>
          <xsd:element name="piValueExpr" type="exprWrapper" minOccurs="0"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- ordered and unordered expressions -->
  <xsd:complexType name="unorderedExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="argExpr" type="exprWrapper"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="orderedExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="argExpr" type="exprWrapper"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="simpleWildcard">
    <xsd:choice>
      <xsd:element name="QName" type="xsd:QName"/>
      <xsd:element name="star" type="emptyContent"/>
    </xsd:choice>
  </xsd:complexType>
  <xsd:element name="Wildcard">
    <xsd:complexType>
      <xsd:all>
        <xsd:element name="star" type="emptyContent" minOccurs="0"/>
        <xsd:element ref="NCName" minOccurs="0"/>
      </xsd:all>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="attributeTest">
    <xsd:complexType>
      <xsd:sequence minOccurs="0">
        <xsd:element name="attributeName" type="simpleWildcard"/>
        <xsd:element name="typeName" type="xsd:QName" minOccurs="0"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="schemaElementTest" type="xsd:QName"/>
  <xsd:element name="schemaAttributeTest" type="xsd:QName"/>
  <xsd:element name="elementTest">
    <xsd:complexType>
      <xsd:sequence minOccurs="0">
        <xsd:element name="elementName" type="simpleWildcard"/>
        <xsd:sequence minOccurs="0">
          <xsd:element name="typeName" type="xsd:QName"/>
          <xsd:element name="nillable" type="emptyContent" minOccurs="0"/>
        </xsd:sequence>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="documentTest">
    <xsd:complexType>
      <xsd:choice minOccurs="0">
        <xsd:element ref="elementTest"/>
        <xsd:element ref="schemaElementTest"/>
      </xsd:choice>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="piTest">
    <xsd:complexType>
      <xsd:choice minOccurs="0">
        <xsd:element name="piTarget" type="xsd:NCName"/>
        <xsd:element name="piValue" type="xsd:string"/>
      </xsd:choice>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="nameTest" type="xsd:QName"/>
  <xsd:group name="kindTest">
    <xsd:choice>
      <xsd:element ref="elementTest"/>
      <xsd:element ref="schemaElementTest"/>
      <xsd:element ref="attributeTest"/>
      <xsd:element ref="schemaAttributeTest"/>
      <xsd:element name="textTest" type="emptyContent"/>
      <xsd:element name="commentTest" type="emptyContent"/>
      <xsd:element name="anyKindTest" type="emptyContent"/>
      <xsd:element ref="documentTest"/>
      <xsd:element ref="piTest"/>
    </xsd:choice>
  </xsd:group>
  <xsd:element name="xpathAxis">
    <xsd:simpleType>
      <xsd:restriction base="xsd:NMTOKEN">
        <xsd:enumeration value="child"/>
        <xsd:enumeration value="attribute"/>
        <xsd:enumeration value="self"/>
        <xsd:enumeration value="parent"/>
        <xsd:enumeration value="descendant-or-self"/>
        <xsd:enumeration value="descendant"/>
        <xsd:enumeration value="following"/>
        <xsd:enumeration value="following-sibling"/>
        <xsd:enumeration value="ancestor"/>
        <xsd:enumeration value="ancestor-or-self"/>
        <xsd:enumeration value="preceding"/>
        <xsd:enumeration value="preceding-sibling"/>
      </xsd:restriction>
    </xsd:simpleType>
  </xsd:element>
  <xsd:element name="stepExpr">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="xpathAxis"/>
        <xsd:choice>
          <xsd:group ref="kindTest"/>
          <xsd:element ref="nameTest"/>
          <xsd:element ref="Wildcard"/>
        </xsd:choice>
        <xsd:element name="predicates" type="exprList" minOccurs="0"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:complexType name="pathExpr">
    <xsd:complexContent>
      <xsd:extension base="expr">
        <xsd:sequence>
          <xsd:element name="argExpr" type="exprWrapper"/>
          <xsd:element name="predicates" type="exprList" minOccurs="0"/>
          <xsd:element ref="stepExpr" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <!-- The following constructs deal with the query prolog -->
  <xsd:element name="module">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="versionDecl" minOccurs="0"/>
        <xsd:choice>
          <xsd:element ref="mainModule"/>
          <xsd:element ref="libraryModule"/>
        </xsd:choice>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="mainModule">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="prolog" minOccurs="0"/>
        <xsd:element name="queryBody" type="exprWrapper"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:complexType name="namespaceDeclType">
    <xsd:sequence>
      <xsd:element name="prefix" type="xsd:NCName"/>
      <xsd:element name="uri" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:element name="namespaceDecl" type="namespaceDeclType"/>
  <xsd:element name="moduleDecl" type="namespaceDeclType"/>
  <xsd:element name="libraryModule">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="moduleDecl"/>
        <xsd:element ref="prolog" minOccurs="0"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="versionDecl">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="version" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="prolog">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
          <xsd:element ref="boundarySpaceDecl"/>
          <xsd:element ref="defaultCollationDecl"/>
          <xsd:element ref="baseUriDecl"/>
          <xsd:element ref="constructionDecl"/>
          <xsd:element ref="orderingModeDecl"/>
          <xsd:element ref="emptyOrderingDecl"/>
          <xsd:element ref="copyNamespacesDecl"/>
        </xsd:choice>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
          <xsd:element ref="defaultNamespaceDecl"/>
          <xsd:element ref="namespaceDecl"/>
          <xsd:element ref="schemaImport"/>
          <xsd:element ref="moduleImport"/>
        </xsd:choice>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
          <xsd:element ref="varDecl"/>
          <xsd:element ref="functionDecl"/>
          <xsd:element ref="optionDecl"/>
        </xsd:choice>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="boundarySpaceDecl">
    <xsd:simpleType>
      <xsd:restriction base="xsd:NMTOKEN">
        <xsd:enumeration value="strip"/>
        <xsd:enumeration value="preserve"/>
      </xsd:restriction>
    </xsd:simpleType>
  </xsd:element>
  <xsd:element name="defaultCollationDecl" type="xsd:string"/>
  <xsd:element name="baseUriDecl" type="xsd:string"/>
  <xsd:element name="orderingModeDecl">
    <xsd:simpleType>
      <xsd:restriction base="xsd:NMTOKEN">
        <xsd:enumeration value="ordered"/>
        <xsd:enumeration value="unordered"/>
      </xsd:restriction>
    </xsd:simpleType>
  </xsd:element>
  <xsd:element name="emptyOrderingDecl" type="emptyOrderingMode"/>

  <xsd:element name="constructionDecl">
    <xsd:simpleType>
      <xsd:restriction base="xsd:NMTOKEN">
        <xsd:enumeration value="strip"/>
        <xsd:enumeration value="preserve"/>
      </xsd:restriction>
    </xsd:simpleType>
  </xsd:element>
  <xsd:element name="copyNamespacesDecl">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="preserveMode">
          <xsd:simpleType>
            <xsd:restriction base="xsd:NMTOKEN">
              <xsd:enumeration value="preserve"/>
              <xsd:enumeration value="no-preserve"/>
            </xsd:restriction>
          </xsd:simpleType>
        </xsd:element>
        <xsd:element name="inheritMode">
          <xsd:simpleType>
            <xsd:restriction base="xsd:NMTOKEN">
              <xsd:enumeration value="inherit"/>
              <xsd:enumeration value="no-inherit"/>
            </xsd:restriction>
          </xsd:simpleType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:simpleType name="defaultNamespaceCategory">
    <xsd:restriction base="xsd:NMTOKEN">
      <xsd:enumeration value="function"/>
      <xsd:enumeration value="element"/>
    </xsd:restriction>
  </xsd:simpleType>
  <xsd:element name="defaultNamespaceDecl">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="defaultNamespaceCategory" 
                     type="defaultNamespaceCategory"/>
        <xsd:element name="uri" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="varDecl">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="varName" type="xsd:QName"/>
        <xsd:element ref="typeDeclaration" minOccurs="0"/>
        <xsd:choice>
          <xsd:element name="varValue" type="exprWrapper"/>
          <xsd:element name="external" type="emptyContent"/>
        </xsd:choice>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="optionDecl">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="optionName" type="xsd:QName"/>
        <xsd:element name="optionContents" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="param">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="varName" type="xsd:QName"/>
        <xsd:element ref="typeDeclaration" minOccurs="0"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="paramList">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="param" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="functionDecl">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="functionName" type="xsd:QName"/>
        <xsd:element ref="paramList"/>
        <xsd:element ref="typeDeclaration" minOccurs="0"/>
        <xsd:choice>
          <xsd:element name="functionBody" type="exprWrapper"/>
          <xsd:element name="externalDefinition" type="emptyContent"/>
        </xsd:choice>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="moduleImport">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="namespacePrefix" type="xsd:NCName" minOccurs="0"/>
        <xsd:element name="targetNamespace" type="xsd:string"/>
        <xsd:element name="targetLocation" type="xsd:string" 
                     minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="schemaImport">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:choice minOccurs="0">
          <xsd:element name="namespacePrefix" type="xsd:NCName"/>
          <xsd:element name="defaultElementNamespace" type="emptyContent"/>
        </xsd:choice>
        <xsd:element name="targetNamespace" type="xsd:string"/>
        <xsd:element name="targetLocation" type="xsd:string" 
                     minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <!-- The element below handles the trivial XQuery embedding -->
  <xsd:element name="xquery" type="xsd:string"/>

</xsd:schema>

5 A Trivial Embedding of XQuery

1 Introduction observed that the [XML Query 1.0 Requirements] says "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." There are many possible ways to define an XML syntax for XQuery. This document specifies two XML Syntaxes for XQuery: the one in 4 An XML Schema for the XQuery XML Syntax and the "trivial embedding" defined in this section. Of course, XQueries could be expressed in XML Syntax in other ways.

The trivial embedding specified here can be used when an XQuery is exchanged with other entities as XML or embedded in an XML document, and when it is not necessary to communicate the underying structure of the query.

The trivial embedding defined in this specification requires that the entire query be enclosed within an element named "xquery" in the XQueryX namespace (the "xqx:" namespace prefix is used here only for the purposes of this example), as illustrated here:

<xqx:xquery>for $i... let $j...where $x = $y...return...</xqx:xquery>

If the XQuery contains characters that are prohibited in XML text (such as < and &), they must be "escaped" as either character entity references or character references.

<xqx:xquery>for $i... let $j...where $x &lt; $y...return...</xqx:xquery>

or

<xqx:xquery>for $i... let $j...where $x &x003C; $y...return...</xqx:xquery>

This limitation may require that user agents scan the XQuery text, escaping such prohibited characters, before transmitting or embedding the XQuery as XML.

A References

XML Query 1.0 Requirements
World Wide Web Consortium. XML Query (XQuery) Requirements. W3C Working Draft, 2003-11-12. Available at: http://www.w3.org/TR/2003/WD-xquery-requirements-20031112/.
XQuery 1.0: An XML Query Language
World Wide Web Consortium. XQuery 1.0: An XML Query Language. W3C Public Working Draft, 2005-04-04. Available at: http://www.w3.org/TR/2005/WD-xquery-20050404/.
XML Query Use Cases
World Wide Web Consortium. XML Query Use Cases. W3C Public Working Draft, 2003-11-12. See http://www.w3.org/TR/2003/WD-xquery-use-cases-20031112/.
XQuery 1.0 Formal Semantics
World Wide Web Consortium. XQuery 1.0 and XPath 2.0 Formal Semantics. W3C Public Working Draft, 2005-04-04. See http://www.w3.org/TR/2005/WD-xquery-semantics-20050404/.
Uniform Resource Locators (URL)
Internet Engineering Task Force (IETF). Uniform Resource Locators (URL). Request For Comments No. 1738, Dec. 1994. Available at: http://www.ietf.org/rfc/rfc1738.txt.

B Transforming XQueryX to XQuery

The following stylesheet converts from XQueryX syntax to XML Query syntax. Note the intent of the stylesheet is to produce a valid XQuery with the same semantics as the input XQueryX.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xqx="http://www.w3.org/2005/04/XQueryX">

  <xsl:output method="text"/>
  <xsl:strip-space elements="*"/>

  <xsl:variable name="DOT">.</xsl:variable>
  <xsl:variable name="SPACE"><xsl:text> </xsl:text></xsl:variable>
  <xsl:variable name="SLASH"><xsl:text>/</xsl:text></xsl:variable>
  <xsl:variable name="SLASH_SLASH"><xsl:text>//</xsl:text></xsl:variable>
  <xsl:variable name="LESSTHAN"><xsl:text>&lt;</xsl:text></xsl:variable>
  <xsl:variable name="GREATERTHAN"><xsl:text>&gt;</xsl:text></xsl:variable>
  <xsl:variable name="LPAREN">(</xsl:variable>
  <xsl:variable name="RPAREN">)</xsl:variable>
  <xsl:variable name="NEWLINE"><xsl:text>
</xsl:text></xsl:variable>
  <xsl:variable name="COMMA">,</xsl:variable>
  <xsl:variable name="COMMA_SPACE">, </xsl:variable>
  <xsl:variable name="COMMA_NEWLINE"><xsl:text>,
</xsl:text></xsl:variable>
  <xsl:variable name="QUOTE"><xsl:text>'</xsl:text></xsl:variable>
  <xsl:variable name="DOUBLEQUOTE"><xsl:text>"</xsl:text></xsl:variable>
  <xsl:variable name="TRUE"><xsl:text>true</xsl:text></xsl:variable>
  <xsl:variable name="TO"><xsl:text> to </xsl:text></xsl:variable>
  <xsl:variable name="LBRACE"><xsl:text>{</xsl:text></xsl:variable>
  <xsl:variable name="RBRACE"><xsl:text>}</xsl:text></xsl:variable>
  <xsl:variable name="LBRACKET"><xsl:text>[</xsl:text></xsl:variable>
  <xsl:variable name="RBRACKET"><xsl:text>]</xsl:text></xsl:variable>
  <xsl:variable name="DOLLAR"><xsl:text>$</xsl:text></xsl:variable>
  <xsl:variable name="MINUS"><xsl:text>-</xsl:text></xsl:variable>
  <xsl:variable name="PLUS"><xsl:text>+</xsl:text></xsl:variable>
  <xsl:variable name="EQUAL"><xsl:text>=</xsl:text></xsl:variable>
  <xsl:variable name="COLON"><xsl:text>:</xsl:text></xsl:variable>
  <xsl:variable name="DOUBLE_COLON"><xsl:text>::</xsl:text></xsl:variable>
  <xsl:variable name="SEMICOLON"><xsl:text>;</xsl:text></xsl:variable>
  <xsl:variable name="AT"><xsl:text>@</xsl:text></xsl:variable>
  <xsl:variable name="STAR"><xsl:text>*</xsl:text></xsl:variable>
  <xsl:variable name="QUESTIONMARK"><xsl:text>?</xsl:text></xsl:variable>
  <xsl:variable name="ASSIGN">
    <xsl:value-of select="$COLON"/>
    <xsl:value-of select="$EQUAL"/>
  </xsl:variable>
  <xsl:variable name="SEPARATOR">
    <xsl:value-of select="$SEMICOLON"/>
  </xsl:variable>
  <xsl:variable name="COMMENT_BEGIN">
    <xsl:text>&lt;!--</xsl:text>
  </xsl:variable>
  <xsl:variable name="COMMENT_END">
    <xsl:text>--&gt;</xsl:text>
  </xsl:variable>
  <xsl:variable name="PI_BEGIN">
    <xsl:text>&lt;?</xsl:text>
  </xsl:variable>
  <xsl:variable name="PI_END">
    <xsl:text>?&gt;</xsl:text>
  </xsl:variable>
  <xsl:variable name="CDATA_BEGIN">
    <xsl:text>&lt;![CDATA[</xsl:text>
  </xsl:variable>
  <xsl:variable name="CDATA_END">
    <xsl:text>]&gt;</xsl:text>
  </xsl:variable>
  <xsl:variable name="PRAGMA_BEGIN">
    <xsl:text>(# </xsl:text>
  </xsl:variable>
  <xsl:variable name="PRAGMA_END">
    <xsl:text> #)</xsl:text>
  </xsl:variable>

  <xsl:template name="delimitedList">
    <xsl:param name="delimiter" />
    <xsl:param name="leftEncloser"/>
    <xsl:param name="rightEncloser" />
    <xsl:param name="selector"></xsl:param>

    <xsl:value-of select="$leftEncloser"/>
    <xsl:for-each select="*">
      <xsl:apply-templates select="."/>
      <xsl:if test="not (position()=last())">         
        <xsl:value-of select="$delimiter"/>
      </xsl:if>        
    </xsl:for-each>
    <xsl:value-of select="$rightEncloser"/>
  </xsl:template>    

  <xsl:template name="paranthesizedList">
    <xsl:param name="delimiter" select="$COMMA_SPACE"/>
    <xsl:call-template name="delimitedList">
      <xsl:with-param name="delimiter" select="$delimiter" />
      <xsl:with-param name="leftEncloser" select="$LPAREN"/>
      <xsl:with-param name="rightEncloser" select="$RPAREN"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="commaSeparatedList">
    <xsl:call-template name="delimitedList">
      <xsl:with-param name="delimiter">
        <xsl:value-of select="$COMMA_SPACE"/>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="quote">
    <xsl:param name="item"/>
    <xsl:value-of select="$DOUBLEQUOTE"/>
    <xsl:value-of select="$item"/>
    <xsl:value-of select="$DOUBLEQUOTE"/>
  </xsl:template>

  <xsl:template match="xqx:*[@xsi:type='xqx:exprWrapper']">
    <xsl:apply-templates select="xqx:expr"/>
  </xsl:template>

  <xsl:template match="xqx:QName">
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="xqx:NCName">
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:rootExpr']">
    <xsl:value-of select="$SLASH"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:contextItemExpr']">
    <xsl:value-of select="$DOT"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:stringConstantExpr']">
    <xsl:call-template name="quote">
      <xsl:with-param name="item" select="xqx:value/text()"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:integerConstantExpr'
      or @xsi:type='xqx:decimalConstantExpr' 
      or xqx:type='xsd:doubleConstantExpr']">
    <xsl:value-of select="xqx:value/text()"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:varRef']">
    <xsl:value-of select="$DOLLAR"/>
    <xsl:value-of select="xqx:name/text()"/>
  </xsl:template>

  <xsl:template match="xqx:pragma">
    <xsl:value-of select="$PRAGMA_BEGIN"/>
    <xsl:value-of select="xqx:pragmaName"/>
    <xsl:value-of select="$SPACE"/>
    <xsl:value-of select="xqx:pragmaContents"/>
    <xsl:value-of select="$PRAGMA_END"/>
  </xsl:template>
  <xsl:template match="xqx:expr[@xsi:type='xqx:extensionExpr']">
    <xsl:apply-templates select="xqx:pragma"/>
    <xsl:value-of select="$LBRACE"/>
    <xsl:apply-templates select="xqx:enclosedExpr"/>
    <xsl:value-of select="$RBRACE"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:functionCallExpr']">
    <xsl:value-of select="xqx:functionName/text()"/>
    <xsl:for-each select="xqx:arguments">
      <xsl:call-template name="paranthesizedList"/>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:constructorFunctionExpr']">
    <xsl:value-of select="xqx:typeName"/>
    <xsl:for-each select="xqx:arg">
      <xsl:call-template name="paranthesizedList"/>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="xqx:opType">
    <xsl:choose>
      <xsl:when test="./text() = 'unaryMinus'">
        <xsl:value-of select="$MINUS"/>
      </xsl:when>
      <xsl:when test="./text() = 'unaryPlus'">
        <xsl:value-of select="$PLUS"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="./text()"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="operatorArgs">
    <xsl:param name="opType"/>
    <xsl:for-each select="xqx:arguments">
      <xsl:call-template name="paranthesizedList">
        <xsl:with-param name="delimiter">
          <xsl:value-of select="$SPACE"/>
          <xsl:value-of select="$opType"/>
          <xsl:value-of select="$SPACE"/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:operatorExpr']">
    <xsl:choose>
      <xsl:when test="xqx:infixOp">
        <xsl:call-template name="operatorArgs">
          <xsl:with-param name="opType" select="xqx:opType"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="xqx:opType"/>
        <xsl:for-each select="xqx:arguments">
          <xsl:call-template name="paranthesizedList"/>
        </xsl:for-each>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:sequenceExpr']">
    <xsl:for-each select="*">
      <xsl:call-template name="paranthesizedList">
        <xsl:with-param name="delimiter" select="$COMMA_NEWLINE"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:rangeSequenceExpr']">
    <xsl:value-of select="$LPAREN"/>
    <xsl:apply-templates select="xqx:startExpr"/>
    <xsl:value-of select="$TO"/>
    <xsl:apply-templates select="xqx:endExpr"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>

  <xsl:template match="xqx:forClause">
    <xsl:text> for </xsl:text>
    <xsl:call-template name="commaSeparatedList"/>
    <xsl:value-of select="$NEWLINE"/>
  </xsl:template>

  <xsl:template match="xqx:forClauseItem">
    <xsl:apply-templates select="xqx:typedVariableBinding"/>
    <xsl:apply-templates select="xqx:positionalVariableBinding"/>
    <xsl:text> in </xsl:text>
    <xsl:apply-templates select="xqx:forExpr"/>
  </xsl:template>

  <xsl:template match="xqx:letClauseItem">
    <xsl:apply-templates select="xqx:typedVariableBinding"/>
    <xsl:value-of select="$ASSIGN"/>
    <xsl:apply-templates select="xqx:letExpr"/>
  </xsl:template>

  <xsl:template match="xqx:letClause">
    <xsl:text> let </xsl:text>
    <xsl:call-template name="commaSeparatedList"/>
    <xsl:value-of select="$NEWLINE"/>
  </xsl:template>

  <xsl:template match="xqx:returnClause">
    <xsl:text> return </xsl:text>
    <xsl:apply-templates select="*"/>
    <xsl:value-of select="$NEWLINE"/>
  </xsl:template>

  <xsl:template match="xqx:whereClause">
    <xsl:text> where </xsl:text>
    <xsl:apply-templates select="*"/>
    <xsl:value-of select="$NEWLINE"/>
  </xsl:template>

  <xsl:template match="xqx:collation">
    <xsl:text> collation </xsl:text>
    <xsl:value-of select="$DOUBLEQUOTE"/>
    <xsl:value-of select="."/>
    <xsl:value-of select="$DOUBLEQUOTE"/>
  </xsl:template>
  <xsl:template match="xqx:emptyOrderingMode">
    <xsl:value-of select="$SPACE"/>
    <xsl:value-of select="."/>
  </xsl:template>
  <xsl:template match="xqx:orderingKind">
    <xsl:value-of select="$SPACE"/>
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="xqx:orderModifier">
    <xsl:apply-templates select="*"/>
  </xsl:template>

  <xsl:template match="xqx:orderBySpec">
    <xsl:apply-templates select="xqx:orderByExpr"/>
    <xsl:value-of select="$SPACE"/>
    <xsl:apply-templates select="xqx:orderModifier"/>
  </xsl:template>

  <xsl:template match="xqx:orderByClause">
    <xsl:if test="xqx:stable">
      <xsl:text> stable</xsl:text>
    </xsl:if>
    <xsl:text> order by </xsl:text>
    <xsl:apply-templates select="xqx:orderBySpec[1]"/>
    <xsl:for-each select="xqx:orderBySpec[position() > 1]">
      <xsl:value-of select="$COMMA_SPACE"/>
      <xsl:apply-templates select="."/>
    </xsl:for-each>
    <xsl:value-of select="$NEWLINE"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:flworExpr']">
    <xsl:value-of select="$NEWLINE"/>
    <xsl:apply-templates select="*"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:ifThenElseExpr']">
    <xsl:value-of select="$LPAREN"/>
    <xsl:text> if </xsl:text>
    <xsl:apply-templates select="xqx:ifClause"/>
    <xsl:text> then </xsl:text>
    <xsl:apply-templates select="xqx:thenClause"/>
    <xsl:text> else </xsl:text>
    <xsl:apply-templates select="xqx:elseClause"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>

  <xsl:template match="xqx:positionalVariableBinding">
    <xsl:text> at </xsl:text>
    <xsl:value-of select="$DOLLAR"/>
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="xqx:variableBinding">
    <xsl:value-of select="$DOLLAR"/>
    <xsl:value-of select="."/>
  </xsl:template>
  <xsl:template match="xqx:typedVariableBinding" name="typedVariableBinding">
    <xsl:value-of select="$DOLLAR"/>
    <xsl:value-of select="xqx:varName"/>
    <xsl:apply-templates select="xqx:typeDeclaration"/>
  </xsl:template>

  <xsl:template match="xqx:quantifiedExprInClause">
    <xsl:apply-templates select="xqx:typedVariableBinding"/>
    <xsl:text> in </xsl:text>
    <xsl:apply-templates select="xqx:sourceExpr"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:quantifiedExpr']">
    <xsl:value-of select="$LPAREN"/>
    <xsl:value-of select="xqx:quantifier"/>
    <xsl:value-of select="$SPACE"/>
    <xsl:apply-templates select="xqx:quantifiedExprInClause[1]"/>
    <xsl:for-each select="xqx:quantifiedExprInClause[position() > 1]">
      <xsl:value-of select="$COMMA_SPACE"/>
      <xsl:apply-templates select="."/>
    </xsl:for-each>
    <xsl:text> satisfies </xsl:text>
    <xsl:apply-templates select="xqx:predicateExpr"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:instanceOfExpr']">
    <xsl:value-of select="$LPAREN"/>
    <xsl:apply-templates select="xqx:argExpr"/>
    <xsl:text> instance of </xsl:text>
    <xsl:apply-templates select="xqx:sequenceType"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:castExpr']">
    <xsl:value-of select="$LPAREN"/>
    <xsl:apply-templates select="xqx:argExpr"/>
    <xsl:text> cast as </xsl:text>
    <xsl:apply-templates select="xqx:singleType"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:castableExpr']">
    <xsl:value-of select="$LPAREN"/>
    <xsl:apply-templates select="xqx:argExpr"/>
    <xsl:text> castable as </xsl:text>
    <xsl:apply-templates select="xqx:singleType"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:treatExpr']">
    <xsl:value-of select="$LPAREN"/>
    <xsl:apply-templates select="xqx:argExpr"/>
    <xsl:text> treat as </xsl:text>
    <xsl:apply-templates select="xqx:sequenceType"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>
    <xsl:template match="xqx:typeswitchExprCaseClause">
    <xsl:text> case </xsl:text>
    <xsl:apply-templates select="xqx:variableBinding"/>
    <xsl:apply-templates select="xqx:typeDeclaration"/>
    <xsl:text> return </xsl:text>
    <xsl:apply-templates select="xqx:resultExpr"/>
  </xsl:template>

  <xsl:template match="xqx:typeswitchExprDefaultClause">
    <xsl:text> default </xsl:text>
    <xsl:apply-templates select="xqx:variableBinding"/>
    <xsl:text> return </xsl:text>
    <xsl:apply-templates select="xqx:resultExpr"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:typeswitchExpr']">
    <xsl:value-of select="$LPAREN"/>
    <xsl:text>typeswitch</xsl:text>
    <xsl:value-of select="$LPAREN"/>
    <xsl:apply-templates select="xqx:argExpr"/>
    <xsl:value-of select="$RPAREN"/>
    <xsl:apply-templates select="xqx:typeswitchExprCaseClause"/>
    <xsl:apply-templates select="xqx:typeswitchExprDefaultClause"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:validateExpr']">
    <xsl:value-of select="$LPAREN"/>
    <xsl:text> validate </xsl:text>
    <xsl:value-of select="xqx:validationMode"/>
    <xsl:value-of select="$LBRACE"/>
    <xsl:apply-templates select="xqx:argExpr"/>
    <xsl:value-of select="$RBRACE"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>

  <xsl:template match="xqx:xpathAxis">
    <xsl:value-of select="."/>
    <xsl:value-of select="$DOUBLE_COLON"/>
  </xsl:template>

  <xsl:template match="xqx:predicates">
    <xsl:for-each select="*">
      <xsl:value-of select="$LBRACKET"/>
      <xsl:apply-templates select="."/>
      <xsl:value-of select="$RBRACKET"/>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="xqx:star">
    <xsl:value-of select="$STAR"/>
  </xsl:template>

  <xsl:template match="xqx:Wildcard">
    <xsl:apply-templates select="*[1]"/>
    <xsl:if test="*[2]">
      <xsl:value-of select="$COLON"/>
      <xsl:apply-templates select="*[2]"/>
    </xsl:if>
  </xsl:template>

  <xsl:template name="simpleWildcard" match="xqx:simpleWildcard">
    <xsl:apply-templates select="xqx:star"/>
    <xsl:apply-templates select="xqx:QName"/>
  </xsl:template>

  <xsl:template match="xqx:textTest">
    <xsl:text>text()</xsl:text>
  </xsl:template>
  <xsl:template match="xqx:commentTest">
    <xsl:text>comment()</xsl:text>
  </xsl:template>
  <xsl:template match="xqx:anyKindTest">
    <xsl:text>node()</xsl:text>
  </xsl:template>
  <xsl:template match="xqx:piTest">
    <xsl:text>processing-instruction</xsl:text>
    <xsl:value-of select="$LPAREN"/>
    <xsl:value-of select="*"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>
  <xsl:template match="xqx:documentTest">
    <xsl:text>document-node</xsl:text>
    <xsl:value-of select="$LPAREN"/>
    <xsl:apply-templates select="*"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>
  <xsl:template match="xqx:nameTest">
    <xsl:value-of select="."/>
  </xsl:template>
  <xsl:template match="xqx:attributeTest">
    <xsl:text>attribute</xsl:text>
    <xsl:value-of select="$LPAREN"/>
    <xsl:for-each select="xqx:attributeName">
      <xsl:call-template name="simpleWildcard"/>
    </xsl:for-each>
    <xsl:if test="xqx:typeName">
      <xsl:value-of select="$COMMA"/>
      <xsl:value-of select="xqx:typeName"/>
    </xsl:if>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>

  <xsl:template match="xqx:elementTest">
    <xsl:text>element</xsl:text>
    <xsl:value-of select="$LPAREN"/>
    <xsl:for-each select="xqx:elementName">
      <xsl:call-template name="simpleWildcard"/>
    </xsl:for-each>
    <xsl:if test="xqx:typeName">
      <xsl:value-of select="$COMMA"/>
      <xsl:value-of select="xqx:typeName"/>
    </xsl:if>
    <xsl:if test="xqx:nillable">
      <xsl:value-of select="$QUESTIONMARK"/>
    </xsl:if>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>

  <xsl:template match="xqx:schemaElementTest">
    <xsl:text>schema-element</xsl:text>
    <xsl:value-of select="$LPAREN"/>
    <xsl:value-of select="."/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>
  <xsl:template match="xqx:schemaAttributeTest">
    <xsl:text>schema-attribute</xsl:text>
    <xsl:value-of select="$LPAREN"/>
    <xsl:value-of select="."/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>

  <xsl:template match="xqx:stepExpr">
    <xsl:value-of select="$SLASH"/>
    <xsl:apply-templates select="*"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:pathExpr']">
    <xsl:apply-templates select="xqx:argExpr"/>
    <xsl:apply-templates select="xqx:predicates"/>
    <xsl:apply-templates select="xqx:stepExpr"/>
  </xsl:template>

  <xsl:template match="xqx:attributeConstructor">
    <xsl:value-of select="$SPACE"/>
    <xsl:value-of select="xqx:attributeName"/>
    <xsl:value-of select="$EQUAL"/>
    <xsl:value-of select="$DOUBLEQUOTE"/>
    <xsl:choose>
      <xsl:when test="xqx:attributeValue">
        <xsl:value-of select="xqx:attributeValue"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$LBRACE"/>
        <xsl:apply-templates select="xqx:attributeValueExpr"/>
        <xsl:value-of select="$RBRACE"/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:value-of select="$DOUBLEQUOTE"/>
  </xsl:template>

  <xsl:template match="xqx:attributeList">
    <xsl:apply-templates select="*"/>
  </xsl:template>

  <xsl:template match="xqx:elementContent">
    <xsl:for-each select="*">
      <xsl:value-of select="$LBRACE"/>
      <xsl:apply-templates select="*"/>
      <xsl:value-of select="$RBRACE"/>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:elementConstructor']">
    <xsl:value-of select="$LESSTHAN"/>
    <xsl:value-of select="xqx:tagName"/>
    <xsl:apply-templates select="xqx:attributeList"/>
    <xsl:value-of select="$GREATERTHAN"/>
    <xsl:apply-templates select="xqx:elementContent"/>
    <xsl:value-of select="$LESSTHAN"/>
    <xsl:value-of select="$SLASH"/>
    <xsl:value-of select="xqx:tagName"/>
    <xsl:value-of select="$GREATERTHAN"/>
  </xsl:template>

  <xsl:template match="xqx:tagNameExpr">
    <xsl:value-of select="$LBRACE"/>
    <xsl:apply-templates select="*"/>
    <xsl:value-of select="$RBRACE"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:computedElementConstructor']">
    <xsl:text> element </xsl:text>
    <xsl:apply-templates select="xqx:tagName"/>
    <xsl:apply-templates select="xqx:tagNameExpr"/>
    <xsl:value-of select="$LBRACE"/>
    <xsl:apply-templates select="xqx:contentExpr"/>     
    <xsl:value-of select="$RBRACE"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:computedAttributeConstructor']">
    <xsl:text> attribute </xsl:text>
    <xsl:apply-templates select="xqx:tagName"/>
    <xsl:apply-templates select="xqx:tagNameExpr"/>
    <xsl:value-of select="$LBRACE"/>
    <xsl:apply-templates select="xqx:valueExpr"/>     
    <xsl:value-of select="$RBRACE"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:computedDocumentConstructor']">
    <xsl:text> document {</xsl:text>
    <xsl:apply-templates select="*"/>
    <xsl:text> }</xsl:text>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:computedTextConstructor']">
    <xsl:text> text</xsl:text>
    <xsl:value-of select="$LBRACE"/>
    <xsl:apply-templates select="*"/>
    <xsl:value-of select="$RBRACE"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:computedCommentConstructor']">
    <xsl:text> comment</xsl:text>
    <xsl:value-of select="$LBRACE"/>
    <xsl:apply-templates select="*"/>
    <xsl:value-of select="$RBRACE"/>
  </xsl:template>

  <xsl:template match="xqx:piTargetExpr">
    <xsl:value-of select="$LBRACE"/>
    <xsl:apply-templates select="*"/>
    <xsl:value-of select="$RBRACE"/>
  </xsl:template>
  <xsl:template match="xqx:piValueExpr">
    <xsl:value-of select="$LBRACE"/>
    <xsl:apply-templates select="*"/>
    <xsl:value-of select="$RBRACE"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:computedPIConstructor']">
    <xsl:text> processing-instruction </xsl:text>
    <xsl:value-of select="xqx:piTarget"/>
    <xsl:apply-templates select="xqx:piTargetExpr"/>
    <xsl:apply-templates select="xqx:piValueExpr"/>
  </xsl:template>

  <xsl:template match="xqx:expr[@xsi:type='xqx:unorderedExpr']">
    <xsl:text> unordered( </xsl:text>
    <xsl:apply-templates select="*"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>
  <xsl:template match="xqx:expr[@xsi:type='xqx:orderedExpr']">
    <xsl:text> ordered( </xsl:text>
    <xsl:apply-templates select="*"/>
    <xsl:value-of select="$RPAREN"/>
  </xsl:template>

  <xsl:template match="xqx:versionDecl">
    <xsl:text> xquery version </xsl:text>
    <xsl:call-template name="quote">
      <xsl:with-param name="item" select="xqx:version"/>
    </xsl:call-template>
    <xsl:value-of select="$SEPARATOR"/>
    <xsl:value-of select="$NEWLINE"/>
  </xsl:template>

  <xsl:template match="xqx:namespaceDecl">
    <xsl:text> declare namespace </xsl:text>
    <xsl:value-of select="xqx:prefix"/>
    <xsl:value-of select="$EQUAL"/>
    <xsl:call-template name="quote">
      <xsl:with-param name="item" select="xqx:uri"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="xqx:defaultNamespaceDecl">
    <xsl:text> declare default </xsl:text>
    <xsl:value-of select="xqx:defaultNamespaceCategory"/>
    <xsl:text> namespace </xsl:text>
    <xsl:call-template name="quote">
      <xsl:with-param name="item" select="xqx:uri"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="xqx:defaultCollationDecl">
    <xsl:text> default collation </xsl:text>
    <xsl:call-template name="quote">
      <xsl:with-param name="item" select="."/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="xqx:baseUriDecl">
    <xsl:text> declare base-uri </xsl:text>
    <xsl:call-template name="quote">
      <xsl:with-param name="item" select="."/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="xqx:boundarySpaceDecl">
    <xsl:text> declare boundary-space </xsl:text>
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="xqx:constructionDecl">
    <xsl:text> declare construction </xsl:text>
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="xqx:orderingModeDecl">
    <xsl:text> declare ordering </xsl:text>
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="xqx:emptyOrderingDecl">
    <xsl:text> declare default ordering </xsl:text>
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="xqx:copyNamespacesDecl">
    <xsl:text> declare copy-namespaces </xsl:text>
    <xsl:value-of select="xqx:preserveMode"/>
    <xsl:value-of select="$COMMA"/>
    <xsl:value-of select="xqx:inheritMode"/>
  </xsl:template>

  <xsl:template match="xqx:optionDecl">
    <xsl:text> declare option </xsl:text>
    <xsl:value-of select="xqx:optionName"/>
    <xsl:value-of select="$SPACE"/>
    <xsl:value-of select="xqx:optionContents"/>
  </xsl:template>

  <xsl:template match="xqx:voidSequenceType">
    <xsl:text>void()</xsl:text>
  </xsl:template>

  <xsl:template match="xqx:occurrenceIndicator">
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="xqx:anyItemType">
    <xsl:text>item()</xsl:text>
  </xsl:template>

  <xsl:template match="xqx:sequenceType">
    <xsl:apply-templates select="*"/>
  </xsl:template>

  <xsl:template match="xqx:atomicType">
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="xqx:singleType">
    <xsl:apply-templates select="xqx:atomicType"/>
    <xsl:if test="xqx:optional">
      <xsl:text>?</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="xqx:typeDeclaration">
    <xsl:text> as </xsl:text>
    <xsl:apply-templates select="*"/>
  </xsl:template>

  <xsl:template match="xqx:varDecl">
    <xsl:text> declare variable </xsl:text>
    <xsl:value-of select="$DOLLAR"/>
    <xsl:value-of select="xqx:varName"/>
    <xsl:value-of select="$SPACE"/>
    <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>

  <xsl:template match="xqx:schemaImport">
    <xsl:text> import schema </xsl:text>
    <xsl:if test="xqx:defaultElementNamespace">
      <xsl:text> default element namespace </xsl:text>
    </xsl:if>
    <xsl:if test="xqx:namespacePrefix">
      <xsl:text> namespace </xsl:text>
      <xsl:value-of select="xqx:namespacePrefix"/>
      <xsl:value-of select="$EQUAL"/>
    </xsl:if>
    <xsl:call-template name="quote">
      <xsl:with-param name="item" select="xqx:targetNamespace"/>
    </xsl:call-template>
    <xsl:if test="xqx:targetLocation">
      <xsl:text> at </xsl:text>
      <xsl:call-template name="quote">
        <xsl:with-param name="item" select="xqx:targetLocation"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template match="xqx:moduleImport">
    <xsl:text> import module </xsl:text>
    <xsl:if test="xqx:namespacePrefix">
      <xsl:text> namespace </xsl:text>
      <xsl:value-of select="xqx:namespacePrefix"/>
      <xsl:value-of select="$EQUAL"/>
    </xsl:if>
    <xsl:call-template name="quote">
      <xsl:with-param name="item" select="xqx:targetNamespace"/>
    </xsl:call-template>
    <xsl:if test="xqx:targetLocation">
      <xsl:text> at </xsl:text>
      <xsl:call-template name="quote">
        <xsl:with-param name="item" select="xqx:targetLocation"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template match="xqx:param">
    <xsl:value-of select="$DOLLAR"/>
    <xsl:value-of select="xqx:varName"/>
    <xsl:apply-templates select="xqx:typeDeclaration"/>
  </xsl:template>

  <xsl:template match="xqx:paramList">
    <xsl:call-template name="paranthesizedList"/>
  </xsl:template>

  <xsl:template match="xqx:functionBody">
    <xsl:value-of select="$NEWLINE"/>
    <xsl:value-of select="$LBRACE"/>
    <xsl:value-of select="$NEWLINE"/>
    <xsl:apply-templates select="xqx:expr"/>
    <xsl:value-of select="$NEWLINE"/>
    <xsl:value-of select="$RBRACE"/>
  </xsl:template>

  <xsl:template match="xqx:functionDecl">
    <xsl:text> declare function </xsl:text>
    <xsl:value-of 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:template match="xqx:queryBody">
    <xsl:apply-templates select="*"/>
    <xsl:value-of select="$NEWLINE"/>
  </xsl:template>

  <xsl:template match="xqx:moduleDecl">
    <xsl:text> module </xsl:text>
    <xsl:value-of select="xqx:prefix"/>
    <xsl:value-of select="$EQUAL"/>
    <xsl:call-template name="quote">
      <xsl:with-param name="item" select="xqx:uri" />
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="xqx:prolog">
    <xsl:for-each select="*">
      <xsl:apply-templates select="."/>
      <xsl:value-of select="$SEPARATOR"/>
      <xsl:value-of select="$NEWLINE"/>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="xqx:libraryModule">
    <xsl:apply-templates select="xqx:moduleDecl"/>
    <xsl:apply-templates select="xqx:prolog"/>
  </xsl:template>

  <xsl:template match="xqx:mainModule">
    <xsl:apply-templates select="xqx:prolog"/>
    <xsl:apply-templates select="xqx:queryBody"/>
  </xsl:template>

  <xsl:template match="xqx:module">
    <xsl:apply-templates select="*"/>
  </xsl:template>

</xsl:stylesheet>

C The application/xquery+xml Media Type (Non-Normative)

This Appendix specifies the media type for XQueryX Version 1.0. XQueryX is the XML syntax of a language, XQuery, for querying over data from XML data sources, as specified in [XQuery 1.0: An XML Query Language].

C.1 Introduction

This document, together with its normative references, defines the XML syntax for the XML Query language XQuery Version 1.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 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.

C.2 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 [RFC3023].

C.2.1 Encoding Considerations

The considerations as specified in RFC 3023 [XMLMIME] also hold for 'application/xquery+xml'.

C.2.2 Fragment Identifiers

For documents labeled as 'application/xquery+xml', fragment identifiers are handled as specified in RFC 3023 [XMLMIME].

C.2.3 Restrictions on usage

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

C.2.4 Security Considerations

Queries written in XQueryX may cause arbitrary URIs to be dereferenced. Therefore, the security issues of [Uniform Resource Locators (URL)] Section 6 should be considered. In addition, the contents of file: URIs can in some cases be accessed, processed and returned as results.

Furthermore, because the XQuery language (and thus the XQueryX language) permits extensions, it is possible that application/xquery+xml may describe content that has security implications beyond those described here. However, if the processor follows only the normative semantics of this specification, this content will be ignored. Only in the case where the processor recognizes and processes the additional content, or where further processing of that content is dispatched to other processors, would security issues arise.

The XML Query Working group is working on a facility to allow XQuery (and thus XQueryX) expressions to be used to create and update persistent data. Untrusted queries should not be given write access to data.

C.2.5 Interoperability Considerations

See Section 5 ConformanceXQ.

C.2.6 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 1.0 on the World Wide Web, as a first class XML application.

C.2.7 Additional Information

C.2.7.1 Recognizing 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/yyyy/mm/XQueryX" to identify the XQueryX namespace (where "yyyy" is exactly four decimal digits and "mm" is exactly two decimal digits). This sequence will normally be found in a namespace attribute of the first element in the document.

C.2.7.2 File Extensions

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

C.2.7.3 Macintosh File Type Code(s)

The appropriate Macintosh file type code is TEXT.

C.2.8 Person and Email Address to Contact For Further Information

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

C.2.9 Intended Usage

COMMON

C.2.10 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.

D XQueryX Issues (Non-Normative)

This section contains the current issues for XQueryX. The individual issues are shown in detail after an abbreviated issues list.

D.1 XQueryX Issue Summary

Issue Priority Status ID
1: Should we define a programmatic conversion from the XQuery abstract syntax to the XQueryX Schema? (xqueryx-auto) 2 open xqueryx-auto
2: How should XQueryX represent operators? (xqueryx-operator-syntax) 3 open xqueryx-operator-syntax
3: Representation of QNames in xqx: element content is suboptimal (xqueryx-qname-in-context) 3 open xqueryx-qname-in-context
4: The XQueryX schema must be kept aligned with the XQuery grammar (xqueryx-grammar-updates) 1 open xqueryx-grammar-updates
5: Should there be a "less-trivial embedding" of XQuery into XML? (xqueryx-less-trivial-embedding) 1 open xqueryx-less-trivial-embedding
6: Must an XQueryX document always start at the level of an XQuery module? (xqueryx-start-at-module) 2 open xqueryx-start-at-module
7: The XQuery process model does not incorporate XQueryX (xqueryx-process-model) 3 open xqueryx-process-model

D.2 XQueryX Issues

Issue: xqueryx-auto, priority: 2, status: open

Should we define a programmatic conversion from the XQuery abstract syntax to the XQueryX Schema?

Source: XML Query WG

If we could define a programmatic conversion from the XQuery abstract syntax to the XQueryX Schema (and the Stylesheet), we could guarantee that the current and future versions of the XQueryX Schema were complete and up-to-date. This would probably need to include annotations to the XQuery grammar. It has been estimated that this would take several times as much effort as the current manual approach.

Resolution:

None recorded.

Issue: xqueryx-operator-syntax, priority: 3, status: open

How should XQueryX represent operators?

Source: XML Query WG

There are many possible notations that XQueryX could use to represent operators. It currently uses the following syntax for operators:

                <xqx;infixOp/>
                <xqx;opType>+</xqx:opType>

and

                <xqx;infixOp/>
                <xqx;opType>and</xqx:opType>

Several other possibilities have been suggested, eg:

                <xqx:function name="PLUS">
                    <xqx:constant datatype="INTEGER">1</xqx:constant>
                    <xqx:constant datatype="INTEGER">2</xqx:constant>
                </xqx:function>

or

                <xqx:plus/>
                <xqx:and/>
                

or

                <xqx:binaryOperator name="plus"/>
                <xqx:binaryOperator name="and"/>
                

or

                <xqx:mathOperator name="+"/>
                <xqx:logicalOperator name="and"/>

Is there any compelling reason to change from the current notation to some alternative?

Resolution:

None recorded.

Issue: xqueryx-qname-in-context, priority: 3, status: open

Representation of QNames in xqx: element content is suboptimal

Source: XML Query WG

One capability enabled by the existence of XQueryX is the ability to process XQueries using ordinary XML tools, including XQuery itself, XPath, and XSLT. XQueryX schema elements sometimes represent QNames. For example: "<functionName>avg</functionName>". The representation of QNames in context like this makes it very difficult for XML-aware tools to find those QNames by using their fully-qualified form, including their namespace URIs. Are there any XQueryX changes that would make this feasible?

Resolution:

None recorded.

Issue: xqueryx-grammar-updates, priority: 1, status: open

The XQueryX schema must be kept aligned with the XQuery grammar

Source: XML Query WG

Changes are made to the XQuery grammar at an ever-decreasing frequency and the XQueryX schema must be re-aligned with the revised grammar whenever changes are made.

Resolution:

Partially resolved: The grammar changes through early February, 2005, have been applied.

Issue: xqueryx-less-trivial-embedding, priority: 1, status: open

Should there be a "less-trivial embedding" of XQuery into XML?

Source: XML Query WG

The XQueryX specification includes both a schema defining an XML representation of XQuery semantics in a syntax that roughly parallels the XQuery grammar. It also includes a "trivial embedding" of XQuery that merely wraps XQuery syntax in a containing XML element (and escapes certain important characters).

There may be an important requirement to provide a "less-trivial" embedding that uses a sort of mixed XML-and-human-readable syntax.

Resolution:

None recorded.

Issue: xqueryx-start-at-module, priority: 2, status: open

Must an XQueryX document always start at the level of an XQuery module?

Source: XML Query WG

Valid XQuery syntax ranges from the ultra-trivial (e.g., "42" is a valid XQuery expression) to the complex (e.g., fully-specified modules). Should XQueryX documents always represent fully-specified modules, or should it be permissible to represent ultra-trivial expressions?

This issue could be resolved by adding the following statement to Section 2, Mapping the XQuery Syntax: "XQueryX documents must begin with either a module or expr element."

Resolution:

None recorded.

Issue: xqueryx-process-model, priority: 3, status: open

The XQuery process model does not incorporate XQueryX

Source: XML Query WG

The XQuery process model does not currently incorporate the use of XQueryX. That process model must be updated to account for XQueryX.

Resolution:

None recorded.

Issue: xqueryx-xsl-normative, priority: 3, status: closed

Should the stylesheet be normative ?

Source: XML Query WG

The XQueryX Schema defines the syntax of XQueryX. But we also need to define the semantics. If we had some programmatic way to convert from XQuery syntax to XQueryX syntax, then this process would define the semantics of XQueryX. As it is, we can only go in the other direction : from XQueryX to XQuery via a stylesheet. So, should the stylesheet be the normative definition of the semantics of XQueryX ?

Resolution:

RESOLVED: The Query WG has determined that the stylesheet must be normative in order to define the semantics of XQueryX.

Issue: xqueryx-tidy, priority: 2, status: closed

Some tidy-up of terms is needed.

Source: XML Query WG

Need to tidy up some of the terminology in the Schema : e.g. the use of flwr vs the newer flwor.

Resolution:

RESOLVED: The tidying has been done, particularly the cited example.

Issue: xqueryx-xslt, priority: 5, status: closed

XQueryX and XSLT

Source: XML Query WG

Should there be some clear relationship between XQueryX and XSLT?

Resolution:

RESOLVED: No, this is not a goal.

Issue: xqueryx-expand-paths, priority: 3, status: closed

Should path expressions be expanded?

Source: ML Query WG

The current representation requires path expressions to be expanded. Should this be optional?

Resolution:

RESOLVED: XPath expressions should be expanded, and it should not be optional.

Issue: xqueryx-human-readable, priority: 4, status: closed

Human readable XQueryX?

Source: XML Query WG

Should making XQueryX queries easier for humans to read and write be a goal?

Resolution:

RESOLVED: No, this is not a goal. It was decided that the priority is to have an XML syntax. The human-readable characteristic is somewhat subjective, so the decision is to go for a solution that allows a very granular access to the language.

Issue: xqueryx-semantics, priority: 3, status: closed

Should XQueryX mirror the Formal Semantics?

Source: XML Query WG

Should XQueryX mirror the Formal Semantics rather than the abstract syntax of XQuery?

Resolution:

RESOLVED: No, this is not a goal.

Issue: xqueryx-define-transformation, priority: 2, status: closed

Define Transformations from XQuery Grammar

This issue was a duplicate of [Issue 1: Should we define a programmatic conversion from the XQuery abstract syntax to the XQueryX Schema?].

Resolution:

RESOLVED, but see [Issue 1: Should we define a programmatic conversion from the XQuery abstract syntax to the XQueryX Schema?]

Issue: xqueryx-path-expressions, priority: 3, status: closed

Representing Path Expressions

Source: XML Query WG

Should path expressions be represented in a linear fashion, with the individual steps represented as a sequence? One Working Group member has suggested that the path "doc("a")/b/c" should be represented as follows:

                <path>
                    <function name="doc">
                        <constant>a</constant>
                    </function>
                    <step axis="descendant">
                        <identifier>b</identifier>
                    </step>
                    <step axis="descendant">
                        <identifier>c</identifier>
                    </step>
                </path>
                

Resolution:

RESOLVED: the schema has this sort of structure, only without the use of attributes.

Issue: xqueryx-slash-slash, priority: 3, status: closed

Representing //

Source: XML Query WG

In this document we use the constant SLASHSLASH as a fictive axis that corresponds to the meaning of the "//" operator. In fact, this operator does not correspond directly to an axis, but to descendant-or-self::node()/. For example, //para is short for /descendant-or-self::node()/child::para. Since XQueryX must be able to translate back to the original XQuery syntax, we currently use SLASHSLASH to preserve the original operator.

Is this the best way to represent the // operator in XQueryX?

Resolution:

RESOLVED: Overtaken by events; the schema uses the full (expanded) path notation instead of abbreviations.

Issue: xqueryx-operators-symbolspace, priority: 3, status: closed

Symbol space for operators

Source: XML Query WG

The current syntax does not distinguish functions from operators. Since a function may have the same name as an operator, some mechanism must be chosen to disambiguate their names. For instance, since a user can write a function named plus, perhaps the operator plus should be represented as:

                <operator name="plus"/>
                

rather than

                <function name="plus"/>
                

Resolution:

RESOLVED: Overtaken by events in both XQuery and in XQueryX; the schema now clearly distinguishes operators and functions.

Issue: xqueryx-star-identifier, priority: 3, status: closed

Wildcard

Originator: XML Query WG
Locus: xqueryx

Should * be used as an identifier? It should probably be a wildcard.

Resolution:

RESOLVED: * is represented as a wildcard element.

Issue: xqueryx-cast-treat-typeswitch, priority: 3, status: closed

Type Expressions

Source: XML Query WG

CAST, TREAT, and TYPESWITCH have no representation in this Working Draft. This must be added soon.

Resolution:

RESOLVED: This specification now covers those expressions.

Issue: xqueryx-schema-declarations, priority: 3, status: closed

SCHEMA declaration

Source: XML Query WG

There is currently no representation for schema declarations in XQueryX. This must be added.

Resolution:

RESOLVED: This issue is moot.

Issue: xqueryx-case-of-constants, priority: 3, status: closed

Case of Constants

Source: XML Query WG

Should XQueryX constants use upper or lower case?

Resolution:

RESOLVED: There is no compelling reason to adopt either convention; the schema uses lowercase generally when the notion being represented corresponds to an XQuery keyword (e.g., "eq") and camelcase generally when representing notions that do not correspond to a keyword (e.g., unaryPlus).

Issue: xqueryx-var-rep, priority: 3, status: closed

Should XQueryX variables be in uppercase?

Source: Jonathan Robie

The way the variable class is defined in the alternate schema is not consistent with the way other types/elements are treated

Resolution:

RESOLVED: This issue is moot, as the alternate schema no longer exists.

Issue: xqueryx-support-pragmas-etc, priority: 3, status: closed

Shoud XQueryX support pragmas, MUEs, and comments?

Source: Editors

It seems reasonable to support the first two, but not the third (comments).

If the answer is yes, then how rigorously should XQueryX preserve fidelity with respect to the position of these constructs in the base documents? (For example, can XQueryX restrict its support for pragmas and MUEs to only the prolog section?)

If the answer is yes, then the schema for XQueryX needs to reflect this -- and that would mean that every single type/element definition would have to accomodate such a construct. This is not just painful -- it's pretty ridiculous. We must bear in mind that, even with this enormous pain, we still would not have complete fidelity. For example, the XQuery construct "declare function foo" has multiple whitespace locations, while the equivalent in XQueryX has fewer — because XQueryX does not recognize the syntactic pieces of this construct.

If the answer is yes, then some clarifications are in order. What are the expected semantics of a pragma/MUE at some arbitrary location in the XQuery? Do they apply to the entire query? Some subset of the query? Forward-looking subset of the query? The immediately containing block?

Resolution:

RESOLVED: The schema now supports pragmas (made possible by the recent changes made to pragma syntax in XQuery). MUEs (must-understand extensions) no longer exist. At a Query WG meeting in 2004, the WG decided that comments in XQuery have no meaningful correlation in XQueryX (because the goal of XQueryX is to provide an XML syntax to represent XML queries, not to provide a fully reversible transformation of XQuery human-readable syntax to XQueryX and back).

Issue: xqueryx-normative-semantics, priority: 1, status: closed

How should the semantics of XQueryX be specified normatively?

Source: XML Query WG

The semantics of XQueryX must be stated normatively. One possible way is to show the correspondence between the XQueryX and XQuery syntaxes; if this solution is chosen, then how do we demonstrate that the XQueryX syntax is equivalent to the XQuery syntax?.

Resolution:

RESOLVED: The XQueryX document states that the semantics depend on the newly-normative stylesheet that transforms XQueryX documents into XQuery human-readable syntax.

Issue: xqueryx-wrappers-necessary, priority: 3, status: closed

Are "wrapper" elements necessary or desirable?

Source: XML Query WG

The XQueryX schema currently includes the use of "wrapper" elements (<exprWrapper> and <exprList>). These elements might have uses in future enhancements of XQueryX, but arguably do not have any utility in this version.

Should these elements be retained, or should they be removed from the schema design?

Resolution:

RESOLVED: The exprWrapper and exprList elements have been removed from the Schema. There remain two types with those names, but they do not appear in any instance XQueryX document.

Issue: xqueryx-param-vs-arg, priority: 5, status: closed

"<xqx:parameters>" should be "<xqx:arguments>"

Source: XML Query WG

The element "<xqx:parameters>" is misnamed, since it actually represents the arguments to a function invocation and not the parameters of a function definition. It should probably be changed to "<xqx:arguments>"

Resolution:

RESOLVED: All instances of "parameters" in the Schema have been changed to "arguments".

Issue: xqueryx-encode-everything, priority: 4, status: closed

Should XQueryX represent everything that can be expressed in XQuery syntax?

Source: XML Query WG

XQueryX is intended to be a language, or syntax, for representing XQuery semantics in an XML form. There is no requirement or intent to presume "compilation" of XQuery expressions from the human-readable syntax into XQueryX. Consequently, the decision has already been made that XQuery comments are not represented in XQueryX (of course, XQueryX is XML and thus can contain XML comments).

But there is at least one additional case to be considered: the XQuery prolog allows an encoding specification (e.g., UTF-8). XQueryX currently allows that encoding specification (corresponding only to the XQuery encoding parameter) to be included in an XQueryX document. This does not affect the encoding of the XQueryX document itself in any way. Should that capability be retained or removed as meaningless? If it is retained, should the stylesheet generate the corresponding XQuery prolog encoding parameter?

Resolution:

RESOLVED: Representation of the XQuery encoding parameter is no longer possible in an XQueryX instance document.

Issue: xqueryx-trivial-schema-namespace, priority: 3, status: closed

Trivial embedding should have a schema and namespace

Source: XML Query WG

The trivial embedding described in this document makes use of an element called "<XQuery>". That element should be in a specified namespace. That namespace could be the same one used by the remainder of XQueryX (represented by the prefix "xqx", or it could be a new namespace ("xqxt"). In either case, there must be a definition of the element in an XML schema.

Resolution:

RESOLVED: A new element definition, <xqx:xquery>, has been added to the XQueryX schema and namespace.