<xsl:attribute-set> |
Allows you to define a group of attributes for the output document. You can then reference the entire attribute set with its name, rather than create all attributes individually.
Category
Top-level element
Required Attributes

name
  Defines the name of this attribute set.

Optional Attributes

use-attribute-sets
  Lists one or more attribute sets that should be used by this attribute set. If you specify more than one set, separate their names with whitespace characters. You can use this attribute to embed other < xsl:attribute-set > s in this one, but be aware that an < xsl:attribute-set > that directly or indirectly embeds itself results in an error. In other words, if attribute set A embeds attribute set B , which in turn embeds attribute set C , which in turn embeds attribute set A , the XSLT processor will signal an error.

Content
One or more <xsl:attribute> elements.
Appears in
<xsl:stylesheet>. <xsl:attribute-set> is a top-level element and can only appear as a child of <xsl:stylesheet>.
Defined in
XSLT section 7.1.4, Named Attribute Sets.
Example
For this example, we'll create a stylesheet that defines attribute sets for regular text, emphasized text, and large text. Just for variety's sake, we'll use the Extensible Stylesheet Language Formatting Objects (XSL-FO) specification to convert our XML document into a PDF file. Here's our stylesheet:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fo="http://www.w3.org/1999/XSL/Format">

      <xsl:output method="html"/>

      <xsl:attribute-set name="regular-text">
        <xsl:attribute name="font-size">12pt</xsl:attribute>
        <xsl:attribute name="font-family">sans-serif</xsl:attribute>
      </xsl:attribute-set>

      <xsl:attribute-set name="emphasized-text" use-attribute-sets="regular-text">
        <xsl:attribute name="font-style">italic</xsl:attribute>
      </xsl:attribute-set>

      <xsl:attribute-set name="large-text" use-attribute-sets="regular-text">
        <xsl:attribute name="font-size">18pt</xsl:attribute>
        <xsl:attribute name="font-weight">bold</xsl:attribute>
        <xsl:attribute name="space-after.optimum">21pt</xsl:attribute>
      </xsl:attribute-set>

      <xsl:template match="/">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
          <fo:layout-master-set>
            <fo:simple-page-master margin-right="75pt" margin-left="75pt"
              page-height="11in" page-width="8.5in"
              margin-bottom="25pt" margin-top="25pt" master-name="main">
              <fo:region-before extent="25pt"/>
              <fo:region-body margin-top="50pt" margin-bottom="50pt"/>
              <fo:region-after extent="25pt"/>
            </fo:simple-page-master>
            <fo:page-sequence-master master-name="standard">
              <fo:repeatable-page-master-alternatives>
                <fo:conditional-page-master-reference master-name="main"
                  odd-or-even="any"/>
              </fo:repeatable-page-master-alternatives>
            </fo:page-sequence-master>
          </fo:layout-master-set>

          <fo:page-sequence master-name="standard">
            <fo:flow flow-name="xsl-region-body">
              <xsl:apply-templates select="list"/>
            </fo:flow>
          </fo:page-sequence>
        </fo:root>
      </xsl:template>

      <xsl:template match="list">
        <fo:block xsl:use-attribute-sets="large-text">
          <xsl:value-of select="title"/>
        </fo:block>
        <fo:list-block provisional-distance-between-starts="0.4cm"
          provisional-label-separation="0.15cm">
          <xsl:for-each select="listitem">
            <fo:list-item start-indent="0.5cm" space-after.optimum="17pt">
              <fo:list-item-label>
                <fo:block xsl:use-attribute-sets="regular-text">*</fo:block>
              </fo:list-item-label>
              <fo:list-item-body>
                <fo:block xsl:use-attribute-sets="emphasized-text">
                  <xsl:value-of select="."/>
                </fo:block>
              </fo:list-item-body>
            </fo:list-item>
          </xsl:for-each>
        </fo:list-block>
      </xsl:template>

    </xsl:stylesheet>
Notice that both the emphasized-text and large-text attribute sets use the regular-text attribute set as a base. In the case of large-text, the font-size attribute defined in the large-text attribute set overrides the font-size attribute included from the regular-text attribute set. We'll apply our stylesheet to the following XML document:
    <?xml version="1.0"?>
    <list>
      <title>A few of my favorite albums</title>
      <listitem>A Love Supreme</listitem>
      <listitem>Beat Crazy</listitem>
      <listitem>Here Come the Warm Jets</listitem>
      <listitem>Kind of Blue</listitem>
      <listitem>London Calling</listitem>
      <listitem>Remain in Light</listitem>
      <listitem>The Joshua Tree</listitem>
      <listitem>The Indestructible Beat of Soweto</listitem>
    </list>
