如何使用Xpath 1.0比较多个属性对?

时间:2014-01-27 20:56:57

标签: xml xpath

目标是仅选择那些

的节点
  1. 有一个兄弟节点,其子节点的属性值与需要选择的节点的属性值相匹配。

  2. 有一个兄弟节点,其属性值与需要选择的节点的另一个属性值相匹配。

  3. 我可以看到为什么像下面这样的Xpath表达式不会选择我正在寻找的节点集:

    //first/second[@attr1=parent::first/second/third/@attrx][@attr2=parent::first/second[@attry]
    

    是否可以选择我正在寻找的节点集,如果是这样的话?

1 个答案:

答案 0 :(得分:1)

这些适合你吗?

具有带有属性的子节点的兄弟节点的节点 与需要选择的节点的属性值匹配的值:

//*[(@attribute = ./following-sibling::*/*/@attribute)
    or 
    (@attribute = ./preceding-sibling::*/*/@attribute)]
                    --- sibling node --- ------------                 
                                               |
                                   child node with a same attribute

节点有一个兄弟节点,其节点具有匹配的属性值 需要选择的节点的另一个属性值。

//*[(@attribute1 = ./following-sibling::*/@attribute2)
    or 
    (@attribute1 = ./preceding-sibling::*/@attribute2)]
                     --- sibling node with another attribute
相关问题