【发布时间】:2011-06-16 10:20:43
【问题描述】:
最好通过一个简化的例子来展示:
<?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>
我希望所有<B> 节点立即 跟随<A> 节点,name 属性等于"right"。
我尝试了什么:
//A[@name="right"]/following-sibling::*[1]
选择紧跟“右”<A>(即包括<C>)之后的任何节点。我不知道如何使它只有<B>。这不起作用:
//A[@name="right"]/following-sibling::*[1 and B]
这个:
//A[@name="right"]/following-sibling::B[1]
会选择“右”<A> 之后的第一个 <B>,但不一定是紧随其后的。
【问题讨论】: