Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我该如何选择第二个<son>。它应该是这样的:parent[first-child='son']
<son>
parent[first-child='son']
<parent> <daughter> <son> </parent> <parent> <son> </parent>
你想要一个没有任何东西的儿子:
//son[not(preceding-sibling::*)]
如果需要指定父级,请使用
//son[not(preceding-sibling::*)][parent::parent]
(请注意,第一个parent::表示轴,而第二个parent是元素的名称。)
parent::
parent
我想你想要//parent[*[1][local-name() = 'son']]。这将选择parent第一个元素子节点具有本地名称的元素son。
//parent[*[1][local-name() = 'son']]
son