L'élément <xsl:when> permet de créer une condition dans une structure conditionnelle <xsl:choose>.

<xsl:when test="expression>
   Instructions...
</xsl:when>
Les attributs :
Attribut Description
test="pattern" effectue un test conditionnel sur l'expression pattern spécifiée.

Cet élément ne peut être contenu que par l'instruction <xsl:choose>.

Cet élément peut contenir les instructions suivantes :

Exemple : [voir]
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" 
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" 
               media-type="text/html; charset=ISO-8859-1" version="4.0"/>
  <xsl:template match="/">
  <html>
      <head>
        <title>La logithèque : 
                  <xsl:value-of select="logitheque/categorie[position()=7]/@nom"/>
        </title>
      </head>
      <body>
        <table border="0" width="60%" class="produit">
        <tr>
          <th>Logiciel</th>
          <th>Lien</th>
        </tr>
        <xsl:apply-templates 
                    select="logitheque/categorie[position()=7]/logiciel"/>
        </table>
      </body>
  </html>
  </xsl:template>
  <xsl:template match="logitheque/categorie[position()=7]/logiciel">
  <xsl:choose>
      <xsl:when test="editeur/@lien != ''">
        <xsl:variable name="url" select="editeur/@lien"/>
        <tr>
        <td class="c1">
          <a href="{editeur/@lien}" target="_blank" 
                style="font-size:10pt; font-weight:bold">
            <xsl:apply-templates select="nom"/>
          </a>
        </td>
        <td>
          <xsl:value-of select="$url"/>
        </td>
        </tr>
      </xsl:when>
      <xsl:otherwise>
        <xsl:variable name="url">failed.html</xsl:variable>
        <tr>
        <td class="c1">
          <a href="failed.html" target="_blank" 
                style="font-size:10pt; font-weight:bold">
            <xsl:apply-templates select="nom"/>
          </a>
        </td>
        <td>
          <xsl:value-of select="$url"/>
        </td>
        </tr>
      </xsl:otherwise>
  </xsl:choose>
  </xsl:template>
</xsl:stylesheet>
En savoir plus :
Découvrez cet élément sur le site du W3CDécouvrez cet élément sur le site de Microsoft