Incrementing a variable in XSL

163 Views Asked by At

I have the following variable quarter defined and I want to increment it's current value by one in my XSL sheet if it's value does not equal 4.

I have the following code:

  <xsl:if test="not($quarter=4)">
      </xsl:text><xsl:value-of select="$quarter+1" />
  </xsl:if>

But this does not work - does anyone have an idea of how I can add 1 to my $quarter variable?

2

There are 2 best solutions below

0
Ruprecht von Waldenfels On

This cannot work due to the /xsl:text tag. Does the if statement really work? Try by outputing the variable with xsl:message. Aside from that, check that the variable actually stores a number, and, if it does, try explicitely casting the variable contents as a number using an xpath function.

2
Adriano Repetti On

Syntax is correct (assuming $quarter is a valid XSL number variable, in case you may use number($quarter)+1). What's wrong is <xsl:text> node, you do not have a valid XML file:

<xsl:if test="not($quarter=4)">
    </xsl:text><xsl:value-of select="$quarter+1" />
</xsl:if>

Should be changed to:

<xsl:if test="not($quarter=4)">
    <xsl:value-of select="$quarter+1" />
</xsl:if>

Note that a) you used closing tag </xsl:text> instead of opening one and b) as noted by Micheal <xsl:text> can contain only text, no child elements.