This is the mail archive of the mailing list .

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: XPath for all of an element type prior to context node?

Hi Michael,

> When the context node is any of those with an id attribute, I want a way to
> get the list of resources nodes that occur:
> - before the context node; or
> - after the context node.

>From the source you posted, it looks as though the resource elements
aren't the ancestors or descendants of any of the nodes with id
attributes, so you should just be able to use:

  preceding::resource (to get those before the context node)
  following::resource (to get those after it)

If you're doing this a lot and have a long document, you may or may
not find it more efficient to use a couple of keys that index the
resource elements according to the nodes with id attributes that
they're before or after:

<xsl:key name="resources-before" match="resource"
         use="following::*/@id" />
<xsl:key name="resources-after" match="resource"
         use="preceding::*/@id" />

and then use:

  key('resources-before', @id) (to get those before the context node)
  key('resources-after', @id)  (to get those after it)
I hope that was what you were after,


Jeni Tennison

 XSL-List info and archive:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]