我正在尝试删除命名空间前缀。我尝试了几个 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/