首页 > 解决方案 > 如何在 XSLT1.0 的中间位置使用 xsl:template?

问题描述

我在我的 XSLT1.0 中的模板的上部使用它来从 xml 获取不同的数据值。

完整代码:- https://www.dropbox.com/s/6jollabe8tbbd7j/code.xslt?dl=0 在以下位置使用此块:- 第 745 行

而且我必须在我的 xslt 中间使用这个块,但是如何做到这一点。如果我使用它,我会遇到异常,因为样式表中的这个位置不允许使用 xsl:template!如何解决任何建议表示赞赏

<xsl:template match="COMBINED-PAYMENT-HISTORY">
    <xsl:variable name="items-rtf">
        <xsl:call-template name="tokenize">
            <xsl:with-param name="text" select="normalize-space(.)"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="items" select="exsl:node-set($items-rtf)/item" /> 
<table>
    <!-- month -->
    <tr>
        <xsl:for-each select="$items">
            <td>
                <xsl:value-of select="substring-before(., ':')" />
            </td>
        </xsl:for-each>
    </tr>
    <!-- year -->
    <tr>
        <xsl:for-each select="$items">

            <td>
                <xsl:value-of select="substring-before(substring-after(., ':'), ',')" />
            </td>
        </xsl:for-each>
    </tr>
    <!-- data -->
    <tr>
        <xsl:for-each select="$items">
            <td>
                <xsl:value-of select="substring-after(., ',')" />
            </td>
        </xsl:for-each>
    </tr>
</table>
</xsl:template>

<xsl:template name="tokenize">
    <xsl:param name="text" />
    <xsl:param name="delimiter" select="'|'" />
    <xsl:variable name="token" select="substring-before($text, $delimiter)" />
    <item>
        <xsl:value-of select="$token" />
    </item>
    <xsl:variable name="next" select="substring-after($text, $delimiter)" />
    <xsl:if test="$next">
        <!-- recursive call -->
        <xsl:call-template name="tokenize">
            <xsl:with-param name="text" select="$next" />
        </xsl:call-template>
    </xsl:if> 
</xsl:template>

</xsl:stylesheet>

标签: htmlxmlxsltxhtml

解决方案


推荐阅读