XPath跟随 - 具有多个条件的兄弟

时间:2011-08-01 10:12:45

标签: xpath

我有以下xml文档。我正在尝试选择任何具有相同value2的兄弟姐妹且其中value3未关闭的孩子。

<root>
  <child>
    <value1>Type A</value1>
    <value2>Class 1</value2>
    <value3>Active</value3>
  </child>
  <child>
    <value1>Type B</value1>
    <value2>Class 1</value2>
    <value3>Closed</value3>
  </child>
  <child>
    <value1>Type C</value1>
    <value2>Class 2</value2>
    <value3>Active</value3>
  </child>
  <child>
    <value1>Type D</value1>
    <value2>Class 2</value2>
    <value3>Active</value3>
  </child>
  <child>
    <value1>Type E</value1>
    <value2>Class 3</value2>
    <value3>Active</value3>
  </child>
</root>

我的尝试是:

  

// child [following-sibling :: child / value2 = value2 and value3!='Closed']

但是这没有将多个条件应用于下一个兄弟函数的预期结果。

有什么想法吗?

1 个答案:

答案 0 :(得分:6)

//child[value2 = following-sibling::child[not(value3 = 'Closed')]/value2]

要申请任何兄弟姐妹,请联合following-siblingpreceding-sibling轴。

//child[value2 = (following-sibling::child | preceding-sibling::child)[not(value3 = 'Closed')]/value2]