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

Unable to Successfully Pass Parameters to xsl:call-template

我设计了一个通用模板,其中包含 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>

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

<?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,所以我不确定这是否是一个已知的缺点。

定义带参数的 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.