Microsoft XML 2.5 SDK


 

xsl:attribute Element

[This is preliminary documentation and subject to change.]

Creates an attribute node and attaches it to an output element.

Syntax

<xsl:attribute

    name="attribute-name"  >

</xsl:attribute>

Attributes

name

Name of the attribute to create.

Element Information

Number of occurrences Unlimited
Parent elements xsl:copy, xsl:element, xsl:for-each, xsl:if, xsl:otherwise, xsl:template, xsl:when, output elements
Child elements xsl:choose, xsl:copy, xsl:eval, xsl:for-each, xsl:if, xsl:value-of
Requires closing tag Yes. XSL is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of well-formed.

Remarks

The contents of this element specify the value of the attribute.

Attributes can be added or modified during transformation by placing the xsl:attribute element within elements that generate output, such as the xsl:copy element. Note that xsl:attribute can be used directly on output elements, and not only in conjunction with xsl:element.

All attributes must be applied before children are added to the element.

Examples

This example generates an attribute that obtains its value from the XML source. It generates output in the form <IMG src="value-from-XML-source" />, using an XSL pattern that retrieves the appropriate data from the XML source, here "imagenames/imagename".

<IMG>
  <xsl:attribute name="src">
    <xsl:value-of select="imagenames/imagename" />
  </xsl:attribute>
</IMG>

This example copies the "myElement" element and adds a "copied" attribute with the value "true".

<xsl:template match="myElement">
  <xsl:copy>
    <xsl:attribute name="copied">true</xsl:attribute>
    <xsl:apply-templates />
  </xsl:copy>
</xsl:template>

See Also

Accessing and Outputting Attributes