xsl:choose ... xsl:when ... xsl:otherwise

  • Conditionally process a part of the template, allowing alternatives.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template name="test">
        <xsl:choose>
          <xsl:when test="@test='1'">
            ...
          </xsl:when>
          <xsl:when test="@test='2'">
            ...
          </xsl:when>
          <xsl:otherwise>
            ...
          </xsl:otherwise>
        </choose>
      </xsl:template>
    </xsl:stylesheet>
    					
  • The test attribute value always expects a boolean result, the value is converted to a boolean as if by a call to the XPath boolean function.

Note

It is not allowed to have any content in the xsl:choose element.