2014-12-02 62 views
1

所以我给了一些东西来解决,并且我对XSLT的了解有限。我基本上想从我运行的模板中保留一个变量。模板中的XSLT返回变量

<xsl:template name="repeatable"> 
    <xsl:param name="index" select="1" /> 
    <xsl:param name="total" select="10" /> 

    <xsl:if test="not($index = $total)"> 
     <xsl:call-template name="repeatable"> 
      <xsl:with-param name="index" select="$index + 1" /> 
     </xsl:call-template> 
    </xsl:if> 
    </xsl:template> 

以上是我想从中返回变量“$ total”的模板。下面的模板是我称之为上述模板的模板。

<xsl:template match="randomtemplate"> 
    <xsl:call-template name="repeatable" \> 
</xsl:template> 

所以基本上,我只想让“总”变量返回给我或以某种方式从randomtemplate访问。

干杯

+0

恐怕这没有任何意义。 $ total参数的值是10.它被硬编码到样式表中,并且它不会改变,除非* you *改变它。 – 2014-12-02 05:23:39

回答

1

这实际上可能不是你真正需要的,但你可以做的是改变repeatable模板简单地输出值达到总时,就像这样:

<xsl:template name="repeatable"> 
    <xsl:param name="index" select="1" /> 
    <xsl:param name="total" select="10" /> 

    <xsl:choose> 
     <xsl:when test="not($index = $total)"> 
     <xsl:call-template name="repeatable"> 
      <xsl:with-param name="index" select="$index + 1" /> 
     </xsl:call-template> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:value-of select="$index" /> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:template> 

然后,您可以在xsl:variable包裹xsl:call-template捕捉到该值,然后将它输出

<xsl:variable name="result"> 
    <xsl:call-template name="repeatable" /> 
</xsl:variable> 
<xsl:value-of select="$result" /> 

竟被这在这种情况下输出10

+0

“*在这种情况下,会输出”10“。*”是否有输出其他内容的情况? – 2014-12-02 14:11:11