عنصر <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>