Elemento <xsl:attribute> di XSLT

Definizione e uso

L'elemento <xsl:attribute> viene utilizzato per aggiungere attributi agli elementi.

Nota:L'elemento <xsl:attribute> sostituirà l'attributo con lo stesso nome.

Sintassi

<xsl:attribute name="attributename" namespace="uri">
  <!-- Contenuto:template -->
</xsl:attribute>

Attributo

Attributo Valore Descrizione
name attributename Obbligatorio. Specifica il nome dell'attributo.
namespace URI Opzionale. Assegna un URI di namespace all'attributo.

Esempio

Esempio 1

Aggiungi l'attributo source all'elemento picture:

<picture>
  <xsl:attribute name="source"/>
</picture>

Esempio 2

Aggiungi l'attributo source all'elemento picture e assegna il valore con "images/name":

<picture>
  <xsl:attribute name="source">
    <xsl:value-of select="images/name" />
  </xsl:attribute>
</picture>

Esempio 3

Creare un set di attributi che può essere applicato a qualsiasi elemento di output:

<xsl:attribute-set name="font">
  <xsl:attribute name="fname">Arial</xsl:attribute>
  <xsl:attribute name="size">14px</xsl:attribute>
  <xsl:attribute name="color">red</xsl:attribute>
</xsl:attribute-set>