如何在 XQuery 中创建删除函数
当我尝试创建删除功能时遇到问题。我当前的代码是:
Xquery:
declare variable $d as xs:string;
declare variable $p as xs:string;
let $xp := saxon:evaluate(concat("doc('",$d,"')",$p))
return document {for $n in doc($d)/* return qsx10p8:delete($n, $xp)}
declare function qsx10p8:delete
($n as node(), $xp as node()*)
as node() {
if ($n[self::element()])
then element
{fn:local-name($n)}
{for $c in $n/(*|@*)
return qsx10p8:delete($c, $xp),
if (some $x in $xp satisfies ($n is $x))
then ()
else ($n/text())}
else $n
};
如果输入是: $d = C:/supplier.xml 和 $p= /Suppliers/Supplier/*
结果是:
<Suppliers><Supplier><address /><Phone /></Supplier></Suppliers>
但我希望结果为
。 有没有办法编辑我的功能代码以删除那些必要的标签?
I met a problem when I try to create delete function. My current code is:
Xquery:
declare variable $d as xs:string;
declare variable $p as xs:string;
let $xp := saxon:evaluate(concat("doc('",$d,"')",$p))
return document {for $n in doc($d)/* return qsx10p8:delete($n, $xp)}
declare function qsx10p8:delete
($n as node(), $xp as node()*)
as node() {
if ($n[self::element()])
then element
{fn:local-name($n)}
{for $c in $n/(*|@*)
return qsx10p8:delete($c, $xp),
if (some $x in $xp satisfies ($n is $x))
then ()
else ($n/text())}
else $n
};
If the input are: $d = C:/supplier.xml and $p= /Suppliers/Supplier/*
the result is:
<Suppliers><Supplier><address /><Phone /></Supplier></Suppliers>
But I want the result to be <Suppliers><Supplier></Supplier></Suppliers>
.
Is there any way to edit my function codes to remove those necessary tags as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试以下递归函数作为删除这些所需元素的方法。
You could try the following recursive function as a way of deleting those desired elements.
此 XQuery:
将此
xs:string
作为$pPath
参数:'Supplier/address|Supplier/Phone'
输出:
This XQuery:
With this
xs:string
as$pPath
param:'Supplier/address|Supplier/Phone'
Output: