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

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: []On Behalf Of
Filippo Furfaro
  Sent: Montag, 8. Oktober 2001 12:26
  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