Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何使用Xpath 1.0比较多个属性对?_Xml_Xpath - Fatal编程技术网

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

Xml 如何使用Xpath 1.0比较多个属性对?,xml,xpath,Xml,Xpath,目标是只选择那些 具有具有子节点的同级节点,该子节点的属性值与需要选择的节点的属性值匹配 //*[(@attribute1 = ./following-sibling::*/@attribute2) or (@attribute1 = ./preceding-sibling::*/@attribute2)] --- sibling node with another attribute 具有具有属性值与需要选择的节点的另一个属性值匹配

目标是只选择那些

  • 具有具有子节点的同级节点,该子节点的属性值与需要选择的节点的属性值匹配

  • //*[(@attribute1 = ./following-sibling::*/@attribute2)
        or 
        (@attribute1 = ./preceding-sibling::*/@attribute2)]
                         --- sibling node with another attribute
    
  • 具有具有属性值与需要选择的节点的另一个属性值匹配的同级节点

  • //*[(@attribute1 = ./following-sibling::*/@attribute2)
        or 
        (@attribute1 = ./preceding-sibling::*/@attribute2)]
                         --- sibling node with another attribute
    
    我可以理解为什么像下面这样的Xpath表达式不会选择我要查找的节点集:

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

    是否可以选择我要查找的节点集?如果可以,如何选择?

    这些是否适用于您

    具有同级节点和具有属性的子节点的节点 与需要选择的节点的属性值匹配的值:

    //*[(@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