如何将所有foo标记重命名为baz,使用如下所示的XQuery?
FLWOR:
declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
declare namespace array = "http://www.w3.org/2005/xpath-functions/array";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
for $x in /root
return rename node $x/root/foo as "baz"样本医生:
<root>
<foo>bar</foo>
</root>我想要的输出:
<root>
<baz>bar</baz>
</root>另见:
http://xqueryfiddle.liberty-development.net/nc4P6y8
以及:
removing an element from xml using saxon xquery
它使用的东西并不完全不同。
发布于 2020-06-18 11:11:57
你应该能用
for $foo in doc('input.xml')//foo
return rename node $foo as "baz"假设您支持XQuery更新(比如在Saxon9或10EE或BaseX中)。
发布于 2020-06-18 08:55:41
假设您的实际文档比所显示的文档更复杂,那么使用XSLT而不是XQuery对一个大文档进行小的更改通常更容易。在XSLT3.0中,这是
<xsl:stylesheet ...>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="foo">
<baz><xsl:apply-templates/></baz>
</xsl:template>
</xsl:stylesheet>或者,如果这是一次性的要求,可以考虑使用Saxon的Gizmo实用程序:
java net.sf.saxon.Gizmo -s:source.xml
/>rename //foo to "baz"
/>save out.xml
/>quithttps://stackoverflow.com/questions/62443842
复制相似问题