无法成功将参数传递给xsl:call-template

时间:2016-01-15 20:11:02

标签: xslt-1.0 xsl-fo apache-fop

我有一个通用模板,我设计了2个参数titlecategory

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:fo="http://www.w3.org/1999/XSL/Format">

    <xsl:param name="category" />
    <xsl:param name="title" />
    <xsl:template name="test-group">
        <fo:block>
            <xsl:value=of select="$title" />
        </fo:block>
        <fo:block>
            <xsl:value-of select="$category" />
        </fo:block>
    </xsl:template>
</xsl:stylesheet>

在父模板中,我有以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:include href="templates/generic_template.xsl" />
    ...
    <xsl:call-template name="test-group">
        <xsl:with-param name="category" select="'animals'" />
        <xsl:with-param name="title" select="'DOGS'" />
    </xsl:call-template>
    ...
</xsl:stylesheet>

但是,当转换完成标题和类别为空时。我使用的是FOP 2.0,所以我不确定这是否是一个众所周知的缺点。

1 个答案:

答案 0 :(得分:1)

定义带参数的xsl:template时,xsl:template中使用的参数名称应使用嵌套在其中的xls:param元素声明。

<xsl:template name="test-group">
  <xsl:param name="category" />
  <xsl:param name="title" />
  ...
</xsl:template>

附加到xsl:template而不是xsl:stylesheet的参数。 这类似于使用xsl:call-template调用模板时,除非您使用xsl:with-param指定值。

相关问题