最好由一個簡化的例子中所示的一些具體節點:XPATH:選擇給定名稱的節點被緊接
<?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>
,但不一定是緊隨之一。
+1爲好問題。 – 2011-06-16 13:05:09