Reputation: 131
Can I limit the scope of "Ancestor"? For example,
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>
Condition: 1. Select nodes *[@itemtype="product' and not(@itemprop)] 2. Under this childnodes, select itemprop, but between them, there's no new itemtype, in this case only line 6 should be selected.
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])]
How can I exclude the top nodes from ancestor searching?
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>
Upvotes: 1
Views: 251
Reputation: 24928
If I understand you correctly, you're looking for something like this:
//*[@itemtype='product'][not(@itemprop='name')]/descendant-or-self::*[1]
Output:
<div itemtype="product">
<div itemtype="List">
<span itemprop="name"> </span>
</div>
<span itemprop="name"> </span>
</div>
Upvotes: 1