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>
完整的XSLT元素參考手冊