<xsl:variable>

Définition et utilisation

L'élément <xsl:variable> est utlisé pour déclarer des variables.

Syntaxe
<xsl:variable name="nom" select="expression">
  template-body
</xsl:variable>

Attributs
Attribut Valeur Description
name nom Obligatoire. Le nom de la variable
select expression Facultatif. La valeur de la variable

Exemples

Dans cet exemple l'élément <xsl:variable> est vide et n'a pas d'attribut "select". Cela signifie que la valeur de la variable est une chaîne vide :

<xsl:variable name="j"/>

Cet exemple ajoute une valeur à la variable "header" grâce au contenu de l'élément <xsl:variable> :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="header">
  <tr>
    <th>Element</th>
    <th>Description</th>
  </tr>
</xsl:variable>
<xsl:template match="/">
  <html>
  <body>
  <table>
    <xsl:copy-of select="$header" />
    <xsl:for-each select="reference/record">
    <tr>
    <xsl:if category="XML">
      <td><xsl:value-of select="element"/></td>
      <td><xsl:value-of select="description"/></td>
    </xsl:if>
    </tr>
    </xsl:for-each>
  </table>
  <br />
  <table>
    <xsl:copy-of select="$header" />
    <xsl:for-each select="table/record">
    <tr>
    <xsl:if category="XSL">
      <td><xsl:value-of select="element"/></td>
      <td><xsl:value-of select="description"/></td>
    </xsl:if>
    </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>