【发布时间】:2011-10-31 19:45:29
【问题描述】:
我有一堆 xsl 文件。我想集中控制结果文档的缩进。我现在在每个 xsl 文件中使用下面的代码。我在每个文件中都有一个 xsl:template name="data" 模板,但是这个模板的内容是不同的。是否可以将 xsl:template match="/" 的内容正确移出到单独的 xsl 文件中并将其导入每个 xsl 文件中。我试过但没有效果。有人可以告诉我一个工作代码吗?
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output name="indent" method="html" indent="yes" omit-xml-declaration="yes"/>
<xsl:output name="no_indent" method="html" indent="no" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:variable name="indent" select="//page/view-data/html-indent"/>
<xsl:if test="$indent='yes'">
<xsl:result-document format="indent" >
<xsl:call-template name="data"/>
</xsl:result-document>
</xsl:if>
<xsl:if test="$indent='no'">
<xsl:result-document format="no_indent" >
<xsl:call-template name="data"/>
</xsl:result-document>
</xsl:if>
</xsl:template>
<xsl:template name="data">
<!-- The content is different from file to file -->
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
-
您也可以尝试 xsl:include 指令 - 在这种情况下,模板将具有与主文档相同的优先级
-
没关系,我都试过了:xsl:include 和 xsl:import。没有效果。
标签: xslt doctype xslt-2.0 saxon indentation