更新XQUERY中节点的所有属性



我有一个带有属性和子节点的节点。

<node attr1="value1" attr2="value2"><child1/><child2/></node>

我有一个具有不同属性集的第二个节点:

<node attr1="value1_new" attr3="value3_new"/>

我想用第二个节点的属性替换第一个节点的所有属性,保留子节点。应该删除第二个节点中缺少的属性。期望的结果是:

<node attr1="value1_new" attr3="value3_new"><child1/><child2/></node>

该命令将替换节点的所有内容,从而删除子节点:

let $replacement = <node attr1="value1_new" attr3="value3_new"/>
replace node /node[1] with $replacement

如何更新属性和保留子属性?

使用BaseX支持的各种XQuery更新扩展,我可以使用BaseX 10.4

copy $n1 := <node attr1="value1" attr2="value2"><child1/><child2/></node>,
$n2 := <node attr1="value1_new" attr3="value3_new"/>
modify ( 
delete node $n1/@*,
insert node $n2/@* into $n1
)
return $n1

返回结果

<node attr1="value1_new" attr3="value3_new"><child1/><child2/></node>

最新更新