Page 1 of 1

Get the following siblings with a limit

Posted: Wed Dec 15, 2021 1:19 am
by sunnykeerthi
Hi,

I'm want an XSLT that will extract the content following the h1 and before the next h1 or end of the document.

Here is my data.

Code: Select all

<div id="toc">
<h1>Head 1</h1>
<p>para text</p>
<div class="class1">div content</div>
<h1>Head 2</h1>
<p>para text</p>
  <span>span content</span>
<h1>Head 3</h1>
<p>para text</p>
</div>
when I try descendant::h1[1]/following::node() it retrieves everything. this works fine with descendant::h1[3]/following::node(), because there is no following h1 after h1[3]. Please let me know on how can I do it.

Re: Get the following siblings with a limit

Posted: Wed Dec 15, 2021 7:42 am
by Radu
Hi,

Maybe you can try something like this (descendant::h1[1]/following::*)[1]

By the way node() matches elements, text content, comments, processing instructions. This is why I used "*" which matches only elements.

Regards,
Radu