Xml – How to implement if-else statement in XSLT

if statementxmlxslt

I am trying to implement an if -else statement in XSLT but my code just doesn't parse. Does anyone have any ideas?

  <xsl:variable name="CreatedDate" select="@createDate"/>
  <xsl:variable name="IDAppendedDate" select="2012-01-01" />
  <b>date: <xsl:value-of select="$CreatedDate"/></b> 

  <xsl:if test="$CreatedDate > $IDAppendedDate">
    <h2> mooooooooooooo </h2>
  </xsl:if>
  <xsl:else>
    <h2> dooooooooooooo </h2>
  </xsl:else>

Best Answer

You have to reimplement it using <xsl:choose> tag:

<xsl:choose>
  <xsl:when test="$CreatedDate > $IDAppendedDate">
    <h2> mooooooooooooo </h2>
  </xsl:when>
  <xsl:otherwise>
    <h2> dooooooooooooo </h2>
  </xsl:otherwise>
</xsl:choose>