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

Re: [xsl] Selecting between heading tags in XHTML


Subject: Re: [xsl] Selecting between heading tags in XHTML
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 30 Oct 2014 18:47:49 -0000

There's no direct way of selecting all nodes on an axis until some condition.

The best solution is rather context dependent, e.g. are you in XSLT 1.0 or
XSLT 2.0 or standalone XPath. It may also depend what you want to do with the
nodes, e.g. apply-templates to them.

One solution in XPath 2.0 is

following-sibling::* except following-sibling::h1/following-sibling::*

But it's not necessarily the most efficient.

Michael Kay
Saxonica
mike@xxxxxxxxxxxx
+44 (0) 118 946 5893




On 30 Oct 2014, at 18:35, Mark Giffin m1879@xxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> I want to select all siblings between heading tags in an XHTML file, as
shown below.
>
> <div>
>    <h4>my heading</h4> <<<---- select from this sibling
>    <ol>
>      <li></li>
>    </ol>
>    <p></p>
>    <p></p>
>    <p></p>
>    <ul>
>      <li></li>
>    </ul>      <<<<---- all the way down to this sibling
>    <h1></h1>  <<<<---- Do not select this sibling or anything after it
>    <p></p>
>    etc.
> </div>
>
> Given the context of <h4> above, I figure that
>
> following-sibling::*[some predicate here]
>
> would do this but I haven't guessed what would exclude the <h1> (or <h2>,
etc.) and everything that follows it. What's a good way to do this?
>
> Thanks,
> Mark


Current Thread
Keywords