3

您好,我需要在我的 XSL 中实现以下功能,但似乎我被卡住了......任何帮助将不胜感激。

请在下面的代码片段中查看我的评论。

<xsl:template name="/">
<xsl:call-template name="looptemplate">
      <xsl:with-param name="x" select="1"/>
      <xsl:with-param name="max" select="10"/>
</xsl:call-template>
</xsl:template>

<xsl:template name=" looptemplate">
<xsl:param name="x"/>
<xsl:param name="max"/>

    <xsl:call-template name="TemplateToCall">
        <xsl:with-param name="nodePath" select="a/b$i"></xsl:with-param>

        <!--
        Get dynamically root nodes
        a/b1, a/b2, a/b3 etc
        -->

    </xsl:call-template>
                  <!--
                Loop again until x reaches max
               -->
</xsl:template>

<xsl:template name="TemplateToCall">
<xsl:param name="nodePath"/>

<xsl:for-each select="$nodePath">
    <xsl:value-of select="value1"/>, <xsl:value-of select="value2"/>
</xsl:for-each>
</xsl:template>
4

1 回答 1

4

您不能将 XPath 构建为字符串并像那样动态评估它(至少在普通的 XSLT 1.0 或 2.0 中不会,在 XSLT 3.0 中会有一条xsl:evaluate指令),但您可以执行类似的操作

<xsl:call-template name="TemplateToCall">
    <xsl:with-param name="nodes" select="a/*[local-name() = concat('b', $i)]"/>

然后在被调用的模板中

<xsl:template name="TemplateToCall">
    <xsl:param name="nodes"/>

    <xsl:for-each select="$nodes">
于 2013-10-11T10:13:43.010 回答