xsl:if and xsl:choose

The xsl:if instruction cannot express an else condition. It has a single input port, and a single output port, as shown in Figure 244.

Figure 244. xsl:if Instruction Block

Once fully defined, the xsl:if block generates code like the following:

<Review>
               
	<xsl:if test="authors/author= 'Minollo'">
               
		<xsl:value-of select="'Recommended'"/>
               
	</xsl:if>
               
	<xsl:if test="contains(authors/author,'Pedruzzi')">
               
		<xsl:value-of select="'A best buy'"/>
               
	</xsl:if>
               
</Review>
               

            

If you need to express an else condition, use the xsl:choose instruction block. This instruction block has two output ports by default, one for the xsl:when test= attribute, and one for the one xsl:otherwise element.

Figure 245. xsl:choose Instruction Block

The xsl:choose instruction block generates code like the following:

<Review>
               
	<xsl:choose>
               
		<xsl:when test="authors/author= 'Minollo'">
               
			<xsl:value-of select="'Recommended'"/>
               
		</xsl:when>
               
		<xsl:when test="contains(authors/author,'Pedruzzi')">
               
			<xsl:value-of select="'authors best buy'"/>
               
		</xsl:when>
               
		<xsl:otherwise>
               
			<xsl:value-of select="'bah...'"/>
               
		</xsl:otherwise>
               
	</xsl:choose>
               
</Review>
               

            

If you need to define more than one xsl:when test= attribute, use the xsl:choose shortcut menu (right click) and select Add When Port.

Note

 

Stylus Studio generates the xsl:otherwise element by default for all xsl:choose instructions.

 
Free Stylus Studio XML Training: