[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Need for a technique

Subject: Re: Need for a technique
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 13 Feb 2001 13:05:13 +0000
tennison technique
Hi Paul,

> In this example, I am looking for the nearest enclosing <hx> element (h1 or
> h2).
>
> I need an Xpath expression that would give back h1 for the first <x/>
> element, and h2 for the second.

You can get the 'enclosing' elements with the ancestor:: axis.  So you
want to look along the ancestor:: axis and find any elements that are
called h1 or h2:

  ancestor::h1 | ancestor::h2

or:

  ancestor::*[self::h1 or self::h2]

or, if you want any element whose name starts with 'h' and ends in a
number, then:

  ancestor::*[starts-with(name(), 'h') and
              number(substring(name(), 2))]

and so on.

You want the nearest of these, which you can identify by studying its
position in the document relative to the other nodes in the set. The
first expression (ancestor::h1 | ancestor::h2) is a union of two node
sets, so if you use a positional predicate on that, the positions will
be judged in document order, and you want the last:

  (ancestor::h1 | ancestor::h2)[last()]

The other expressions are single steps, and the ancestor:: axis is a
backwards axis, so any positional predicates will be assessed with the
node set in reverse document order, and you need:

  ancestor::*[self::h1 or self::h2][1]

or:

  ancestor::*[starts-with(name(), 'h') and
              number(substring(name(), 2))][1]

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

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-2013 All Rights Reserved.