Next / Previous / Contents / Shipman's homepage

9.4. xsl:attribute: Output an attribute

The purpose of this tag is to add an attribute to an element, especially if the attribute name is something that has to be computed during processing. The attribute is added to whatever element is being output at that point by your template. Here are the attributes:

name (required)

An XPath expression that specifies the attribute name.


If used, the value of this attribute is prefixed to the attribute name as a namespace.

Here's an example. This generates a dish element with an attribute whose namespace is dl:, whose attribute name is the value of the variable dish-tag, and whose value is the name of the dish-lang variable:

      <xsl:attribute name="$dish-tag" namespace="'dl'">
        <xsl:value-of select="$dish-lang"/>