Conditional processing

Conditional processing in xslt is a not unlike conditional processing in other well-known programming languages, although its wrapped in the xml-syntax which we all love.

If statements

Simle if-statements are done using the <xsl:if> tags

Example:

<xsl:if select="$mystring != ''>
    ...
</xsl:if>

 There is no else-statements, so in case you need that, consider the choose/when construct.

 

Choose/when statements

In case you want to case out using multiple conditions, you need the choose/when construct.

Example:

<xsl:choose>
  <xsl:when test="$mystring = ''">
    ... 
  </xsl:when>
  <xsl:when test="$mystring = 'foo'">
    ... 
  </xsl:when>
  <xsl:otherwise>
    ... 
  </xsl:otherwise>
</xsl:choose>