only for RuBoard |
xsl:choose provides conditional processing, supporting the selection of one choice of several possibilities.
The xsl:choose element can be thought of as analgous to the C# switch statement or the Visual Basic Select Case statement. The xsl:when element is used in conjunction with the xsl:choose element to provide the functionality for each condition.
None.
You can use the xsl:choose element to test if an attribute exists or not. Using the following XML instance document, the image attribute is not specified for NewRiders.com but is available for xmlandasp.net :
<?xml version="1.0" encoding="utf-8" ?> <links> <link name="NewRiders.com" /> <link name="xmlandasp.net" image="images/xmlandasp.gif"/> </links>
The following stylesheet displays images when the image attribute is specified; otherwise , it displays the value of the name attribute:
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:apply-templates select="links/link" /> </xsl:template> <xsl:template match="link"> <xsl:choose> <xsl:when test="@image"> <img> <xsl:attribute name="src"> <xsl:value-of select="@image" /> </xsl:attribute> </img> </xsl:when> <xsl:otherwise> <xsl:value-of select="@name"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:for-each, xsl:if, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements
xsl:otherwise, xsl:when
only for RuBoard |