Xpath: select preceding and following sibling

Viewed 15

HTML:

<div class="reviewText" id="game-review">
    <h2>xWays Hoarder xSplit Review</h2>
    <p>While other studios are busy studying Greek mythology or Ancient Rome for their backstory, NoLimit City is contemplating the amount of shit a male produces with an average life-expectancy of 76 years. The <strong>11,030x</strong> potential is literally a reflection of that number (in kilograms), and it triggers the ‘King of Waste’ big win feature when cracked.</p>
    <p>Talk about being too successful to ‘give a shite’ anymore, but please do understand that we mean this in the best possible way. xWays Hoarder xSplit is another stunningly good release from the crafty studio, building on the already established and successful xWays feature, while also adding a brand new and innovative xSplit Wild to the mix.</p>
    <div class="imgText">
        <div class="parentImgText">
            <div class="childImgText"><img alt="Reel-Screen" class="textImgBig blurring lazyloaded" data-src="https://slotcatalog.com/userfiles/image/games/Nolimit-City/20688/xWays-Hoarder-xSplit-6504018.jpg" title="Reel-Screen" src="https://slotcatalog.com/userfiles/image/games/Nolimit-City/20688/xWays-Hoarder-xSplit-6504018.jpg" width="826" height="464"></div>
        </div>
        <span class="titleImg">xWays Hoarder xSplit Slot - Reels Screen</span></div>
    <h2 id="xways-hoarder-xsplit-features">xWays Hoarder xSplit Features</h2>
    <p>xWays symbols can land on the 3 middle reels only, and they always reveal 2 to 4 instances of a randomly selected matching pay symbol. If you land multiple xWays symbols, they all reveal the same matching symbol.</p>
    <p>The newcomer, xSplit Wilds, can land during base game play only, and this symbol will only appear on reels 3, 4 and 5. Whenever they land, all symbols to the left on the same row are split in two. If an xWays symbol is split by the xSplit Wild, the value of the xWays symbol is doubled for every split. The xSplit turns into a regular wild, and this wild can also be split by a new xSplit symbol.</p>
    <p>You trigger the Bunker Raid Bonus Round when you land <strong>3 or 4 Fallout Scatters</strong> anywhere on reels 2 to 5. This awards <strong>7 or 10 Bunker Raid Spins</strong>, respectively. However, if a scatter is split by an xSplit Wild, it turns into a Super Scatter. If you trigger the bonus round with a Super Scatter involved, the Super Scatter and the symbols below turn into sticky xWays symbols.</p>
    <p>All xWays symbols you land during the bonus round are sticky for the duration of the feature, and they also award <strong>+1 extra spin</strong>. The xWays symbols drop down to the bottom row, or the lowest xWays symbol on that reel, and it will then merge with any sticky xWays symbol already present.</p>
    <p>xWays symbols are also collected in a meter, and you reach a new ‘Hoarder Level’ for every 3 you land. Each new Hoarder level removes the lowest remaining character (premium) and object (low value) symbol from the reels. Starting at level zero, the bonus round comes with 3 Hoarder levels on top of that.</p>
    <p>If you manage to reach the top of the <strong>Hoarder meter</strong>, the whole feature shifts to the Wasteland Free Spins round. Only 4 symbols will land during this top-tier bonus round, namely the 2 highest value character/premium symbols and the 2 highest value object symbols.</p>
    <p>The 9 xWays symbols you’ve gathered on the 3 middle reels will now merge to form a mega symbol that covers the entire 3 middle reels per free spin. Each of the merged xWays symbols still come with a symbol count of x2 to x4 however, multiplying with each other per spin to generate potentially massive payouts.</p>
    <p>Non-UK players can take advantage of the <strong>Bonus Buy feature</strong> with the following options:</p>
    <ul>
        <li>Bunker Raid Spins with 7 free spins costs <strong>95x</strong> your stake with a <strong>96.38 %</strong> RTP.</li>
        <li>Bunker Raid Spins with 10 free spins costs <strong>180x</strong> your stake with a <strong>96.38 %</strong> RTP.</li>
        <li>Wasteland Free Spins with 7 free spins costs <strong>777x</strong> your stake with a <strong>96.68 %</strong> RTP.</li>
        <li>Random Mystery option costs <strong>218x</strong> your stake with a <strong>96.5%</strong> RTP.</li>
    </ul>
    <p>In this context, it’s good to keep in mind that the Bonus Round triggers organically once every 307 spins on average.</p>
    <h2 id="the-200-spins-xways-hoarder-xsplit-experience">The 200 Spins xWays Hoarder xSplit Experience</h2>
    <p>We purchase the random bonus round option pretty soon after the video starts, and this gave us 10 bunker raid spins. We landed quite a few xWays symbols, and this kept the feature going for a good while. One big win followed another, and we will definitely be back for more! Check it all out for yourself in the 8-and-a-half-minute highlights video below.</p>

I need to select all p and li tags after one h2 and before another h2

My xpath now is //div[@id='game-review']//h2/following-sibling::p[preceding-sibling::h2] which is not working. Right now this code returns all elements with p tag between the headers, but I need to get p for each header with h2 tag

1 Answers

This XPath will do that work:

//*[self::p or self::*/li][preceding-sibling::h2 and following-sibling::h2]

Explanations:
[preceding-sibling::h2 and following-sibling::h2] is limiting the sibling elements between the h2 tags.
//*[self::p or self::*/li] selecting p tag nodes or li sub-nodes of any kind of parent tag.
It works, you can check it here or with any similar XPath online validator.

Related