[英](XPATH) Limit the scope of "Ancestor"
我可以限制“祖先”的范圍嗎? 例如,
1...<div itemtype="product" itemprop="name">
2... <div itemtype="product">
3... <div itemtype="List">
4... <span itemprop="name"> </span>
5... </div>
6... <span itemprop="name"> </c>
7... </div>
8...</div>
條件: 1. 選擇節點 *[@itemtype="product' and not(@itemprop)] 2. 在這個子節點下,選擇 itemprop,但它們之間沒有新的 itemtype,在這種情況下只應選擇第 6 行。
I used this code, but not working due to ancestor nodes
//*[@itemtype and not(@itemprop) and contains(@itemtype, '/Product')]//*[@itemprop='name' and count(ancestor::*[contains(@itemtype, 'schema.org/Product')])=count(ancestor::*[@itemtype])]
如何從祖先搜索中排除頂級節點?
1...<div itemtype="product" itemprop="name"> --> ignore this line
------------------------------------------->
2... <div itemtype="product">
3... <div itemtype="List">
4... <span itemprop="name"> </span>
5... </div>
6... <span itemprop="name"> </c>
7... </div>
8...</div>
如果我理解正確的話,你正在尋找這樣的東西:
//*[@itemtype='product'][not(@itemprop='name')]/descendant-or-self::*[1]
輸出:
<div itemtype="product">
<div itemtype="List">
<span itemprop="name"> </span>
</div>
<span itemprop="name"> </span>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.