Xquery 用于检查xml文件中是否存在节点的函数

Xquery 用于检查xml文件中是否存在节点的函数,xquery,Xquery,我有一个函数,它接受一个节点,如果该节点是一组节点的一部分,则返回true或false。例如,我有一个xml文档: <person> <name> Joseph </name> <child> Mary </child> <mother> Janet </mother> <father> Fred </father> </per

我有一个函数,它接受一个节点,如果该节点是一组节点的一部分,则返回true或false。例如,我有一个xml文档:

    <person>
     <name> Joseph </name>
     <child> Mary </child>
     <mother> Janet </mother>
     <father> Fred </father>
    </person>

在函数中,表达式
person/(name,father)
没有上下文。更新函数以接受person元素作为变量,并将其用作上下文:
$person/(name,father)

此外,由于该函数使用
for
(name,father)
序列进行迭代,因此该函数将返回多个布尔变量-一个用于
name
,另一个用于
father
。如果将值序列与传入的值进行比较,如果序列中的任何值的计算结果为true,则返回true;如果它们都为false,则返回false,这听起来像是您想要的:

declare function local:findNode(
  $node as element(),
  $person as element(person)
) as xs:boolean
{
  $person/((name, father)=$node)
}; 

let $person :=
<person>
 <name> Joseph </name>
 <child> Mary </child>
 <mother> Janet </mother>
 <father> Fred </father>
</person>
let $node := <name> Rick </name>
return local:findNode($node, $person)
声明函数本地:findNode(
$node作为元素(),
$person作为元素(person)
)as xs:boolean
{
$person/((姓名、父亲)=$node)
}; 
让$person:=
约瑟夫
玛丽
珍妮特
弗莱德
让$node:=Rick
返回本地:findNode($node,$person)
declare function local:findNode(
  $node as element(),
  $person as element(person)
) as xs:boolean
{
  $person/((name, father)=$node)
}; 

let $person :=
<person>
 <name> Joseph </name>
 <child> Mary </child>
 <mother> Janet </mother>
 <father> Fred </father>
</person>
let $node := <name> Rick </name>
return local:findNode($node, $person)