Copyright © 2003 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark, document use and software licensing rules apply.
This document presents an XML Syntax for [XQuery 1.0: An XML Query Language].
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, published on 19 December 2003, of this document 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 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 is proposing that XQueryX will be an optional conformance level for XQuery 1.0. The WG invites feedback on the approaches for representing XQuery 1.0 in XML in this Working Draft.
This document has been produced following the procedures set out for the W3C Process. This document was produced through the efforts 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]. Note these are not the latest versions: we expect that XQueryX documents will always lag the language document.
Public comments on this document and its open issues are invited. Comments should be sent to the W3C XPath/XQuery mailing list, public-qt-comments@w3.org (archived at http://lists.w3.org/Archives/Public/public-qt-comments/). Commenters are requested to put the string "[XQueryX]" at the beginning of the subject line of email messages involving such comments.
Patent disclosures relevant to this specification may be found on the XML Query Working Group's patent disclosure page and the XSL Working Group's patent disclosure page.
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.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
6 MIME Type
A References
B Transforming XQueryX to XQuery
C XQueryX Issues (Non-Normative)
C.1 Issue List
C.2 XQueryX Issues
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 abstract syntax directly 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:
Parser Reuse. In heterogeneous data environments, a variety of systems may be used to execute a query. One parser can generate XQueryX for all of these systems.
Queries on Queries. Because XQueryX is represented in XML, queries can be queried and can be transformed into new queries. For instance, a query can be performed against a set of XQueryX queries to determine which queries use FLWOR expressions to range over a set of invoices.
Generating Queries. In some XML-oriented programming environments, it may be more convenient to build a query in its XQueryX representation than in the corresponding XQuery representation, since XML tools can be used to do so.
Embedding Queries in XML. XQueryX can be embedded directly in an XML document.
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" Expr
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:element name="exprWrapper" type="exprWrapper"/> <xsd:complexType name="flwrExpr"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element ref="forClause" minOccurs="0" maxOccurs="unbounded"/> <xsd:element ref="letClause" minOccurs="0" maxOccurs="unbounded"/> <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="forClause"> <xsd:complexType> <xsd:sequence> <xsd:element name="typedVariable" type="typedVariable"/> <xsd:element name="positionalVar" type="exprWrapper" minOccurs="0"/> <xsd:element name="forExpr" type="exprWrapper"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="letClause"> <xsd:complexType> <xsd:sequence> <xsd:element name="typedVariable" type="typedVariable"/> <xsd:element name="letExpr" type="exprWrapper"/> </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.
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. We are not proposing XQueryX as a convenient syntax for humans to read and write, so we slant our representation toward the programmer.
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."
<bib> { for $b in doc("http://www.bn.com/bib.xml")/bib/book where $b/publisher = "Addison-Wesley" and $b/@year > 1991 return <book year="{ $b/@year }"> { $b/title } </book> } </bib>
<?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/2003/12/XQueryX" xsi:schemaLocation="http://www.w3.org/2003/12/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:flwrExpr"> <xqx:forClause> <xqx:forClauseItem> <xqx:typedVariableBinding> <xqx:varName>b</xqx:varName> </xqx:typedVariableBinding> <xqx:forExpr> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:functionCallExpr"> <xqx:functionName>document</xqx:functionName> <xqx:parameters> <xqx:expr xsi:type="xqx:stringConstantExpr"> <xqx:value>bib.xml</xqx:value> </xqx:expr> </xqx:parameters> </xqx:expr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>bib</xqx:QName> </xqx:nodeName> </xqx:elementTest> </xqx:stepExpr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>book</xqx:QName> </xqx:nodeName> </xqx:elementTest> </xqx:stepExpr> </xqx:expr> </xqx:forExpr> </xqx:forClauseItem> </xqx:forClause> <xqx:whereClause> <xqx:expr xsi:type="xqx:operatorExpr" xqx:infix="true"> <xqx:opType>AND</xqx:opType> <xqx:parameters> <xqx:expr xsi:type="xqx:operatorExpr" xqx:infix="true"> <xqx:opType>=</xqx:opType> <xqx:parameters> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:variable"> <xqx:name>b</xqx:name> </xqx:expr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>publisher</xqx:QName> </xqx:nodeName> </xqx:elementTest> </xqx:stepExpr> </xqx:expr> <xqx:expr xsi:type="xqx:stringConstantExpr"> <xqx:value>Addison-Wesley</xqx:value> </xqx:expr> </xqx:parameters> </xqx:expr> <xqx:expr xsi:type="xqx:operatorExpr" xqx:infix="true"> <xqx:opType>></xqx:opType> <xqx:parameters> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:variable"> <xqx:name>b</xqx:name> </xqx:expr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:attributeTest> <xqx:nodeName> <xqx:QName>year</xqx:QName> </xqx:nodeName> </xqx:attributeTest> </xqx:stepExpr> </xqx:expr> <xqx:expr xsi:type="xqx:integerConstantExpr"> <xqx:value>1991</xqx:value> </xqx:expr> </xqx:parameters> </xqx:expr> </xqx:parameters> </xqx:expr> </xqx:whereClause> <xqx:returnClause> <xqx:expr xsi:type="xqx:elementConstructor"> <xqx:tagName>book</xqx:tagName> <xqx:attributeList> <xqx:expr xsi:type="xqx:attributeConstructor"> <xqx:attributeName>year</xqx:attributeName> <xqx:attributeValue> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:variable"> <xqx:name>b</xqx:name> </xqx:expr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:attributeTest> <xqx:nodeName> <xqx:QName>year</xqx:QName> </xqx:nodeName> </xqx:attributeTest> </xqx:stepExpr> </xqx:expr> </xqx:attributeValue> </xqx:expr> </xqx:attributeList> <xqx:elementContent> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:variable"> <xqx:name>b</xqx:name> </xqx:expr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>title</xqx:QName> </xqx:nodeName> </xqx:elementTest> </xqx:stepExpr> </xqx:expr> </xqx:expr> </xqx:elementContent> </xqx:expr> </xqx:returnClause> </xqx:expr> </xqx:elementContent> </xqx:expr> </xqx:queryBody> </xqx:mainModule> </xqx:module>
Applying the stylesheet in B Transforming XQueryX to XQuery to the XQueryX solution, we get:
<bib>{ for $b in document("bib.xml")/child::element(bib)/child::element(book) where (($b/child::element(publisher) = "Addison-Wesley") AND ($b/child::attribute(@year) > 1991)) return <book year="{$b/child::attribute(@year)}">{$b/child::element(title)}</book> }</bib>
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."
<bib> { for $b in doc("http://www.bn.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>
<?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/2003/12/XQueryX" xsi:schemaLocation="http://www.w3.org/2003/12/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:flwrExpr"> <xqx:forClause> <xqx:forClauseItem> <xqx:typedVariableBinding> <xqx:varName>b</xqx:varName> </xqx:typedVariableBinding> <xqx:forExpr> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:functionCallExpr"> <xqx:functionName>document</xqx:functionName> <xqx:parameters> <xqx:expr xsi:type="xqx:stringConstantExpr"> <xqx:value>bib.xml</xqx:value> </xqx:expr> </xqx:parameters> </xqx:expr> <xqx:stepExpr> <xqx:xpathAxis>descendant-or-self</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>book</xqx:QName> </xqx:nodeName> </xqx:elementTest> <xqx:predicates> <xqx:expr xsi:type="xqx:operatorExpr" xqx:infix="true"> <xqx:opType>AND</xqx:opType> <xqx:parameters> <xqx:expr xsi:type="xqx:operatorExpr" xqx:infix="true"> <xqx:opType>=</xqx:opType> <xqx:parameters> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:currentNode"/> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>publisher</xqx:QName> </xqx:nodeName> </xqx:elementTest> </xqx:stepExpr> </xqx:expr> <xqx:expr xsi:type="xqx:stringConstantExpr"> <xqx:value>Addison-Wesley</xqx:value> </xqx:expr> </xqx:parameters> </xqx:expr> <xqx:expr xsi:type="xqx:operatorExpr" xqx:infix="true"> <xqx:opType>=</xqx:opType> <xqx:parameters> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:currentNode"/> <xqx:stepExpr> <xqx:xpathAxis>self</xqx:xpathAxis> <xqx:attributeTest> <xqx:nodeName> <xqx:QName>year</xqx:QName> </xqx:nodeName> </xqx:attributeTest> </xqx:stepExpr> </xqx:expr> <xqx:expr xsi:type="xqx:stringConstantExpr"> <xqx:value>1991</xqx:value> </xqx:expr> </xqx:parameters> </xqx:expr> </xqx:parameters> </xqx:expr> </xqx:predicates> </xqx:stepExpr> </xqx:expr> </xqx:forExpr> </xqx:forClauseItem> </xqx:forClause> <xqx:orderByClause> <xqx:orderBySpec> <xqx:orderByExpr> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:variable"> <xqx:name>b</xqx:name> </xqx:expr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>title</xqx:QName> </xqx:nodeName> </xqx:elementTest> </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:expr xsi:type="xqx:variable"> <xqx:name>b</xqx:name> </xqx:expr> <xqx:stepExpr> <xqx:xpathAxis>self</xqx:xpathAxis> <xqx:attributeTest> <xqx:nodeName> <xqx:QName>year</xqx:QName> </xqx:nodeName> </xqx:attributeTest> </xqx:stepExpr> </xqx:expr> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:variable"> <xqx:name>b</xqx:name> </xqx:expr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>title</xqx:QName> </xqx:nodeName> </xqx:elementTest> </xqx:stepExpr> </xqx:expr> </xqx:elementContent> </xqx:expr> </xqx:returnClause> </xqx:expr> </xqx:elementContent> </xqx:expr> </xqx:queryBody> </xqx:mainModule> </xqx:module>
Applying the stylesheet in B Transforming XQueryX to XQuery to the XQueryX solution, we get:
<bib>{ for $b in document("bib.xml")/descendant-or-self::element(book) [((./child::element(publisher) = "Addison-Wesley") AND (./self::attribute(@year) = "1991"))] order by $b/child::element(title) return <book>{$b/self::attribute(@year) $b/child::element(title)}</book> }</bib>
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."
<results> FOR $a IN distinct(document("http://www.bn.com")//author) RETURN <result> $a, FOR $b IN document("http://www.bn.com")/bib/book[author = $a] RETURN $b/title </result> </results>
<?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/2003/12/XQueryX" xsi:schemaLocation="http://www.w3.org/2003/12/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:flwrExpr"> <xqx:forClause> <xqx:forClauseItem> <xqx:typedVariableBinding> <xqx:varName>a</xqx:varName> </xqx:typedVariableBinding> <xqx:forExpr> <xqx:expr xsi:type="xqx:functionCallExpr"> <xqx:functionName>distinct</xqx:functionName> <xqx:parameters> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:functionCallExpr"> <xqx:functionName>document</xqx:functionName> <xqx:parameters> <xqx:expr xsi:type="xqx:stringConstantExpr"> <xqx:value>http://www.bn.com</xqx:value> </xqx:expr> </xqx:parameters> </xqx:expr> <xqx:stepExpr> <xqx:xpathAxis>descendant-or-self</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>author</xqx:QName> </xqx:nodeName> </xqx:elementTest> </xqx:stepExpr> </xqx:expr> </xqx:parameters> </xqx:expr> </xqx:forExpr> </xqx:forClauseItem> </xqx:forClause> <xqx:returnClause> <xqx:expr xsi:type="xqx:elementConstructor"> <xqx:tagName>result</xqx:tagName> <xqx:elementContent> <xqx:expr xsi:type="xqx:sequenceExpr"> <xqx:expr xsi:type="xqx:variable"> <xqx:name>a</xqx:name> </xqx:expr> <xqx:expr xsi:type="xqx:flwrExpr"> <xqx:forClause> <xqx:forClauseItem> <xqx:typedVariableBinding> <xqx:varName>b</xqx:varName> </xqx:typedVariableBinding> <xqx:forExpr> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:functionCallExpr"> <xqx:functionName>document</xqx:functionName> <xqx:parameters> <xqx:expr xsi:type="xqx:stringConstantExpr"> <xqx:value>http://www.bn.com</xqx:value> </xqx:expr> </xqx:parameters> </xqx:expr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>bib</xqx:QName> </xqx:nodeName> </xqx:elementTest> </xqx:stepExpr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>book</xqx:QName> </xqx:nodeName> </xqx:elementTest> <xqx:predicates> <xqx:expr xsi:type="xqx:operatorExpr" xqx:infix="true"> <xqx:opType>=</xqx:opType> <xqx:parameters> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:currentNode"/> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>author</xqx:QName> </xqx:nodeName> </xqx:elementTest> </xqx:stepExpr> </xqx:expr> <xqx:expr xsi:type="xqx:variable"> <xqx:name>a</xqx:name> </xqx:expr> </xqx:parameters> </xqx:expr> </xqx:predicates> </xqx:stepExpr> </xqx:expr> </xqx:forExpr> </xqx:forClauseItem> </xqx:forClause> <xqx:returnClause> <xqx:expr xsi:type="xqx:pathExpr"> <xqx:expr xsi:type="xqx:variable"> <xqx:name>b</xqx:name> </xqx:expr> <xqx:stepExpr> <xqx:xpathAxis>child</xqx:xpathAxis> <xqx:elementTest> <xqx:nodeName> <xqx:QName>title</xqx:QName> </xqx:nodeName> </xqx:elementTest> </xqx:stepExpr> </xqx:expr> </xqx:returnClause> </xqx:expr> </xqx:expr> </xqx:elementContent> </xqx:expr> </xqx:returnClause> </xqx:expr> </xqx:elementContent> </xqx:expr> </xqx:queryBody> </xqx:mainModule> </xqx:module>
Applying the stylesheet in B Transforming XQueryX to XQuery to the XQueryX solution, we get:
<results>{ for $a in distinct(document("http://www.bn.com")/descendant-or-self::element(author)) return <result>{($a, for $b in document("http://www.bn.com")/child::element(bib)/child::element(book)[(./child::element(author) = $a)] return $b/child::element(title) )}</result> }</results>
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" encoding="UTF-8"?> <xsd:schema targetNamespace="http://www.w3.org/2003/12/XQueryX" xmlns="http://www.w3.org/2003/12/XQueryX" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified"> <!-- Version 1.1 of the XQueryX schema. Authors: Jim Melton, S. Muralidhar (Oracle Corp.) The main data structure in this schema is the set of types that describe expressions. I've chosen to model expressions as an inheritance hierarchy, with an "expr" abstract base class. 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. I'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. I'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. I'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> <xsd:element name="exprList" type="exprList"/> <!-- Simple wrapper class --> <xsd:complexType name="exprWrapper"> <xsd:sequence> <xsd:element ref="expr"/> </xsd:sequence> </xsd:complexType> <xsd:element name="exprWrapper" type="exprWrapper"/> <!-- Kludge for anySimpleType --> <xsd:simpleType name="constantValueType"> <xsd:union memberTypes="xsd:integer xsd:decimal xsd:string xsd:double"/> </xsd:simpleType> <!-- 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="constantValueType"/> </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="variable"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element name="name" type="xsd:QName"/> </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="parameters" type="exprList" minOccurs="0"/> </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 ref="expr" minOccurs="2" maxOccurs="2"/> </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="unbounded"/> <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="<"/> <xsd:enumeration value="<="/> <xsd:enumeration value=">="/> <xsd:enumeration value=">="/> </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="<<"/> <xsd:enumeration value=">>"/> </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="parameters" 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="occurenceIndicator"> <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="emptySequenceType" type="emptyContent"/> <xsd:sequence> <xsd:group ref="itemType"/> <xsd:element name="occurenceIndicator" type="occurenceIndicator" 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 name="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:element name="orderModifier"> <xsd:complexType> <xsd:sequence> <xsd:choice minOccurs="0"> <xsd:element name="ascending" type="emptyContent"/> <xsd:element name="descending" type="emptyContent"/> </xsd:choice> <xsd:choice minOccurs="0"> <xsd:element name="emptyGreatest" type="emptyContent"/> <xsd:element name="emptyLeast" type="emptyContent"/> </xsd:choice> <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 name="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 name="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 name="whereClause" minOccurs="0"/> <xsd:element name="orderByClause" minOccurs="0"/> <xsd:element name="returnClause"/> </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="qExpr" type="exprWrapper"/> <xsd:element name="quantifiedExprInClause"> <xsd:complexType> <xsd:sequence> <xsd:element ref="typedVariableBinding"/> <xsd:element ref="qExpr" /> </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 name="quantifiedExprInClause" maxOccurs="unbounded"/> <xsd:element name="satisfiesExpr" 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="returnExpr" 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="returnExpr" 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="treatExpr" type="exprWrapper"/> <xsd:element name="typeswitchExprCaseClause" maxOccurs="unbounded"/> <xsd:element name="typeswitchExprDefaultClause" /> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <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> <!-- handle the INSTANCE OF construct --> <xsd:complexType name="instanceOfExpr"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element name="treatExpr" type="exprWrapper"/> <xsd:element ref="sequenceType"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="treatExpr"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element ref="expr"/> <xsd:element ref="sequenceType"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="castableExpr"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element ref="expr"/> <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 ref="expr"/> <xsd:element ref="singleType"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <!-- Used for the VALIDATE construct --> <xsd:simpleType name="validationMode"> <xsd:restriction base="xsd:NMTOKEN"> <xsd:enumeration value="lax"/> <xsd:enumeration value="strict"/> <xsd:enumeration value="skip"/> </xsd:restriction> </xsd:simpleType> <xsd:element name="schemaContextLocation"> <xsd:complexType> <xsd:sequence> <xsd:element name="type" type="emptyContent" minOccurs="0"/> <xsd:element ref="QName" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="validationContext"> <xsd:complexType> <xsd:sequence> <xsd:element name="validationMode" type="validationMode" minOccurs="0"/> <xsd:choice> <xsd:element name="globalValidationContext" type="emptyContent"/> <xsd:element ref="schemaContextLocation"/> </xsd:choice> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:complexType name="validateExpr"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element ref="validationContext" minOccurs="0"/> <xsd:element ref="exprWrapper"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <!-- attributeConstructor is no longer a subclass of expr --> <xsd:complexType name="attributeConstructor"> <xsd:sequence> <xsd:element name="attributeName" type="xsd:QName"/> <xsd:element name="attributeValue" type="exprWrapper"/> </xsd:sequence> </xsd:complexType> <xsd:element name="elementContent"> <xsd:complexType> <xsd:choice maxOccurs="unbounded"> <xsd:element ref="expr"/> </xsd:choice> </xsd:complexType> </xsd:element> <xsd:element name="attributeList"> <xsd:complexType> <xsd:sequence> <xsd:element name="attributeConstructor" type="attributeConstructor" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> <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> <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 ref="expr"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="computedTextConstructor"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element ref="expr" minOccurs="0"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="computedCommentConstructor"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element ref="expr"/> </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> <xsd:complexType name="computedNamespaceConstructor"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element name="prefix" type="xsd:NCName"/> <xsd:element name="uri" type="exprWrapper"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="commentConstructor"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element name="comment" type="xsd:string"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="cdataConstructor"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element name="cdataValue" type="xsd:string"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="piConstructor"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element name="piTarget" type="xsd:NCName"/> <xsd:element name="piValue" type="xsd:string"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="unorderedExpr"> <xsd:complexContent> <xsd:extension base="expr"> <xsd:sequence> <xsd:element ref="expr"/> </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="nameTest"> <xsd:complexType> <xsd:choice> <xsd:element ref="QName"/> <xsd:element ref="Wildcard"/> </xsd:choice> </xsd:complexType> </xsd:element> <xsd:element name="attributeTest"> <xsd:complexType> <xsd:choice minOccurs="0"> <xsd:sequence> <xsd:element ref="schemaContextLocation"/> <xsd:element ref="QName"/> </xsd:sequence> <xsd:sequence> <xsd:element name="nodeName" type="simpleWildcard"/> <xsd:element name="typeName" type="simpleWildcard" minOccurs="0"/> </xsd:sequence> </xsd:choice> </xsd:complexType> </xsd:element> <xsd:element name="elementTest"> <xsd:complexType> <xsd:choice minOccurs="0"> <xsd:sequence> <xsd:element ref="schemaContextLocation"/> <xsd:element ref="QName"/> </xsd:sequence> <xsd:sequence> <xsd:element name="nodeName" type="simpleWildcard"/> <xsd:sequence minOccurs="0"> <xsd:element name="typeName" type="simpleWildcard"/> <xsd:element name="nillable" type="emptyContent" minOccurs="0"/> </xsd:sequence> </xsd:sequence> </xsd:choice> </xsd:complexType> </xsd:element> <xsd:element name="documentTest"> <xsd:complexType> <xsd:sequence> <xsd:element ref="elementTest" minOccurs="0"/> </xsd:sequence> </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:group name="kindTest"> <xsd:choice> <xsd:element ref="elementTest"/> <xsd:element ref="attributeTest"/> <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="descendant-or-self"/> <xsd:enumeration value="parent"/> </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="QName"/> <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 ref="expr"/> <xsd:element name="predicates" type="exprList" minOccurs="0"/> <xsd:element ref="stepExpr" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <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> <!-- The following constructs deal with the query prolog --> <xsd:element name="module"> <xsd:complexType> <xsd:sequence> <xsd:element name="version" 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="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="version" type="xsd:string"/> <xsd:element name="mustUnderstandExtension"> <xsd:complexType> <xsd:sequence> <xsd:element ref="QName"/> <xsd:element name="contents" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="pragma"> <xsd:complexType> <xsd:sequence> <xsd:element ref="QName"/> <xsd:element name="contents" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="xqueryComment" type="xsd:string"/> <xsd:element name="prolog"> <xsd:complexType> <xsd:sequence> <xsd:choice minOccurs="0" maxOccurs="unbounded"> <xsd:element ref="namespaceDecl"/> <xsd:element ref="xmlspaceDecl"/> <xsd:element ref="defaultNamespaceDecl"/> <xsd:element ref="defaultCollationDecl"/> <xsd:element ref="baseUriDecl"/> <xsd:element ref="schemaImport"/> <xsd:element ref="moduleImport"/> <xsd:element ref="varDecl"/> <xsd:element ref="validationDecl"/> <xsd:element ref="functionDecl"/> <!-- These two (pragmas and MUEs) have been added here temporarily --> <xsd:element ref="pragma"/> <xsd:element ref="mustUnderstandExtension"/> </xsd:choice> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="xmlspaceDecl"> <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="namespaceDecl" type="namespaceDeclType"/> <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="uri" type="xsd:string"/> <xsd:element name="defaultNamespaceCategory" type="defaultNamespaceCategory"/> </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="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="validationDecl" type="validationMode"/> <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"/> </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"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
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 the XML Syntax for XQuery that has been chosen by the W3C. However, other XML syntaxes for XQuery could be designed for specific purposes.
When the only requirement is for an XML "wrapper" so that the text of an XQuery can be exchanged in an XML form, a so-called "trivial embedding" may be appropriate. Such an XML syntax looks like this:
<XQuery>for $i... let $j...where $x = $y...return...</XQuery>
If the XQuery contains characters that are prohibited in XML text (such as < and &), the entire XQuery could be enclosed in a CDATA section:
<XQuery><![CDATA[for $i... let $j...where $x < $y...return...]]></XQuery>
However, in some cases, an XQuery might already contain a CDATA section, which cannot be nested within another CDATA section. Such a trivially-embedded XQuery should put the CDATA section only around the characters that are not otherwise permitted to apper in XML text:
<XQuery>for $i... let $j...where $x <![CDATA[<]]> $y...return...</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/2003/12/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><</xsl:text></xsl:variable> <xsl:variable name="GREATERTHAN"><xsl:text>></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: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: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:variable']"> <xsl:value-of select="$DOLLAR"/> <xsl:value-of select="xqx:name/text()"/> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:functionCallExpr']"> <xsl:value-of select="xqx:functionName/text()"/> <xsl:for-each select="xqx:parameters"> <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 match="xqx:expr[@xsi:type='xqx:operatorExpr']"> <xsl:variable name="operator"> <xsl:text> </xsl:text> <xsl:apply-templates select="xqx:opType"/> <xsl:text> </xsl:text> </xsl:variable> <xsl:choose> <xsl:when test="xqx:infixOp"> <xsl:for-each select="xqx:parameters"> <xsl:call-template name="paranthesizedList"> <xsl:with-param name="delimiter" select="$operator"/> </xsl:call-template> </xsl:for-each> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="xqx:opType"/> <xsl:for-each select="xqx:parameters"> <xsl:call-template name="paranthesizedList"/> </xsl:for-each> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:sequenceExpr']"> <xsl:call-template name="paranthesizedList"> <xsl:with-param name="delimiter" select="$COMMA_NEWLINE"/> </xsl:call-template> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:rangeSequenceExpr']"> <xsl:value-of select="$LPAREN"/> <xsl:apply-templates select="./*[1]"/> <xsl:value-of select="$TO"/> <xsl:apply-templates select="./*[2]"/> <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:text> for </xsl:text> <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:text> let </xsl:text> <xsl:apply-templates select="xqx:typedVariableBinding"/> <xsl:text> := </xsl:text> <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="text()"/> </xsl:template> <xsl:template match="xqx:orderModifier"> <xsl:for-each select="*"> <xsl:choose> <xsl:when test="name()='ascending'"> <xsl:text> ascending </xsl:text> </xsl:when> <xsl:when test="name()='descending'"> <xsl:text> descending </xsl:text> </xsl:when> <xsl:when test="name()='emptyGreatest'"> <xsl:text> empty greatest </xsl:text> </xsl:when> <xsl:when test="name()='emptyLeast'"> <xsl:text> empty least </xsl:text> </xsl:when> <xsl:when test="name()='collation'"> <xsl:text> collation </xsl:text> <xsl:value-of select="."/> </xsl:when> </xsl:choose> </xsl:for-each> </xsl:template> <xsl:template match="xqx:orderBySpec"> <xsl:apply-templates select="xqx:orderByExpr/xqx:expr"/> <xsl:value-of select="$SPACE"/> <xsl:apply-templates select="xqx:orderModifier"/> </xsl:template> <xsl:template match="xqx:orderByClause"> <xsl:choose> <xsl:when test="xqx:stable"> <xsl:text> stable </xsl:text> </xsl:when> </xsl:choose> <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="xqx:forClause"/> <xsl:apply-templates select="xqx:letClause"/> <xsl:apply-templates select="xqx:whereClause"/> <xsl:apply-templates select="xqx:orderByClause"/> <xsl:apply-templates select="xqx:returnClause"/> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:ifThenElseExpr']"> <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:template> <xsl:template match="xqx:positionalVariableBinding"> <xsl:text> at </xsl:text> <xsl:value-of select="$DOLLAR"/> <xsl:value-of select="./text()"/> </xsl:template> <xsl:template name="variableBinding"> <xsl:value-of select="$DOLLAR"/> <xsl:value-of select="./text()"/> </xsl:template> <xsl:template name="typedVariableBinding"> <xsl:value-of select="$DOLLAR"/> <xsl:value-of select="./text()"/> <xsl:if test="xqx:typeDeclaration"> <xsl:text> as </xsl:text> <xsl:apply-templates select="xqx:typeDeclaration"/> </xsl:if> </xsl:template> <xsl:template match="xqx:quantifiedExprInClause"> <xsl:apply-templates select="typedVariableBinding"/> <xsl:text> in </xsl:text> <xsl:apply-templates select="xqx:qExpr/*"/> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:quantifiedExpr']"> <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:satisfiesExpr/*"/> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:instanceOfExpr']"> <xsl:value-of select="$LPAREN"/> <xsl:apply-templates select="xqx:treatExpr/*"/> <xsl:text> instance of </xsl:text> <xsl:apply-templates select="xqx:sequenceType"/> <xsl:value-of select="$RPAREN"/> </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:expr[@xsi:type='xqx:castExpr']"> <xsl:value-of select="$LPAREN"/> <xsl:apply-templates select="xqx:expr"/> <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:expr"/> <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:expr"/> <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:returnExpr/*"/> </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:returnExpr/*"/> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:typeswitchExpr']"> <xsl:value-of select="$LPAREN"/> <xsl:text>(typeswitch(</xsl:text> <xsl:apply-templates select="xqx:treatExpr/*"/> <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:QName"> <xsl:value-of select="."/> </xsl:template> <xsl:template match="xqx:NCName"> <xsl:value-of select="."/> </xsl:template> <xsl:template name="QName_Path"> <xsl:call-template name="delimitedList"> <xsl:with-param name="delimiter" select="$SLASH"/> </xsl:call-template> </xsl:template> <xsl:template match="xqx:schemaContextLocation"> <xsl:text> context </xsl:text> <xsl:choose> <xsl:when test="xqx:type"> <xsl:text> type (</xsl:text> <xsl:apply-templates select="xqx:QName[1]"/> <xsl:value-of select="$RPAREN"/> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="xqx:QName[1]"/> </xsl:otherwise> </xsl:choose> <xsl:for-each select="xqx:QName[position() > 1]"> <xsl:value-of select="$SLASH"/> <xsl:apply-templates select="."/> </xsl:for-each> </xsl:template> <xsl:template match="xqx:validatonContext"> <xsl:value-of select="xqx:validationMode"/> <xsl:if test="xqx:globalValidationContext"> <xsl:text> global </xsl:text> </xsl:if> <xsl:apply-templates select="xqx:schemaContextLocation"/> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:validateExpr']"> <xsl:text> validate </xsl:text> <xsl:apply-templates select="xqx:validationContext"/> <xsl:value-of select="$LBRACE"/> <xsl:apply-templates select="xqx:exprWrapper/*"/> <xsl:value-of select="$RBRACE"/> </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:text>*</xsl:text> </xsl:template> <xsl:template match="xqx:Wildcard"> <xsl:call-template name="delimitedList"> <xsl:with-param name="delimiter" select="$COLON"/> </xsl:call-template> </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="."/> <xsl:value-of select="$RPAREN"/> </xsl:template> <xsl:template match="xqx:documentTest"> <xsl:text>document-node(</xsl:text> <xsl:apply-templates select="*"/> <xsl:value-of select="$RPAREN"/> </xsl:template> <xsl:template match="xqx:attributeTest"> <xsl:text>attribute(</xsl:text> <xsl:choose> <xsl:when test="xqx:schemaContextLocation"> <xsl:apply-templates select="xqx:schemaContextLocation"/> <xsl:value-of select="$COMMA"/> <xsl:apply-templates select="xqx:QName"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$AT"/> <xsl:value-of select="xqx:nodeName"/> <xsl:if test="xqx:typeName"> <xsl:value-of select="$COMMA"/> <xsl:value-of select="xqx:typeName"/> </xsl:if> </xsl:otherwise> </xsl:choose> <xsl:value-of select="$RPAREN"/> </xsl:template> <xsl:template match="xqx:elementTest"> <xsl:text>element(</xsl:text> <xsl:choose> <xsl:when test="xqx:schemaContextLocation"> <xsl:apply-templates select="xqx:schemaContextLocation"/> <xsl:value-of select="$COMMA"/> <xsl:apply-templates select="xqx:QName"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="xqx:nodeName"/> <xsl:if test="xqx:typeName"> <xsl:value-of select="$COMMA"/> <xsl:value-of select="xqx:typeName"/> <xsl:if test="xqx:nillable"> <xsl:text> nillable </xsl:text> </xsl:if> </xsl:if> </xsl:otherwise> </xsl:choose> <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: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:pathExpr']"> <xsl:choose> <xsl:when test="xqx:expr"> <xsl:apply-templates select="xqx:expr"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$DOT"/> </xsl:otherwise> </xsl:choose> <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:value-of select="$LBRACE"/> <xsl:apply-templates select="xqx:attributeValue/xqx:expr"/> <xsl:value-of select="$RBRACE"/> <xsl:value-of select="$DOUBLEQUOTE"/> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:commentConstructor']"> <xsl:text><!--</xsl:text> <xsl:value-of select="comment"/> <xsl:text>--></xsl:text> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:piConstructor']"> <xsl:text><?</xsl:text> <xsl:value-of select="piTarget"/> <xsl:value-of select="$SPACE"/> <xsl:value-of select="piValue"/> <xsl:value-of select="$SPACE"/> <xsl:text>?></xsl:text> <xsl:value-of select="$NEWLINE"/> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:piConstructor']"> <xsl:text><![CDATA["</xsl:text> <xsl:value-of select="."/> <xsl:text>]]></xsl:text> <xsl:value-of select="$NEWLINE"/> </xsl:template> <xsl:template match="xqx:elementContent"> <xsl:value-of select="$LBRACE"/> <xsl:apply-templates select="*"/> <xsl:value-of select="$RBRACE"/> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:elementConstructor']"> <xsl:text><</xsl:text> <xsl:value-of select="xqx:tagName"/> <xsl:apply-templates select="xqx:attributeList/*"/> <xsl:text>></xsl:text> <xsl:apply-templates select="xqx:elementContent"/> <xsl:text><</xsl:text> <xsl:value-of select="$SLASH"/> <xsl:value-of select="xqx:tagName"/> <xsl:text>></xsl:text> </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 name="tagName"> <xsl:value-of select="$SPACE"/> <xsl:value-of select="."/> <xsl:value-of select="$SPACE"/> </xsl:template> <xsl:template name="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:apply-templates select="*"/> <xsl:text> }</xsl:text> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:computedCommentConstructor']"> <xsl:text> comment {</xsl:text> <xsl:apply-templates select="*"/> <xsl:text> }</xsl:text> </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="piTarget"/> <xsl:apply-templates select="piTargetExpr"/> <xsl:value-of select="$LBRACE"/> <xsl:apply-templates select="piValueExpr/*"/> <xsl:value-of select="$RBRACE"/> </xsl:template> <xsl:template match="xqx:expr[@xsi:type='xqx:computedNamespaceConstructor']"> <xsl:text> namespace </xsl:text> <xsl:value-of select="prefix/*"/> <xsl:value-of select="$SPACE"/> <xsl:value-of select="$LBRACE"/> <xsl:apply-templates select="uri/*"/> <xsl:value-of select="$RBRACE"/> </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:version"> <xsl:text> xquery version </xsl:text> <xsl:call-template name="quote"> <xsl:with-param name="item" select="."/> </xsl:call-template> <xsl:value-of select="$SEMICOLON"/> <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:value-of select="$NEWLINE"/> </xsl:template> <xsl:template match="xqx:defaultNamespaceDecl"> <xsl:text> default </xsl:text> <xsl:value-of select="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:value-of select="."/> </xsl:template> <xsl:template match="xqx:baseUriDecl"> <xsl:text> declare base-uri </xsl:text> <xsl:value-of select="."/> </xsl:template> <xsl:template match="xqx:xmlspaceDecl"> <xsl:text> declare xmlspace </xsl:text> <xsl:value-of select="$EQUAL"/> <xsl:value-of select="."/> </xsl:template> <xsl:template match="xqx:emptySequenceType"> <xsl:text>empty()</xsl:text> </xsl:template> <xsl:template match="xqx:atomicType"> <xsl:value-of select="."/> </xsl:template> <xsl:template match="xqx:occurenceIndicator"> <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: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="$LBRACE"/> <xsl:apply-templates select="xqx:expr"/> <xsl:value-of select="$RBRACE"/> </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:validationDecl"> <xsl:text> declare validation </xsl:text> <xsl:value-of select="."/> </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="$SEMICOLON"/> <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>
This section contains the current issues for XQueryX. The individual issues are shown in detail after an abbreviated issues list.
Editorial note | |
Only new issues (post-2003-09) are included in the abbreviated list. |
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: Should the stylesheet be normative ? (xqueryx-xsl-normative) | 3 | Open | xqueryx-xsl-normative |
3: Some terms tidy-up needed. (xqueryx-tidy) | 2 | Open | xqueryx-tidy |
4: Should XQueryX support pragmas, MUEs, and comments? (xqueryx-support-pragmas-etc) | 3 | Open | xqueryx-support-pragmas-etc |
5: How should the semantics of XQueryX be specified normatively?(xqueryx-normative-semantics) | 1 | Open | xqueryx-normative-semantics |
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 around 8 times as much effort as the current manual approach.
Resolution:
Issue (xqueryx-xsl-normative):
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:
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:
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):
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.
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.
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-operator-syntax):
XQueryX Operator Syntax
Source: XML Query WG
XQueryX currently uses function syntax for operators:
<q:function name="PLUS"> <q:constant datatype="INTEGER">1</q:constant> <q:constant datatype="INTEGER">2</q:constant> </q:function>
Several other possibilities have been suggested, eg:
<q:and/> and <q:equal/>
or
<q:binaryOperator name="AND"/> <q:binaryOperator name="EQUALS"/>
or
<q:mathOperator name="and"/> and <q:logicalOperator name="equal"/>
Resolution:
Issue (xqueryx-define-transformation):
Define Transformations from XQuery Grammar priority="2" status="closed"
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):
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:
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:
Issue (xqueryx-operators-symbolspace):
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:
Issue (xqueryx-star-identifier):
Wildcard
Originator: | XML Query WG |
Locus: | xqueryx |
Should * be used as an identifier? It should probably be a wildcard.
Resolution:
Issue (xqueryx-cast-treat-typeswitch):
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):
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):
Case of Constants
Source: XML Query WG
Should XQueryX constants use upper or lower case?
Resolution:
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):
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:
None recorded.
Issue (xqueryx-normative-semantics):
How should the semantics of XQueryX be specified normatively?
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:
None recorded.