这是一个简单的案例。
这是我的 XML:
<?xml version="1.0" encoding="utf-8" ?>
<dogs>
<dog type="Labrador">
<Name>Doggy</Name>
</dog>
<dog type="Batard">
<Name>Unknown</Name>
</dog>
</dogs>
此 XML 与两个 Xslt 一起使用。这是常见的:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="text"/>
<xsl:template match="dogs">
<xsl:text>First template </xsl:text>
<xsl:apply-templates select="." mode="othertemplate" />
</xsl:template>
</xsl:stylesheet>
这是孩子一号:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:include href="transform.xslt"/>
<xsl:template match="dogs" mode="othertemplate">
<xsl:text>		Other template</xsl:text>
</xsl:template>
</xsl:stylesheet>
孩子包括共同的(称为transform.xslt)。
当我执行孩子时,我得到了预期的结果:
First template
Other template
当我执行常见的,我得到这个奇怪的结果:
First template
Doggy
Unknown
常见的应用模式为“othertemplate”的模板。有时,此模式仅包含在子 xslt 中。
我想要那个,如果没有模式为“othertemplate”的模板,那么什么都不应该输出。
我不想为所有不必使用此模板模式的 xslt 文件包含模式为“othertemplate”且正文为空的模板...
我该怎么办?
谢谢