Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath - Select every Nth node after a certain node

Tags:

xpath

Say I have something like the following:

<table>
    <tbody>
        <tr><td>1</td></tr>
        <tr><td>2</td></tr>
        <tr><td>3</td></tr>
        <tr><td>4</td></tr>
        <tr><td>5</td></tr>
        <tr><td>6</td></tr>
        <tr><td>7</td></tr>
        <tr><td>8</td></tr>
        <tr><td>9</td></tr>
        <tr><td>10</td></tr>
        <tr><td>11</td></tr>
        <tr><td>12</td></tr>
        <tr><td>13</td></tr>
        <tr><td>14</td></tr>
    </tbody>
</table>

I want to be able to select every fourth tr element starting with row 3.

The closest I have gotten to this is:

//tbody/tr[position() mod 4 = 1 and position() > 1]

But this starts from the first row.

like image 525
mgates2 Avatar asked Jan 23 '15 20:01

mgates2


1 Answers

All you need to do is //tbody/tr[position() mod 4 = 3].

like image 149
Dabbler Avatar answered Oct 03 '22 00:10

Dabbler