Reputation: 4242
Given the following HTML:
<body>
<h2>
<span class="mw-headline" id="KNOWNID">S</span>
<span class="mw-editsection">
<span class="mw-editsection-bracket">[</span>
<a href="/w/index.php?title=Og&action=edit&section=4">Bn</a>
<span class="mw-editsection-bracket">]</span>
</span>
</h2>
<div class="h"></div>
<p>M</p>
<p>M</p>
<p>M</p>
<p>M</p>
<p>M</p>
<h2>
<span class="mw-headline" id="NEXTKNOWNID">S</span>
<span class="mw-editsection">
<span class="mw-editsection-bracket">[</span>
<a href="/w/index.php?title=Og&action=edit&section=4">Bn</a>
<span class="mw-editsection-bracket">]</span>
</span>
</h2>
</body>
I have the ID="KNOWNID
" and need to select all <p></p>
Elements until the id="NEXTKNOWNID"
. How can this be acomplised with XPATH?
Thanks
Upvotes: 1
Views: 614
Reputation: 473753
Use the preceding-sibling
and following-sibling
:
//p[preceding-sibling::h2/span[@id="KNOWNID"] and following-sibling::h2/span[@id="NEXTKNOWNID"]]
Upvotes: 3