通过简化示例最佳显示:
<?xml version="1.0" encoding="utf-8"?>
<root>
<A name="wrong"></A>
<B>not this</B>
<A name="right">
<subA></subA>
</A>
<B>yes, this</B> <!-- I want only this one -->
<A name="right">
<subA></subA>
</A>
<C>dont want this</C>
<B>not this either</B> <!-- not immediately following -->
</root>
Run Code Online (Sandbox Code Playgroud)
我希望所有<B>节点紧跟<A>在name属性为equals 的节点之后"right".
我尝试了什么:
//A[@name="right"]/following-sibling::*[1]
Run Code Online (Sandbox Code Playgroud)
它选择紧跟在"右"之后的任何节点<A>(即包括<C>).我不知道如何制作它<B>.这不起作用:
//A[@name="right"]/following-sibling::*[1 and B]
Run Code Online (Sandbox Code Playgroud)
这个:
//A[@name="right"]/following-sibling::B[1]
Run Code Online (Sandbox Code Playgroud)
将选择"右"之后的第一个 ,但不一定是紧随其后的第一个.<B><A>
你快到了:
//A[@name='right']/following-sibling::*[position()=1 and self::B]
Run Code Online (Sandbox Code Playgroud)
在样本上只提供一个节点.
要在条件中引用元素名称,您需要self.简单地[B]说就是一个文本完全等于的元素B.
| 归档时间: |
|
| 查看次数: |
18395 次 |
| 最近记录: |