[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

distance between elements and hierarchical order

Charles Brooking charles.brooking at research.canon.com.au
Fri Dec 9 11:01:13 PST 2005


html distance between elements
Wolfgang Hoschek wrote:
> Both can probably be solved by walking the ancestor axis of the 
> elements towards the root.
> For 2) find the nearest common ancestor, and add up the steps.
People can possibly correct me on this, but:

    let $a :=
      element a
      {
        attribute id {"1"},
        element b
        {
          attribute id {"1-1"},
          element c {attribute id {"1-1-1"}},
          element c {attribute id {"1-1-2"}}
        },
        element b
        {
          attribute id {"1-2"},
          element c {attribute id {"1-2-1"}},
          element c {attribute id {"1-2-2"}}
        }
      }
    let
      $x := $a[@id="1"]/b[@id="1-1"]/c[@id="1-1-1"],
      $y := $a[@id="1"]/b[@id="1-2"]/c[@id="1-2-2"]
    let $possible-distances :=
      let
        $x-ancestors := $x/ancestor-or-self::element(),
        $y-ancestors := $y/ancestor-or-self::element()
      for
        $x-ancestor at $x-ancestor-position in $x-ancestors,
        $y-ancestor at $y-ancestor-position in $y-ancestors
      where
        $x-ancestor is $y-ancestor
      return
        count($x-ancestors) - $x-ancestor-position +
        count($y-ancestors) - $y-ancestor-position
    return
      min($possible-distances)

Now a question:

If I had the following as one of the for-clauses:

    $x-ancestor at $x-ancestor-position in $x/ancestor-or-self::element()

would $x itself (always) be at position 1, or should it be last?

Later
Charlie

-- 
Charles Brooking
Associate Software Engineer
Canon Information Systems Research Australia

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://xquery.com/pipermail/talk/attachments/20051209/ef0b7409/attachment.htm


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.