Reputation: 185
This is my HTML:
<table dir = "rtl .......">
<tbody>
<script src = "get.aspx?type=js&file=ajax&rev=3"......>
<script language = "JavaScript" src = "get.aspx?type=js&file=mc&rev=6"></script>
<script>..</script>
<tr>
<td class = "d2"...>..</td>
</tr>
<tr>..</tr> <--
<tr>..</tr> <--
<tr>..</tr> <-- these elements
<tr>..</tr> <--
<tr>..</tr> <--
<tr>..</tr> <--
<tr>..</tr> <--
<tr>
<td class = "d2"...>..</td>
</tr>
<script>..</script>
<tr>..</tr>
<tr>..</tr>
<tr>..</tr>
How would I count or select all <tr>
elements between the two <td>
elements whose id is d2
?
Upvotes: 1
Views: 3701
Reputation: 26940
The xpath is going to be a long one so brace yourself:
count(//tr[preceding-sibling::tr/td[@class = 'd2']][count(.|//tr[following-sibling::tr/td[@class = 'd2']])=count(//tr[following-sibling::tr/td[@class = 'd2']])])
To select the actual nodes and not have just the count, simply remove the first count :
//tr[preceding-sibling::tr/td[@class = 'd2']][count(.|//tr[following-sibling::tr/td[@class = 'd2']])=count(//tr[following-sibling::tr/td[@class = 'd2']])]
There are various things happening here notably:
Upvotes: 4