xquery 将属性转换为标签 [英] xquery to convert attributes to tags
本文介绍了xquery 将属性转换为标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习 Xquery.我的 XML 文档中有这个标签.
I am learning on Xquery. I have this tag in my XML document.
<element a="1" b="2" c="3" name="testgroupID">198</element>
<element a="11" b="12" c="13" name="testgroupverifyID" binary="hidden"/>
我可以知道如何使用 xquery 创建如下内容吗?
May I know how to create something like the following with xquery?
<mytags>
<a>1</a>
<b>2</b>
<c>3</c>
<name>testgroupID</name>
<value>198</value>
</mytags>
<mytags>
<a>11</a>
<b>12</b>
<c>13</c>
<name>testgroupverifyID</name>
<binary>hidden</binary>
</mytags>
目前我只能使用静态方式来做到这一点,例如:
Currently I could only use the static way to do it, like:
$tag := $x/@a然后用 {$tag
$tag := $x/@a and then return it with {$tag
请多多指教.非常感谢.
Kindly advise. Thank you very much.
推荐答案
这个 XQuery:
for $elem in /root/element
return element mytags {
for $child in $elem/(@*|text())
return element {if ($child instance of attribute())
then name($child)
else 'value'} {
string($child)
}
}
输出:
<mytags>
<a>1</a>
<b>2</b>
<c>3</c>
<name>testgroupID</name>
<value>198</value>
</mytags>
<mytags>
<a>11</a>
<b>12</b>
<c>13</c>
<name>testgroupverifyID</name>
<binary>hidden</binary>
</mytags>
这篇关于xquery 将属性转换为标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文