2013-02-13 54 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'。

相关问题