我有一个大型XML文件的以下根元素:
<Interchange xmlns='http://www.e2b.no/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.e2b.no/XMLSchema Interchange'>
我需要
<Interchange>
请指教。这是一个包含我正在尝试的模板的最小文档(我不会包括我的完整尝试,因为它们更长):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Interchange/@xmlns|@xmlns:xsi|@xsi:schemaLocation"/>
</xsl:stylesheet>
答案 0 :(得分:0)
命名空间声明与属性不同。这就是为什么你不能按照你尝试的方式将它们从你的身份模板中排除。
相反,只需匹配元素并输出另一个没有“负担”的Interchange
上面的命名空间:
<xsl:template match="eb:Interchange">
<Interchange>
<xsl:apply-templates/>
</Interchange>
</xsl:template>
确保在XSLT样式表中定义所需的命名空间:
xmlns:eb='http://www.e2b.no/XMLSchema'
使用哪个前缀(在这种情况下为eb
)无关紧要。但这确保找到Interchange
元素。这一点至关重要,因为<Interchange>
和<Interchange xmlns='http://www.e2b.no/XMLSchema'>
是不同的元素。