An example of if-then-else logic in XSLT 1.0 : if « XSLT stylesheet « XML






An example of if-then-else logic in XSLT 1.0





File: Transform.xslt

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:param name="x" select="'10'"/>

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:text>&#xA;An example of if-then-else logic in XSLT 1.0:</xsl:text>
    <xsl:text>&#xA;&#xA;  If $x is larger than 10, print 'Big', </xsl:text>
    <xsl:text>&#xA;    otherwise print 'Little'</xsl:text>
    <xsl:text>&#xA;&#xA;           </xsl:text>
    <xsl:choose>
      <xsl:when test="$x &gt; 10">
        <xsl:text>Big</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>Little</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>&#xA;</xsl:text>
  </xsl:template>

</xsl:stylesheet>

Output:


An example of if-then-else logic in XSLT 1.0:

  If $x is larger than 10, print 'Big', 
    otherwise print 'Little'

           Little

 








Related examples in the same category

1.Compare value of attribute with if statement
2.if statement with and operator
3.if statement in for-each loop
4.Use boolean operator in if statement
5.if statement and value compare
6.Branching