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>
An example of if-then-else logic in XSLT 1.0:</xsl:text>
<xsl:text>

 If $x is larger than 10, print 'Big', </xsl:text>
<xsl:text>
 otherwise print 'Little'</xsl:text>
<xsl:text>

 </xsl:text>
<xsl:choose>
<xsl:when test="$x > 10">
<xsl:text>Big</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>Little</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>
</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