gpt4 book ai didi

xml - 给元素添加命名空间

转载 作者:数据小太阳 更新时间:2023-10-29 01:42:15 25 4
gpt4 key购买 nike

我有一个包含未命名空间元素的 XML 文档,我想使用 XSLT 为它们添加命名空间。大多数元素将在 namespace A 中;一些将在命名空间 B 中。我该怎么做?

最佳答案

使用 foo.xml

<foo x="1">
<bar y="2">
<baz z="3"/>
</bar>
<a-special-element n="8"/>
</foo>

和 foo.xsl

    <xsl:template match="*">
<xsl:element name="{local-name()}" namespace="A" >
<xsl:copy-of select="attribute::*"/>
<xsl:apply-templates />
</xsl:element>
</xsl:template>

<xsl:template match="a-special-element">
<B:a-special-element xmlns:B="B">
<xsl:apply-templates match="children()"/>
</B:a-special-element>
</xsl:template>

</xsl:transform>

我明白了

<foo xmlns="A" x="1">
<bar y="2">
<baz z="3"/>
</bar>
<B:a-special-element xmlns:B="B"/>
</foo>

这就是您要找的吗?

关于xml - 给元素添加命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/144713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com