XSLT <xsl:attribute> 元素

定義和用法
<xsl:attribute>元素用於向元素添加屬性。
注釋:<xsl:attribute> 元素會替換名稱相同的已有屬性。
語法
<xsl:attribute name="attributename" namespace="uri">
<!-- Content:template -->
</xsl:attribute>
<!-- Content:template -->
</xsl:attribute>
屬性
屬性 | 值 | 描述 |
---|---|---|
name | attributename | 必需。規定屬性的名稱。 |
namespace | URI | 可選。為屬性定義命名空間的 URI。 |
實例 1
向 picture 元素添加 source 屬性:
<picture>
<xsl:attribute name="source"/>
</picture>
<xsl:attribute name="source"/>
</picture>
實例 2
向 picture 元素添加 source 屬性,並使用 "images/name" 中的值為其賦值:
<picture>
<xsl:attribute name="source">
<xsl:value-of select="images/name" />
</xsl:attribute>
</picture>
<xsl:attribute name="source">
<xsl:value-of select="images/name" />
</xsl:attribute>
</picture>
實例 3
創建能夠應用到任何輸出元素的屬性集:
<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>
<xsl:attribute name="fname">Arial</xsl:attribute>
<xsl:attribute name="size">14px</xsl:attribute>
<xsl:attribute name="color">red</xsl:attribute>
</xsl:attribute-set>
