อนุภาค <xsl:attribute> ของ XSLT

การกำหนดและการใช้งาน

อนุภาค <xsl:attribute> ใช้เพื่อเพิ่มแอตทริบิวต์ให้กับอนุภาค

หมายเหตุ:อนุภาค <xsl:attribute> จะทดแทนแอตทริบิวต์ที่มีชื่อเดียวกัน

รูปแบบ

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

แอตทริบิวต์

แอตทริบิวต์ ค่า รายละเอียด
name attributename จำเป็น กำหนดชื่อของแอตทริบิวต์
namespace URI เลือกตั้งแล้ว กำหนด URI ของชื่ออนุญาต

ตัวอย่าง

ตัวอย่าง 1

เพิ่มแอตทริบิวต์ source ให้กับอนุภาค picture

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

ตัวอย่าง 2

เพิ่มแอตทริบิวต์ source ให้กับอนุภาค picture และใช้ค่าจาก "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>