<xslTutorial creator="nicmila@idoox.com">
<index keywords='xsl:variable xsl:if boolean()'/>
<description>Boolean function is very useful, if you want to check, if a variable has some defined value. Compare <stylesheet id='id2'/> and <stylesheet id='id3'/>
</description>
<xmlSource id="id1">
<animal>cat</animal>
<animal>dog</animal>
<animal>cow</animal>
</xmlSource>
<attValues>
<value match="">
</value>
</attValues>
<xslStylesheet id="id2">
<xsl:variable name="color">red</xsl:variable>
<xsl:template match="//animal">
<xsl:choose>
<xsl:when test='boolean($color)'>
<P style="color:{$color}">
<xsl:value-of select="."/></P>
</xsl:when>
<xsl:otherwise>
<P><xsl:value-of select="."/></P>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xslStylesheet>
<xslStylesheet id="id3">
<xsl:variable name="color"></xsl:variable>
<xsl:template match="//animal">
<xsl:choose>
<xsl:when test='boolean($color)'>
<P style="color:{$color}">
<xsl:value-of select="."/></P>
</xsl:when>
<xsl:otherwise>
<P><xsl:value-of select="."/></P>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xslStylesheet>
</xslTutorial>