Re: [xsl] Recursion (I think)

Subject: Re: [xsl] Recursion (I think)
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 26 Sep 2005 12:50:00 +0100
> 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


rather than 


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

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">

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.


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

You could also write this as
but I find the first form more readable.


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:

Current Thread