Next / Previous / Contents / Shipman's homepage

10.3. xsl:choose: The multiple-case construct

To produce output with two or more different cases, use the xsl:choose construct. It has one xsl:when element for each case, plus an optional xsl:otherwise element at the end for the “none of the above” case. Each xsl:when element has a test attribute whose value is an XPath expression; the first one that evaluates to a true value is processed.

Here's an example that outputs the content of the turtlechildren of the current node, and puts the first one in parentheses and the last one in square brackets.

    <xsl:for-each select="turtle">
        <xsl:when test="position() = 1">
          <xsl:apply-templates select="."/>
        <xsl:when test="position() = count()">
          <xsl:apply-templates select="."/>
          <xsl:apply-templates select="."/>