xml - 如何在不删除 xmlns 标记的情况下删除 xml 中的命名空间前缀?

标签 xml xslt namespaces

我正在尝试删除命名空间前缀。我尝试了几个 XSLT,但它们似乎不起作用(将在示例后说明原因)。

当前 xml 输出示例:

<s:Body     xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<ns:GetPriceSet     xmlns:ns="http://abc.org/01/02">
<ns:og>
    <TestElement1   xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    <TestElement2   xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</ns:og>
</ns:GetPriceSet>
</s:Body>

我想要的是:
<s:Body     xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<GetPriceSet    xmlns="http://abc.org/01/02">
<og>
    <TestElement1   xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    <TestElement2   xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</og>
</GetPriceSet>
</s:Body>

我尝试从这里使用两个 XSLT:How to remove namespace prefix leaving namespace value (XSLT)?

问题是 ns: 被 ns0 和 ns1 代替,而不是被 XSLT 完全删除。所以我认为 XSLT 需要进一步修改。

最佳答案

根据您分享的示例,这似乎应该有效?

<xsl:template match="ns:*">
        <xsl:element name="{local-name()}" >
            <xsl:apply-templates select="@*|node()"/>
        </xsl:element>
    </xsl:template>

关于xml - 如何在不删除 xmlns 标记的情况下删除 xml 中的命名空间前缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22309054/

相关文章:

xml - 向嵌套元素添加命名空间

c# - XDocument 在生成最终 xml 字符串时添加回车符

html - 我们可以在 XSLT 中使用从数据库表中获取的值吗?

php - Codeigniter 自定义库和命名空间

c# - XmlDocument.SelectSingleNode 为根节点返回 null

xml - 使用 XSLT 根据节点数转换带有条件的 XML

XSLT 选择唯一节点

html - 如何使用 "xsl:attribute"设置显示图像的 src-URL?

php - 在动态类名的开头添加反斜杠

.net - 你如何组织你的命名空间?