Element XSLT <xsl:attribute>
Definicja i zastosowanie
Element <xsl:attribute> służy do dodawania atrybutów do elementów.
Komentarz:Element <xsl:attribute> zastępuje istniejący atrybut o tej samej nazwie.
Gramatyka
<xsl:attribute name="attributename" namespace="uri"> <!-- Content:template --> </xsl:attribute>
Atrybut
Atrybut | Wartość | Opis |
---|---|---|
name | attributename | Wymagane. Określ nazwę atrybutu. |
namespace | URI | Opcjonalnie. Określ URI przestrzeni nazw dla atrybutu. |
Przykład
Przykład 1
Dodaj atrybut "source" do elementu "picture":
<picture> <xsl:attribute name="source"/> </picture>
Przykład 2
Dodaj atrybut "source" do elementu "picture" i przypisz mu wartość z "images/name":
<picture> <xsl:attribute name="source"> <xsl:value-of select="images/name" /> </xsl:attribute> </picture>
Przykład 3
Tworzenie zbioru atrybutów, które można zastosować do dowolnego elementu wyjściowego:
<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>