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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/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
XPath:返回具有特定属性的第一次见面的子对象_Xpath_Return_Parent Child_Attr - Fatal编程技术网

XPath:返回具有特定属性的第一次见面的子对象

XPath:返回具有特定属性的第一次见面的子对象,xpath,return,parent-child,attr,Xpath,Return,Parent Child,Attr,具有以下层次结构: Parent1 --> child1(@name = 'abc') --> child2(@name = 'xyz') --> child3(@name = 'qqq') Parent2 --> child1 --> child2(@name = 'yui') XPath返回所需的以下节点: child1来自父母1 和 child2来自父母2 规则如下: return第一次出现仅子具有特定属性的,在本例

具有以下层次结构:

Parent1
    --> child1(@name = 'abc')
    --> child2(@name = 'xyz')
    --> child3(@name = 'qqq')

Parent2
    --> child1
    --> child2(@name = 'yui')
XPath返回所需的以下节点:

child1来自父母1


child2来自父母2

规则如下:
return第一次出现仅子具有特定属性的,在本例中为
@name

注意:
first()

/root/node()/node()[@name][position()=1]
使用此XML:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <parent1>
    <child1 name="abc"></child1>
    <child2 name="xyz"></child2>
    <child3 name="qqq"></child3>
  </parent1>
  <parent2>
    <child1></child1>
    <child2 name="yui"></child2>
  </parent2>
</root>

返回:

Element='<child1 name="abc" />'
Element='<child2 name="yui" />'
Element=''
元素=“”

感谢您的提示,不幸的是,对于JCR XPath,此函数尚未实现,无论如何,这在其他上下文中是可行的