Subject: RE: the nearest ancestor with the attribute
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Wed, 17 Jan 2001 09:19:36 -0000
|
> You're absolutely right that the ancestor axis is a reverse axis. If
> you were using:
>
> ancestor::*[1]/@attr
>
> you'd be fine (aside from the fact that you'd be stuffed if the node's
> parent didn't have a 'attr' attribute). However, the last axis used in
> the XPath is the 'attribute' axis, which takes you back to document
> order again. To get the last one, use:
>
> ancestor::*/@attr[last()]
>
> At least I *think* that's right ;)
No, I don't think it is. This expression will return a set consisting of the
last @attr attribute of each ancestor element. An element can only have one
@attr attribute so saying you want its last one is pointless.
An axis returns a list of nodes, which is always in either forwards or
reverse document order. This affects the meaning of position() and last()
when applied to a predicate used in a Step based on that axis. The final
result of a path expression, however, is always a set of nodes, with no
intrinsic order. Many operations on a node-set access the nodes in document
order. This includes a filter expression, so:
(ancestor::*/@attr)[last()] will select the last in document order (i.e. the
innermost available attribute).
Mike Kay
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
- RE: the nearest ancestor with the attribute, (continued)
- Vun Kannon, David - Mon, 15 Jan 2001 16:59:33 -0500 (EST)
- Oliver Becker - Tue, 16 Jan 2001 03:28:01 -0500 (EST)
- Wendell Piez - Tue, 16 Jan 2001 11:39:19 -0500 (EST)
- Jeni Tennison - Wed, 17 Jan 2001 03:55:34 -0500 (EST)
- Michael Kay - Wed, 17 Jan 2001 04:33:06 -0500 (EST) <=
- Jeni Tennison - Wed, 17 Jan 2001 05:53:44 -0500 (EST)
- Wendell Piez - Wed, 17 Jan 2001 14:08:10 -0500 (EST)
- Michael Kay - Thu, 18 Jan 2001 04:45:33 -0500 (EST)
- David Carlisle - Thu, 18 Jan 2001 05:54:27 -0500 (EST)
|
|