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

Re: Recursion (I think)

Subject: Re: Recursion (I think)
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 26 Sep 2005 12:50:00 +0100
objecttype mean
> Ok, thanks.  Does that mean it finds the nearest id attribute for any  
> node?  Can I specify that it's the id attribute from the nearest  
> "ObjectType" node?

All axes in Xpath work the same way. On the child axis
child::* selects all element children and child::ObjectType selects
ObjectType children, so on the ancestor axis it would be

ancestor-or-self::ObjectType

rather than 

ancestor-or-self::*

If you only want to consider ObjectType.


> ancestor-or-self::*[ObjectType][1]/@id
that would select the id of the nerest ancestor that had an ObjectType
child.

Just as in the child axis  ObjectType/@id selects the id of ObjectType,
but *[ObjectType]/@id selects the id of an element with an ObjectType child.

> What purpose does the [1] serve?

as always [1] means [position()=1] and selects the first matching item
rather than all of them.

If you are at c 

<a  id="a">
  <b id="b">
    <c/>

then ancestor::*/@id seelcts all the id attributes of all ancestors, so
both id="a" and id="b" here.

ancestor::*[@id] selects all ancestor elements that have an id attribute
so ,a> and <b> here.

ancestor::*[@id][1] just seletcs the first of those (counting backwards)
s <b> here.

ancestor::*[@id][1]/@id

selects the id attribute of the nearest eleemnt that has an id
attribute, so id="b" here.

You could also write this as
(ancestor::*/@id)[last()]
but I find the first form more readable.

David


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.