xPath - 如何向节点的父节点添加条件?
我正在尝试向节点的父节点添加条件,但无法使其工作。
我只想要具有特定类别的节点,但也希望其父节点也具有特定类别,例如:
//*[@class='price' and parent@class='special-price']
有人知道如何为父节点添加条件吗?
谢谢
I'm trying to add a condition to a node's parent, and I can't get it to work.
I only want the nodes having a certain class, but also for which the parent has also a certain class, like :
//*[@class='price' and parent@class='special-price']
Does someone have an idea on how to add conditions on parents too ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您无论如何都要搜索整个文档,请在查找子文档的过程中过滤父文档,而不是选择子文档,然后返回检查父文档。
If you're searching the whole document anyway, then filter the parents en route to the children, rather than selecting the children and then going back up to check the parent.
使用
//*p[@class = 'special-price']/*[@class = 'price']
或//*[@class = 'price' 和 ../ @class = '特价']
。Use
//*p[@class = 'special-price']/*[@class = 'price']
or//*[@class = 'price' and ../@class = 'special-price']
.