0
敲我的頭靠在內表面上,這個之間的獨家兄弟匹配:的XPath 1 - 以下同胞和只剩下一前同輩(不貪婪匹配)
<table class="magic">
<tbody>
<!-- previous sections here -->
<!-- uninteresting section example begin -->
<tr class="head">
<th colspan="2">Spain</th>
</tr>
<!-- ... -->
<tr class="section-break"></tr>
<!-- uninteresting section example end -->
<!-- begin interesting section (position not fixed) -->
<tr class="head">
<th colspan="2">United States</th>
</tr>
<tr></tr> <!-- match here begin (length not fixed) -->
<tr></tr>
<!-- ... -->
<tr></tr> <!-- match here end -->
<tr class="section-break"></tr>
<!-- end interesting section -->
<!-- next sections -->
<!-- ... -->
<tr class="section-break"></tr>
<!-- ... -->
<tr class="section-break"></tr>
<!-- ... -->
</tbody>
<table>
到目前爲止:
/table[@class="magic"]/tbody/tr[following-sibling::tr/th[text()="United States"] and preceding-sibling::tr[contains(@class,"section-break")][12345]]
^--- evil magic constant 12345: must not be hard-coded, probably some sort of `count()`constraint or Kayessian ?
但是如何在United States
之後找到第一個section-break
?
可以用'th =「United States」'替換'./th [contains(。,「United States」)]''。 –