O'Reilly logo

Special Edition Using XSLT by Michael Floyd

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Conditional Processing

XSLT provides two methods for processing based on a set of conditions. Those methods involve the following two elements:

  • <xsl:if>

  • <xsl:choose>

The <xsl:if> element operates like the if ... then construct typically found in programming and scripting languages. You specify the condition for the if statement using the test attribute. The condition results in a Boolean expression that returns either True or False. If the condition is True, the processing is carried out. For example:

<xsl:template match=”product/price”> 
  <xsl:if test=”number()”> 
      $ 
   </xsl:if> 
  <xsl:value-of /> 
</xsl:template> 

To see how this might work in a database application, consider the XML document in Listing 4.8, which represents the results of a database ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required