xsl:choose

only for RuBoard

xsl:choose

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.

Attributes

None.

Example

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> 

Parent Elements

 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 

Child Elements

 xsl:otherwise, xsl:when 
only for RuBoard


XML and ASP. NET
XML and ASP.NET
ISBN: B000H2MXOM
EAN: N/A
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net