RE: About closure operator in XPath and X-Query

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
function:

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,

Peter
(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
of
  any length between two elements going only through <tag1> elements?

  thanks for your help
  Filippo

Received on Monday, 8 October 2001 09:14:32 UTC