本文介绍了抓住XPath中的同级兄弟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图根据以下包含树中某个单词的树中较高位置的强标签来捕获 li
类文本:"restaurants":
I am trying to grab the li
class text in the following based on the strong tag higher up in the tree containing a certain word, in this case: "restaurants":
<p class="">The location, where the condo is situated,
offers a good choice of <strong>restaurants</strong>.
Some of them are listed below:</p>
<ul class="">
<li class="">Restaurant 1</li>
<li class="">Restaurant 2</li>
<li class="">Restaurant 3</li>
<li class="">Restaurant 4</li>
<li class="">Restaurant 5</li>
</ul>
假设我需要使用祖先"在树上向上移动,我尝试了以下几种变体:
I have tried many variations of the following, assuming that I need to go higher up the tree by using "ancestors":
//ul/li[contains(ancestor-or-self::@strong[contains(text(),'Restaurants')])
推荐答案
此XPath,
//p[strong = 'restaurants']/following-sibling::ul[1]/li
将在包含 strong
的 p
元素的同级元素之后,选择第一个 ul
元素的所有 li
元素>字符串值为"restaurants"
的元素.
will select all li
elements of the first ul
element following sibling of the p
element that contains a strong
element whose string value is "restaurants"
.
这篇关于抓住XPath中的同级兄弟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!