将所有参数从xsl:template转发到另一个

时间:2015-08-10 11:01:27

标签: xslt

是否可以将模板中收到的所有参数转发给另一个而不知道它们?

示例:

<xsl:template match="foo">
    <xsl:apply-templates select="bar">
        <xsl:with-param name="father-id" select="@id"/>
    </xsl:apply-templates>
</xsl:template>

<xsl:template match="*" priority="9">
    <!-- do some things -->
    <xsl:next-match/>
</xsl:template>

<xsl:template match="bar">
    <xsl:param name="father-id"/>
    <!-- do some things with my param -->
</xsl:template>

由于father-id,我的参数xsl:template match="*"丢失了。

那么,有没有办法在<xsl:next-match />步骤转发它但不使用以下代码,因为可能有比这个更多的案例和不同的参数?

<xsl:template match="*" priority="9">
    <xsl:param name="father-id"/>
    <!-- do some things -->
    <xsl:next-match>
        <xsl:with-param name="father-id" select="{father-id}"/>
    </xsl:next-match>
</xsl:template>

提前谢谢。

杰拉德。

1 个答案:

答案 0 :(得分:2)

以这种方式尝试:

<xsl:template match="foo">
    <xsl:apply-templates select="bar">
        <xsl:with-param name="father-id" select="@id" tunnel="yes"/>
    </xsl:apply-templates>
</xsl:template>

<xsl:template match="*" priority="9">
    <!-- do some things -->
    <xsl:next-match/>
</xsl:template>

<xsl:template match="bar">
    <xsl:param name="father-id" tunnel="yes"/>
    <!-- do some things with my param -->
</xsl:template>

XSLT 2.0 - 但xsl:next-match也是如此 http://www.w3.org/TR/xslt20/#tunnel-params

相关问题