W3C home > Mailing lists > Public > www-ql@w3.org > October to December 2001

RE: About closure operator in XPath and X-Query

From: Peter Fankhauser <fankhaus@darmstadt.gmd.de>
Date: Mon, 8 Oct 2001 15:17:06 +0200
To: "Filippo Furfaro" <furfaro@si.deis.unical.it>, <www-ql@w3.org>
Message-ID: <KNEAKBHGPLOADKCAOIFNGEPPCEAA.fankhaus@darmstadt.gmd.de>
It appears that you ask for "regular path expressions";
e.g. sth. like "parts/part*/number", to retrieve all "number"-elements
ancestor of "parts" and reachable exclusively by part.

Indeed XPath does not support regular path expression.
Personally, I haven't seen any convincing use cases for
regular path expressions for querying XML (although there exists a
good deal of database literature on processing regular path
expressions (deciding about containment, building specialized indices etc.).

A reasonable approximation for the path expression above is:
"parts//part/number | parts/number".
Homework: consider for which XML-documents this approximation
returns false hits.

Because XQuery supports arbitrary recursive functions, you
can express regular path expressions by means of a user defined

E.g., you can express "parts/part*/number" as follows:

define function myparts( xs:AnyTree* $x ) returns xs:AnyTree*
      for $y in $x return
      typeswitch ($y) as $y
        case element part { xs:AnyTree*} return myparts(nodes($y))
        case element number {xs:AnyTree*} return $y
        default return ()

for $v in /parts/*
return myparts($v)

Homework: try to use XSLTs template mechanism (with
recursion via "apply-templates") to accomplish sth. very similar.

Hope this clarifies,

(speaking for myself)

  -----Original Message-----
  From: www-ql-request@w3.org [mailto:www-ql-request@w3.org]On Behalf Of
Filippo Furfaro
  Sent: Montag, 8. Oktober 2001 12:26
  To: www-ql@w3.org
  Subject: About closure operator in XPath and X-Query

  Is it possible to express the closure (*) operator when specifying a path?
  The // operator provided by XPath seems too weak.
  For instance, how can I express a query that verifies if there is a path
  any length between two elements going only through <tag1> elements?

  thanks for your help
Received on Monday, 8 October 2001 09:14:32 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:43:42 UTC