XSLT <xsl:attribute>-elementti

Määrittely ja käyttö

<xsl:attribute>-elementti käytetään attribuutin lisäämiseen elementtiin.

Huomautus:<xsl:attribute>-elementti korvaa olemassa olevan nimeltään saman attribuutin.

Syntaksi

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

Attribuutti

Attribuutti Arvo Kuvaus
name attributename Välttämätön. Määritä attribuutin nimi.
namespace URI Valinnainen. Määritä attribuutin nimen URI-tila.

Esimerkki

Esimerkki 1

Lisää "source"-attribuutti "picture"-elementtiin:

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

Esimerkki 2

Lisää "source"-attribuutti "picture"-elementtiin ja aseta sille arvo "images/name":

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

Esimerkki 3

Luo attribuuttisarja, joka voidaan soveltaa mihin tahansa tulostuselementtiin:

<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>