2013-02-13 157 views
0

我想選擇所有b,其中c2attr > 5c2 = text2。在XPath中,我寫道:XPath,如何選擇必須滿足子1的兩個屬性的父節點?

a/b[c2 = text2 and c2attr >5] 

但是,它並沒有給我的條件,既滿足時c2=text2c2attr >5。 它給了我每個c2元素,它有c2attr >5。我應該怎樣寫才能正確選擇
b?

例如:

<a> 
    <b> 
     <c1>c1 text</c1> 
     <c2 c2attr="3">text1</c2> 
     <c2 c2attr="8">tex2</c2> 
     <c2 c2attr="50">text3</c2> 
    </b> 
    <b> 
     <c1>c1 text</b1> 
     <c2 c2attr="1">text4</c2> 
     <c2 c2attr="6">tex2</c2> 
     <c2 c2attr="10">text1</c2> 
    </b> 
</a> 

非常感謝您!

回答

0

您需要更改c2 = text2c2 = 'text2'因爲你比較字符串,並添加屬性符@c2attr像這樣:

a/b[c2[text() = 'tex2' and @c2attr > 5]] 

另外,你的XML是無效的,不知道錯字,但你有一個<c1>節點關閉<b1>,它也不包含帶有「text2」的文本,它缺少最後的't'。

相關問題