xsl:choose

Selects one template to instantiate from a group of templates.

Format

<xsl:choose>
               
  <xsl:when test="expression1">
               
    template_body 
               
  </xsl:when>
               
  [<xsl:when test="expression2">
               
    template_body 
               
  </xsl:when>] ...
               
  [<xsl:otherwise>
               
   template_body  
               
  </xsl:otherwise>]
               
</xsl:choose>
               

            

Description

An xsl:choose element contains one or more xsl:when elements followed by zero or one xsl:otherwise element. Each xsl:when element contains a required test attribute, whose value is an expression. Each xsl:when and xsl:otherwise element contains a template.

When the XSLT processor processes an xsl:choose element, it starts by evaluating the expression in the first xsl:when element. The XSLT processor converts the result to a Boolean value. If the result is true, the XSLT processor instantiates the template contained by that xsl:when element. If the result is false, the XSLT processor evaluates the expression in the next xsl:when element.

The XSLT processor instantiates the template of only the first xsl:when element whose test expression evaluates to true. If no expressions evaluate to true and there is an xsl:otherwise element, the XSLT processor instantiates the template in the xsl:otherwise element.

If no expressions in xsl:when elements are true and there is no xsl:otherwise element, the xsl:choose element has no effect.

Tip

 

You can create an xsl:choose element automatically using the XSLT mapper.

Canonicalize XML

Stylus Studio® features a handy XML canonicalizer among its many XML editing utilities, for quickly and easily converting any XML document into its canonical form (c14n), a widely-used W3C standard for normalizing XML files.

XSLT Mapper

Simplify XSLT mapping with the Stylus Studio XSLT Mapper - supports multiple data sources, round-trip engineering (synchronized editing views), XSLT function blocks, integrated XSLT preview and more.

EDIFACT Sample Converted to XML

A sample EDIFACT document before and after conversion to XML, showing markup and full automatically-generated internal documentation.

XML Schema Editor

Stylus Studio's XML Schema Editor lets you easily develop advanced data models expressed in W3C XML Schema. Its synchronized split-pane interface shows both a visual XML Schema Diagram and the underlying code, and you can edit in either one.

Stylus Most Wanted

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.