xsl-list
[Top] [All Lists]

Re: Recursion (I think)

2005-09-26 04:50:00

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::*[(_at_)id] selects all ancestor elements that have an id attribute
so ,a> and <b> here.

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

ancestor::*[(_at_)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
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>