我正在尝试重命名父xml标记。我在stackoverflow中查找它,我看到以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Response_123">
<Response>
<xsl:apply-templates select="@*|node()"/>
</Response>
</xsl:template>
</xsl:stylesheet>
遗憾的是,该代码不符合我的要求。在下面的示例中,标记与命名空间相关联。
<ns1:Response_123 xmlns:ns1="AAA">
<System>Alpha</System>
</ns1:Response_123>
当我使用上面的代码时,我仍然得到相同的消息(没有任何区别)。如何将输出更改为:
<ns1:Response xmlns:ns1="AAA">
<System>Alpha</System>
</ns1:Response>
我也尝试在代码中添加命名空间,它也不起作用。
<xsl:template match="Response_123" namespace="AAA">
<Response namespace="AAA">
<xsl:apply-templates select="@*|node()"/>
</Response>
</xsl:template>
感谢大家!
在XSLT中添加命名空间,并使用命名空间调用模板
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="AAA"
version="1.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ns1:Response_123">
<Response>
<xsl:apply-templates select="@*|node()"/>
</Response>
</xsl:template>
</xsl:stylesheet>