Search

Hey guys, a bit stumped whilst using XSLT. This is basically what I am trying to do...

variable = 0

variable = 1

Later in the document.....

Do something Do something else

Is this possible? If so - can you please advise the correct syntax to use.

Thanks very much in advance

Apologies - the example above was meant to be....

variable = 0

if something = something variable = 1 end if

if variable = 1 do something else do something else end if

You could do it like this:

<xsl:variable name="my-variable">
    <xsl:choose>
        <xsl:when test="/data/foo = 'bar'">1</xsl:when>
        <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose>
</xsl:variable>

Thanks for your help - would this be the same if there was a while statement around the choose one?

There is no while statement in XSLT. :-)

The only loop structure in XSLT is for-each, and it is not possible to declare a variable within such a loop.

In XSLT a 'variable' within a template can have a different value each time the template is called. It is not possible to change the value of a so-called variable once it has been set.

If you declare variable = 0 to create the variable within a scope, this is not working. Parameters are the global variables and cannot be changed by xsl. You can loop through entries, compare a value with a parameter and conditionally generate the template needed.

Play with URL or datasource parameters

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details