Defines a named set of attributes.


<xsl:attribute-set name="set_name">  
  <xsl:attribute name="attr_name">attr_value</xsl:attribute> 
  <xsl:attribute name="attr_name">attr_value</xsl:attribute>  


The name attribute specifies the name of the attribute set. This must be a qualified name. The contents of the xsl:attribute-set element consists of zero or more xsl:attribute elements. Each xsl:attribute element specifies an attribute in the set.

To use an attribute set, specify the use-attribute-sets attribute in one of the following elements:

The value of the use-attribute-sets attribute is a white-space-separated list of names of attribute sets. When you specify the use of an attribute set, it is equivalent to adding an xsl:attribute element for each attribute in each named attribute set to the beginning of the contents of the element in which you specify the use-attribute-sets attribute.

An attribute set cannot include itself. In other words, if attribute set A specifies the use-attribute-sets attribute, the list of attribute sets to use cannot include attribute set A.

You can also specify an attribute set in an xsl:use-attribute-sets attribute on a literal result element. The value of the xsl:use-attribute-sets attribute is a white-space-separated list of names of attribute sets. The xsl:use-attribute-sets attribute has the same effect as the use-attribute-sets attribute on xsl:element with one additional rule. The additional rule is that attributes specified on the literal result element itself are treated as if they were specified by xsl:attribute elements before any actual xsl:attribute elements but after any xsl:attribute elements implied by the xsl:use-attribute-sets attribute.

Thus, for a literal result element, attributes from attribute sets named in an xsl:use-attribute-sets attribute are added first, in the order listed in the attribute. Next, attributes specified on the literal result element are added. Finally, any attributes specified by xsl:attribute elements are added. Since adding an attribute to an element replaces any existing attribute of that element with the same name, this means that 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 as is used for instantiating the element bearing the use-attribute-sets or xsl:use-attribute-sets attribute. However, it is the position in the stylesheet of the xsl:attribute element rather than of the element bearing the use-attribute-sets or xsl:use-attribute-sets attribute that determines which variable bindings are visible. Consequently, only variables and parameters declared by top-level xsl:variable and xsl:param elements are visible.

The XSLT processor merges multiple definitions of an attribute set with the same expanded name. If there are two attribute sets with the same expanded name that both contain the same attribute, the XSLT processor chooses the attribute definition that was specified last in the stylesheet.


The following example creates a named attribute set, title-style, and uses it in a template rule:

<xsl:template match="chapter/heading"> 
  <fo:block quadding="start" xsl:use-attribute-sets="title-style"> 
  <xsl:attribute-set name="title-style"> 
  <xsl:attribute name="font-size">12pt</xsl:attribute> 
  <xsl:attribute name="font-weight">bold</xsl:attribute> 

Free Stylus Studio XML Training: