xsl:when

only for RuBoard

xsl:when

xsl:when provides for multiple condition evaluation.

The xsl:when element is analgous to a case statement in formal programming languages.

Attributes

Attribute Name

Enforced

Description

Values

test

Required

The condition to test. If the expression evaluates to Boolean True, the results are included in the output.

A Boolean expression

select

Optional

The value of the variable. If specified, the content of the xsl:variable element must be empty.

Expression

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:choose 

Child Elements

 xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose,  xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if,  xsl:processing-instruction, xsl:value-of, xsl:variable, output elements 
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