我正在尝试对 XML 文档进行转换。根据某个元素的值,我的 XML 转换可能会产生两种不同类型的基本元素:
<xsl:template match="/">
<xsl:choose>
<xsl:when test="/databean/data[@id='pkhfeed']/value/text()='200'">
<xsl:call-template name="StructureA">
<xsl:with-param name="structure" select="//databean" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="StructureB">
<xsl:with-param name="structure" select="//databean" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
然后使用自己的命名空间和 schemaLocations 创建 StructureA 或 StructureB:
<StructureA xmlns="http://...">
StructureA 和 B 共享一些公共元素,因此这些元素在一个名为“xmlcommon.xslt”的单独文件中定义,这两个结构都包含来自其中的模板。这个 xmlcommon 文件没有定义默认命名空间,因为我希望它可以从 StructureA 或 StructureB 中定义的命名空间中使用。但是当我运行我的转换时,从公共文件中提取的任何模板都会导致空白 xmlns 属性:
<StructureA xmlns="http://...">
<SharedElement xmlns="">Something</SharedElement>
</StructureA>
验证时,然后使用空白命名空间而不是正确的父命名空间。 有谁知道如何阻止我的通用文件中的模板添加那些空白的 xmlns 属性?
这是来自公共文件的片段:
<xsl:stylesheet version="1.0" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="ControlledListStructure">
<xsl:param name="xmlElem" />
<xsl:param name="structure" />
<xsl:element name="{$xmlElem}">
<!-- Blah blah blah -->
</xsl:element>
</xsl:template>
</xsl:stylesheet>