如何在新属性中复制属性值 [英] how to COPY Attribute value in a new attribute
本文介绍了如何在新属性中复制属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在sql中将属性的数据复制到同一列中的新属性
How to copy data of attribute to new attribute in the same column in sql
原始数据
<root>
<child attr='hello'></child>
</root>
结果 1
<root>
<child attr='hello' attr2='hello'></child>
</root>
结果 2(有修改)
<root>
<child attr='hello' attr2='**H**ello **W**orld'></child>
</root>
我只想通过 SQL XML Xquery 做到这一点
推荐答案
我不确定我在第二个结果中是否完全符合您的要求,但我会尝试一下:下面的第一个示例将产生你的结果 #1(我已经把你的原始数据放在 test.xml 中,并假设在你的真实数据中可能会重复 'child' 和 'attr'):
I'm not sure I follow what you're wanting exactly in the second result, but I'll take a stab at it: the first example below would produce your result #1 (I've put your original data in test.xml and assumed in your real data that 'child' and 'attr' might be repeated):
<root>{
for $child in doc('test.xml')/root/*
return
element {name($child)} {
for $attr at $index in $child/@*
return (
attribute {name($attr)} {$attr},
attribute {concat(name($attr), 2)} {$attr}
)
}
}</root>
可以修改它以放入不同的值,例如结果 #2,如下所示:
It could be modified to put a different value in, like in result #2, like the below:
<root>{
for $child in doc('test.xml')/root/*
return
element {name($child)} {
for $attr at $index in $child/@*
return (
attribute {name($attr)} {$attr},
attribute {concat(name($attr), 2)} {
'**H**ello **W**orld'
}
)
}
}</root>
希望有所帮助.
这篇关于如何在新属性中复制属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文