The stylesheet generates this messy-looking file of formatting objects, which describe how the text of our XML source document should be rendered:
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <fo:layout-master-set>
    <fo:simple-page-master master-name="main" margin-top="25pt"
    margin-bottom="25pt" page-width="8.5in" page-height="11in"
    margin-left="75pt" margin-right="75pt">
    <fo:region-before extent="25pt"/>
    <fo:region-body margin-bottom="50pt" margin-top="50pt"/>
    <fo:region-after extent="25pt"/>
    </fo:simple-page-master>
    <fo:page-sequence-master master-name="standard">
    <fo:repeatable-page-master-alternatives>
    <fo:conditional-page-master-reference odd-or-even="any" master-name="main"/>
    </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>
    </fo:layout-master-set>
    <fo:page-sequence master-name="standard">
    <fo:flow flow-name="xsl-region-body">
    <fo:block font-size="18pt" font-family="sans-serif"
    font-weight="bold" space-after.optimum="21pt">A few of my
    favorite albums</fo:block>
    <fo:list-block provisional-label-separation="0.15cm"
    provisional-distance-between-starts="0.4cm">
    <fo:list-item space-after.optimum="17pt" start-indent="0.5cm">
    <fo:list-item-label>
    <fo:block font-size="12pt" font-family="sans-serif">*</fo:block>
    </fo:list-item-label>
    <fo:list-item-body>
    <fo:block font-size="12pt" font-family="sans-serif"
    font-style="italic">A Love Supreme</fo:block>
    </fo:list-item-body>
    </fo:list-item>
    <fo:list-item space-after.optimum="17pt" start-indent="0.5cm">
    <fo:list-item-label>
    <fo:block font-size="12pt" font-family="sans-serif">*</fo:block>
    </fo:list-item-label>
    <fo:list-item-body>
    <fo:block font-size="12pt" font-family="sans-serif"
    font-style="italic">Beat Crazy</fo:block>
    </fo:list-item-body>
    </fo:list-item>
    <fo:list-item space-after.optimum="17pt" start-indent="0.5cm">
    <fo:list-item-label>
    <fo:block font-size="12pt" font-family="sans-serif">*</fo:block>
    </fo:list-item-label>
    <fo:list-item-body>
    <fo:block font-size="12pt" font-family="sans-serif"
    font-style="italic">Here Come the Warm Jets</fo:block>
    </fo:list-item-body>
    </fo:list-item>
    <fo:list-item space-after.optimum="17pt" start-indent="0.5cm">
    <fo:list-item-label>
    <fo:block font-size="12pt" font-family="sans-serif">*</fo:block>
    </fo:list-item-label>
    <fo:list-item-body>
    <fo:block font-size="12pt" font-family="sans-serif"
    font-style="italic">Kind of Blue</fo:block>
    </fo:list-item-body>
    </fo:list-item>
    <fo:list-item space-after.optimum="17pt" start-indent="0.5cm">
    <fo:list-item-label>
    <fo:block font-size="12pt" font-family="sans-serif">*</fo:block>
    </fo:list-item-label>
    <fo:list-item-body>
    <fo:block font-size="12pt" font-family="sans-serif"
    font-style="italic">London Calling</fo:block>
    </fo:list-item-body>
    </fo:list-item>
    <fo:list-item space-after.optimum="17pt" start-indent="0.5cm">
    <fo:list-item-label>
    <fo:block font-size="12pt" font-family="sans-serif">*</fo:block>
    </fo:list-item-label>
    <fo:list-item-body>
    <fo:block font-size="12pt" font-family="sans-serif"
    font-style="italic">Remain in Light</fo:block>
    </fo:list-item-body>
    </fo:list-item>
    <fo:list-item space-after.optimum="17pt" start-indent="0.5cm">
    <fo:list-item-label>
    <fo:block font-size="12pt" font-family="sans-serif">*</fo:block>
    </fo:list-item-label>
    <fo:list-item-body>
    <fo:block font-size="12pt" font-family="sans-serif"
    font-style="italic">The Joshua Tree</fo:block>
    </fo:list-item-body>
    </fo:list-item>
    <fo:list-item space-after.optimum="17pt" start-indent="0.5cm">
    <fo:list-item-label>
    <fo:block font-size="12pt" font-family="sans-serif">*</fo:block>
    </fo:list-item-label>
    <fo:list-item-body>
    <fo:block font-size="12pt" font-family="sans-serif"
    font-style="italic">The Indestructible Beat of Soweto</fo:block>
    </fo:list-item-body>
    </fo:list-item>
    </fo:list-block>
    </fo:flow>
    </fo:page-sequence>
    </fo:root>
Be aware that as of this writing (May 2001), the XSL-FO specification isn't final, so there's no guarantee that these formatting objects will work correctly with future XSL-FO tools. Here's how we invoke the Apache XML Project's FOP (Formatting Objects to PDF translator) tool to create a PDF:
    java org.apache.fop.apps.CommandLine test.fo test.pdf
The FOP tool creates a PDF that looks like Figure A-4.

PDF generated from an XSL-FO file