删除空的xmlns属性
这是我的输入xml删除空的xmlns属性,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,这是我的输入xml 这是我的xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:apply-templates select="//b" /> </xsl:template> &
这是我的xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:apply-templates select="//b" />
</xsl:template>
<xsl:template match="b">
<xsl:choose>
<xsl:when test=".='This is a text'">
<e xmlns="www.example.com">
<f>yes</f>
<g>
<xsl:call-template name="atemp"/>
</g>
</e>
</xsl:when>
<xsl:otherwise>
<d>NO</d>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="atemp">
<l>l</l>
<m>m</m>
<n>n</n>
</xsl:template>
</xsl:stylesheet>
我该怎么办 变化
<xsl:template name="atemp">
<l>l</l>
<m>m</m>
<n>n</n>
</xsl:template>
或者,一路分解到
xsl:stylesheet
:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns="www.example.com">
您也可以将其添加到xsl:template
中,以避免重复<代码>感谢您提供的解决方案。这适用于我上面的示例。但我的实际xslt文件包含许多嵌套的调用模板
语句,如本例-。每次我调用模板时,它都会添加那些xmlns=”“
。是否有其他解决方案,我不必在其中多次编辑文件。此外,即使我们有完全相同的项目副本,xmlns=”“
也没有出现在我的同事的输出文件中。知道为什么会发生这种情况吗。@AmitSingh:如果愿意,您可以将xmlns=“www.example.com”全局添加到xsl:stylesheet
元素中。同事得到不同的结果:我们必须查看一个示例,并提供更多详细信息以提供解释。
<xsl:template name="atemp">
<l>l</l>
<m>m</m>
<n>n</n>
</xsl:template>
<xsl:template name="atemp">
<l xmlns="www.example.com">l</l>
<m xmlns="www.example.com">m</m>
<n xmlns="www.example.com">n</n>
</xsl:template>
<xsl:template name="atemp" xmlns="www.example.com">
<l>l</l>
<m>m</m>
<n>n</n>
</xsl:template>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns="www.example.com">