3zzy 3zzy - 2 months ago 11
CSS Question

Select all elements until - XPath

<ul id="ListView">
<li id="item3d1f07bb0e" class="result clearfix li"></li>
<li id="item2370583f1f" class="result clearfix li"></li>
<li id="item43f35da923" class="result clearfix li"></li>
<li id="item4190e6d48f" class="result clearfix li"></li>
<li class="result clearfix li"></li>
<li id="item3ab7e686fe" class="result clearfix li"></li>
</ul>


XPath:

//li[contains(@class, 'result') and @id]


.. grabs all items, but I want it to stop looking after it finds a
li
without an
id
.

Answer
//li[contains(@class, 'result') and @id and not(preceding-sibling::li[not(@id)])]

stop when the li has a preceding sibling li without an id attribute.

returns:

<li id="item3d1f07bb0e" class="result clearfix li"></li>
<li id="item2370583f1f" class="result clearfix li"></li>
<li id="item43f35da923" class="result clearfix li"></li>
<li id="item4190e6d48f" class="result clearfix li"></li>
Comments