Element <xsl:attribute> w XSLT
Definicja i zastosowanie
Element <xsl:attribute> jest używany do dodania atrybutu do elementu.
Komentarz:Element <xsl:attribute> zastępuje istniejący atrybut o tej samej nazwie.
Gramatyka
<xsl:attribute name="nazwa_atrybutu" namespace="uri"> <!-- Content:template --> </xsl:attribute>
Atrybut
Atrybut | Wartość | Opis |
---|---|---|
name | nazwa_atrybutu | Wymagane. Określ nazwę atrybutu. |
przestrzeń nazw | URI | Opcjonalnie. Nazwij przestrzeń nazw URI 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
Utwórz zestaw atrybutów, który można zastosować do każdego 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>