Elemento <xsl:attribute> de XSLT
Definición y uso
El elemento <xsl:attribute> se utiliza para agregar atributos a los elementos.
Comentarios:El elemento <xsl:attribute> reemplaza al atributo existente con el mismo nombre.
Sintaxis
<xsl:attribute name="attributename" namespace="uri"> <!-- Contenido:template --> </xsl:attribute>
Atributo
Atributo | Valor | Descripción |
---|---|---|
name | attributename | Obligatorio. Especificar el nombre del atributo. |
namespace | URI | Opcional. Definir el URI del espacio de nombres del atributo. |
Ejemplo
Ejemplo 1
Agregar el atributo "source" al elemento "picture":
<picture> <xsl:attribute name="source"/> </picture>
Ejemplo 2
Agregar el atributo "source" al elemento "picture" y asignar el valor de "images/name":
<picture> <xsl:attribute name="source"> <xsl:value-of select="images/name" /> </xsl:attribute> </picture>
Ejemplo 3
Crear un conjunto de atributos que se pueda aplicar a cualquier elemento de salida:
<xsl:attribute-set name="font"> <xsl:attribute name="fname">Arial</xsl:attribute> <xsl:attribute name="size">14px</xsl:attribute> <xsl:attribute name="color">rojo</xsl:attribute> </xsl:attribute-set>