基于前一个子条件的兄弟节点的XPATH

时间:2018-01-05 11:12:29

标签: xml xpath

我有跟随xml,想要获取" cc"值#34;类型" ID所在的"类型"学生存在。我希望XPATH得到值345。

我试过这个但没有得到任何价值.//a / cc [type =" bond"] / following-sibling::cc [type =" id"] /值/文本()

<?xml version="1.0" encoding="UTF-8"?>

<root> 
  <a> 
    <bb>abc</bb>  
    <cc> 
      <type>id</type>  
      <value>345</value> 
    </cc>  
    <cc> 
      <type>student</type>  
      <value>567</value> 
    </cc>  
    <dd>ddd</dd> 
  </a>  
  <a> 
    <bb>zz</bb>  
    <cc> 
      <type>id</type>  
      <value>999</value> 
    </cc>  
    <cc> 
      <type>employee</type>  
      <value>890</value> 
    </cc>  
    <dd>2</dd> 
  </a> 
</root>

2 个答案:

答案 0 :(得分:1)

following-sibling改为preceding-siblingbond改为student)。

//a/cc[type="student"]/preceding-sibling::cc[type="id"]/value/text()

(经xsh测试)。

答案 1 :(得分:0)

试试这个:

    C32
    C55
    C14
    C10
    C20
    C10
    2(O4 *149(H2
    C14
    C5 C7 C6 C8 C11

(在https://codebeautify.org/Xpath-Tester中测试)