0

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?

MattTheHack
  • 1,354
  • 7
  • 28
  • 48
  • 2
    [Reassign xsl variable value](http://stackoverflow.com/questions/19255139/reassign-xsl-variable-value) – har07 Jun 16 '15 at 15:00

2 Answers2

0

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.

0

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.

Adriano Repetti
  • 65,416
  • 20
  • 137
  • 208
  • It should also be noted that the value of `$quarter` is not actually being changed. (The variable is not actually incremented.) It's only the results of `$quarter + 1` that are being output. – Daniel Haley Jun 16 '15 at 23:04
  • @AdrianoRepetti - The xsl:text element cannot have another element inside, it can only contain text. – Michael Kay Jun 17 '15 at 20:36