1

Topic: How "variable" in XSLT to make really variable?

In XSLT-transformation the line is printed thus:

<tr>
<xsl:choose>
<xsl:when test = "$ cnt = 0">
<xsl:call-template name = "printTotal">
<xsl:with-param name = "bc" select = "1"/>
</xsl:call-template>
</xsl:when>
<xsl:when test = "$ cnt> 0">
<xsl:call-template name = "printTotal">
<xsl:with-param name = "bc" select = "2"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name = "printTotal">
<xsl:with-param name = "bc" select = "3"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</tr>

In this code the variable $cnt is checked and depending on its value the template "printTotal" in which parameter certain value is transferred is caused.
That each time not to repeat an identical call of a template it would be desirable to get a variable then to use it in a call of a template which to cause only 1 time, approximately here so:

<tr>
<xsl:variable name = "gr"> <xsl:value-of select = ""/> </xsl:variable>
<xsl:choose>
<xsl:when test = "$ cnt = 0">
<xsl:variable name = "gr"> <xsl:value-of select = "1"/> </xsl:variable>
</xsl:when>
<xsl:when test = "$ cnt> 0">
<xsl:variable name = "gr"> <xsl:value-of select = "2"/> </xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:variable name = "gr"> <xsl:value-of select = "3"/> </xsl:variable>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name = "printTotal">
<xsl:with-param name = "bc" select = "$ gr"/>
</xsl:call-template>
</tr>

But it is impossible so to do, because <xsl:variable name = "gr">... </xsl:variable> -
It is each time new determination of a variable with its initialization.
And how not to set a variable, and simply to change to it value?

2

Re: How "variable" in XSLT to make really variable?

verter wrote:

And how not to set a variable, and simply to change to it value?

In any way

verter wrote:

but it is impossible so to do, because <xsl:variable name = "gr">... </xsl:variable> -
It is each time new determination of a variable with its initialization.

the Output - to define it once
[spoiler]

<tr>
<xsl:variable name = "gr">
<xsl:choose>
<xsl:when test = "$ cnt = 0">
<xsl:value-of select = "1"/>
</xsl:when>
<xsl:when test = "$ cnt> 0">
<xsl:value-of select = "2"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select = "3"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name = "printTotal">
<xsl:with-param name = "bc" select = "$ gr"/>
</xsl:call-template>
</tr>

[/spoiler] Or generally without a variable
[spoiler]

<xsl:call-template name = "printTotal">
<xsl:with-param name = "bc">
<xsl:choose>
<xsl:when test = "$ cnt = 0">
<xsl:value-of select = "1"/>
</xsl:when>
<xsl:when test = "$ cnt> 0">
<xsl:value-of select = "2"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select = "3"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>

[/spoiler]

3

Re: How "variable" in XSLT to make really variable?

_Vasilisk _;
Understood. Thanks!
It turns out that variable actually const

4

Re: How "variable" in XSLT to make really variable?

verter wrote:

it turns out that variable actually const

so. As well as xsl:param