Verboseness - XML Syntax for XQuery 1.0 (XQueryX)

> XML Syntax for XQuery 1.0 (XQueryX)
>  (http://www.w3.org/TR/xqueryx )
> 
At the bottom of this email is an excerpt. As you can see, the
equivalent XML is very, very long-winded. It is using an element syntax
for the XPath expressions, and it also heavily expands the XQuery parts
aswell. When I heard about the XML Syntax, I thought that was an
excellent developement, as an alternative to the existing text syntax,
with its pseuodo elements etc. However this XML Syntax below is such
that it is unlikely to be used for hand written querys.

Could they not have a version with normal XPath and perhaps provide a
return syntax which is similar to an XSLT template body? I think they
should strive to make XQuery consistent with XSLT rather than SQL. Both
XQuery and XSLT perform broadly similar tasks - take nodes specified by
an XPath expression and return nodes based on literals. XSLT is a widely
used XML standard with which many XML programmers are familiar. As it
stands, the text syntax is completely alien to SQL programmers anyway.


------------------------------------------------------------------------
---------------------
Here is Q13 from the the [XQuery Working Draft] : "List each publisher
and the average price of its books." 
FOR $p IN distinct(document("bib.xml")//publisher)
LET $a := avg(document("bib.xml")//book[publisher = $p]/price)
RETURN
    <publisher>
        <name>{ $p/text() }</name>
        <avgprice>{ $a }</avgprice>
    </publisher>
Here is the equivalent XML syntax.
<q:query xmlns:q="http://www.w3.org/2001/06/xqueryx">
  <q:flwr>
    <q:forAssignment variable="$p">
      <q:function name="distinct">
        <q:step axis="SLASHSLASH">
          <q:function name="document">
            <q:constant datatype="CHARSTRING">bib.xml</q:constant>
          </q:function>
          <q:identifier>publisher</q:identifier>
        </q:step>
      </q:function>
    </q:forAssignment>
    <q:letAssignment variable="$a">
      <q:function name="avg">
        <q:step axis="CHILD">
          <q:function name="document">
            <q:constant datatype="CHARSTRING">bib.xml</q:constant>
          </q:function>
          <q:step axis="CHILD">
            <q:predicatedExpr>
              <q:identifier>book</q:identifier>
              <q:predicate>
                <q:function name="EQUALS">
                  <q:identifier>publisher</q:identifier>
                  <q:variable>$p</q:variable>
                </q:function>
              </q:predicate>
            </q:predicatedExpr>
            <q:identifier>price</q:identifier>
          </q:step>
        </q:step>
      </q:function>
    </q:letAssignment>
    <q:return>
      <q:elementConstructor>
        <q:tagName>
          <q:identifier>publisher</q:identifier>
        </q:tagName>
        <q:elementConstructor>
          <q:tagName>
            <q:identifier>name</q:identifier>
          </q:tagName>
          <q:step axis="CHILD">
            <q:variable>$p</q:variable>
            <q:nodeKindTest kind="TEXT" />
          </q:step>
        </q:elementConstructor>
        <q:elementConstructor>
          <q:tagName>
            <q:identifier>avgprice</q:identifier>
          </q:tagName>
          <q:variable>$a</q:variable>
        </q:elementConstructor>
      </q:elementConstructor>
    </q:return>
  </q:flwr>
</q:query>

Received on Thursday, 14 June 2001 06:29:19 UTC