xml - XSLT Return variable from Template -
so have been given fix , have limited knowledge of xslt. want retain variable template run.
<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>
the above template want return variable "$total" from. below template template call above template from.
<xsl:template match="randomtemplate"> <xsl:call-template name="repeatable" \> </xsl:template>
so essentially, want "total" variable returned me or in way accessible randomtemplate.
cheers
this may not actually need, can change repeatable
template output value when total reached, so:
<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>
then, can wrap xsl:call-template
in xsl:variable
capture value, output it
<xsl:variable name="result"> <xsl:call-template name="repeatable" /> </xsl:variable> <xsl:value-of select="$result" />
this output 10
in case.
Comments
Post a Comment