W3C home > Mailing lists > Public > public-qt-comments@w3.org > July 2005

[FS] XQuery last call comment

From: Loredana Afanasiev <lafanasi@gmail.com>
Date: Sat, 16 Jul 2005 18:10:42 +0200
Message-ID: <16ed8eea05071609102e286a29@mail.gmail.com>
To: public-qt-comments@w3.org
Cc: marx@science.uva.nl

Dear Members of W3C XQuery working group,

We have the following question/remark regarding the user-defined functions.

Q: How easy is it to define and use tree navigation primitives in XQuery?

There are very natural cases of user-defined navigation axes that
would profit, both in readability and efficiency, from the applicative
nature of the navigation paths (as opposed to the {\em iterative style} of
programming that XQuery adopted). See for example \cite{bird:exte05}
that extends XPath with linguistically motivated navigation axis.

Let's consider the following example
based on a virtual XML document called \verb|example.xml| in which all
the elements contain an attribute \verb|a| of type \verb|xs:integer|.
And suppose your application makes frequent use of queries containing a
\verb|desc_a| primitive. \verb|desc_a| applies on a context set of
nodes and returns all the descendants with the \verb|@a|-value bigger
then the \verb|@a|-value of the context node.

The following XQuery query  below describes the \verb|desc_a| primitive
as a user-defined function and applies it on a initial sequence of
nodes obtained by evaluating an abstract location path \verb|path1|.
The result of evaluating the user-defined axis step is passed as {\em
  evaluation context} to another abstract location path \verb|path2|.

declare function desc_a($x as element()) as element()*
   for $y in $x/descendant::*
   where $x/@a < $y/@a
   return $y

for $x in doc(example.xml)/path1
return desc_a($x)/path2


It seems natural (and we believe, more efficient) to express this in a
path-like manner:


Here \verb|desc_a()| is the same user-defined function as above,
except we would like in this case, the evaluation results of the
\verb|path1| to be passed as the evaluation context to
\verb|desc_a()|. To achieve this it is required that the {\em dynamic
  context} applies to user-defined functions, which is not the case in

Now let's try to express a location path that contains the
\verb|desc_a()| primitive in the scope of a filter expression.


We cope with this query in XQuery for example, using the
\ver|for-where| expression.

for $x in doc('example.xml')/path1
where exists(desc_a($x))
return $x

This example might not convince you that XQuery should allow for
user-defined navigational axes, but our concern here is the
compositionality of the approach above. What happens in case we want
to express a location path that contains \verb|desc_a()| primitive in
the scope of a nested filter expression, like the example below.  We
believe that the pseudo XPath query below requires effort both to
express it in XQuery and also to interpret it  afterwards.

doc('example.xml')/path1[path2/desc_a()[path3/desc_a()/@a = 10]]

We would appreciate your comments on this issue.

Best regards,
Loredana Afanasiev 
Maarten Marx


  author =          {S. Bird and  Y. Chen and  S. Davidson and
                  H. Lee   and Y. Zheng},
  title =          {Extending {XPath} to Support Linguistic Queries},
  booktitle =          {Proceedings of Programming Language
Technologies for XML (PLANX)},
  pages =         {35-46},
  year =         2005
Received on Sunday, 17 July 2005 14:08:04 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:45:25 UTC