XSLT <xsl:attribute>
❮ ทำการอ้างอิงองค์ประกอบ XSLT ให้สมบูรณ์
ความหมายและการใช้งาน
<xsl:attribute> องค์ประกอบที่ใช้เพื่อเพิ่มแอตทริบิวต์ให้กับองค์ประกอบ
หมายเหตุ: องค์ประกอบ <xsl:attribute> จะแทนที่แอตทริบิวต์ที่มีอยู่ด้วยชื่อที่เทียบเท่ากัน
ไวยากรณ์
<xsl:attribute name="attributename" namespace="uri">
<!-- Content:template -->
</xsl:attribute>
คุณลักษณะ
Attribute | Value | Description |
---|---|---|
name | attributename | Required. Specifies the name of the attribute |
namespace | URI | Optional. Defines the namespace URI for the attribute |
ตัวอย่าง 1
เพิ่มแอตทริบิวต์แหล่งที่มาให้กับองค์ประกอบรูปภาพ:
<picture>
<xsl:attribute name="source"/>
</picture>
ตัวอย่าง 2
เพิ่มแอตทริบิวต์แหล่งที่มาให้กับองค์ประกอบรูปภาพและเติมด้วยค่าจาก "images/name" :
<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>
❮ ทำการอ้างอิงองค์ประกอบ XSLT ให้สมบูรณ์