如何忽略XQuery输出中的XML元素?
我有一个XML文件。我需要得到文件中的所有元素,除了一个。需要在XQuery中编写它。表达方式是什么 我的文件是doc1.xml,它有:如何忽略XQuery输出中的XML元素?,xml,expression,xquery,Xml,Expression,Xquery,我有一个XML文件。我需要得到文件中的所有元素,除了一个。需要在XQuery中编写它。表达方式是什么 我的文件是doc1.xml,它有: <root> <one>1</one> <two>2</two> <three>3</three> </root> 1. 2. 3. 如果我执行fn:doc(doc1.xml),它将返回所有内容。 我想要所有的信息,除了元素值3。 如何执行此操作?
<root>
<one>1</one>
<two>2</two>
<three>3</three>
</root>
1.
2.
3.
如果我执行fn:doc(doc1.xml),它将返回所有内容。
我想要所有的信息,除了元素值3。
如何执行此操作?通过一个使用typeswitch的函数传递文档,对
three
元素不做任何操作,并复制所有其他内容
declare function local:filter($nodes as node()*)
{
for $node in $nodes
return
typeswitch($node)
case element(three)
return ()
case element()
return
element { name($node) } {
$node/@*,
local:filter($node/node())
}
default
return $node
};
let $doc :=
<root>
<one>1</one>
<two>2</two>
<three>3</three>
</root>
return local:filter($doc)
declare function local:filter($nodes as node()*)
{
对于$node中的$node
返回
类型开关($node)
案例要素(三)
返回()
case元素()
返回
元素{name($node)}{
$node/@*,
本地:筛选器($node/node())
}
违约
返回$node
};
让$doc:=
1.
2.
3.
返回本地:筛选器($doc)
您需要按照中建议的行递归复制树,到达不需要的节点时跳过它(而不是处理它)。