[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XPath preceding

Subject: Re: [xsl] XPath preceding
From: Michael Müller-Hillebrand <mmh@xxxxxxxxxxxxx>
Date: Mon, 9 Apr 2012 20:27:42 +0200

Hi Rick,


> the preceding axis contains all nodes in the same document as the context
node that are before the context node in document order, excluding any
ancestors and excluding attribute nodes and namespace nodes

If you have access to XPath 2 you could use he new << and >> operators, but I
guess you have not. So if I read on in the spec:

> NOTE: The ancestor, descendant, following, preceding and self axes partition
a document (ignoring attribute and namespace nodes): they do not overlap and
together they contain all the nodes in the document.

I would assume you have to built something like this:

preceding::case-cite or ancestor::*//case-cite

as ancestors (and their descendants) are also before the current node in
document order but not part of the preceding:: axis.

- Michael

Am 09.04.2012 um 17:09 schrieb Rick Quatro:

> Hello,
> I am trying to find a particular element that is anywhere before the
> element like this:
> preceding::case-cite
> This works if the two elements have the same parent, but I want to match an
> element anywhere before the current element. For example, if the context is
> the <case-cite-2nd> element, I want to find a <case-cite> element anywhere
> in the structure previous to the <case-cite-2nd> element.
> <root>
>  <section>
>    <para>
>      <case-cite/>
>    </para>
>    <para>
>      <case-cite-2nd/>
>    </para>
>  </section>
> </root>
> Thanks in advance.
> Rick Quatro

Current Thread