Share via


<xsl:attribute-set> Element

Defines a named set of attributes.

<xsl:attribute-set
  name = QName
  use-attribute-sets = QNames
</xsl:attribute-set>

Attributes

  • name
    Required. The Qualified Names of the attribute set. The value of the name attribute is a qualified name.
  • use-attribute-sets
    A white space-separated list of attribute sets, specified as a Qualified Names. Specifying this attribute declares each attribute in each listed attribute set.

Element Information

Number of occurrences

Unlimited

Parent elements

xsl:stylesheet, xsl:transform

Child elements

xsl:attribute

Remarks

The content of the <xsl:attribute-set> element consists of zero or more <xsl:attribute> elements that specify the attributes in the set. To use attribute sets, specify a use-attribute-sets attribute on <xsl:element>, <xsl:copy>, or <xsl:attribute-set> elements.

An error occurs if using use-attribute-setsattributes on <xsl:attribute-set> elements causes an attribute set to directly or indirectly use itself.

Specifying a use-attribute-sets attribute can be an efficient way to declare multiple attributes on an element. To accomplish the same results using <xsl:attribute>, you would have to use an <xsl:attribute> element for each attribute in each named attribute set. You would add these <xsl:attribute> elements as content of the <xsl:element>, <xsl:copy>, or <xsl:attribute-set> element.

Attribute sets can also be used by specifying an xsl:use-attribute-sets attribute on a literal result element. For a literal result element, attributes will be added in the following order:

  1. Attributes from attribute sets named in an xsl:use-attribute-sets attribute, in the order listed in that attribute.

  2. Attributes specified on the literal result element.

  3. Any attributes specified by <xsl:attribute> elements will be added.

Because adding an attribute to an element replaces any existing attribute of that element with the same name, attributes specified in attribute sets can be overridden by attributes specified on the literal result element itself.

The template within each <xsl:attribute> element in an <xsl:attribute-set> element is instantiated each time the attribute set is used. It is instantiated using the same current node and current node list that is used for instantiating the element that bears the use-attribute-sets or xsl:use-attribute-sets attribute. However, it is the position of the <xsl:attribute> element in the style sheet — rather than the position of the element bearing the use-attribute-sets or xsl:use-attribute-sets attribute — that determines which variable bindings are visible. Therefore, only variables and parameters declared by top-level <xsl:variable> and <xsl:param> elements are visible.

Multiple definitions of an attribute set with the same expanded-name are merged. An attribute from a definition that has higher import precedence takes precedence over an attribute from a definition that has lower import precedence.

An error occurs if there are two attribute sets that have the same expanded-name and equal import precedence, and that both contain the same attribute, unless there is a definition of the attribute set with higher import precedence that also contains the attribute.

The following topic provides an example of the <xsl:attribute-set> element.