<html>
<head>
<title>&lt;xsl:attribute-set&gt;</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="Description">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
<tr>
<td valign="top" class="NAME">&lt;xsl:attribute-set&gt;</td>
<td valign="top" class="COMPATIBILITY">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
</tr>
<tr>
<td valign="top" colspan="2" class="description">
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. </td></tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Category</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Top-level element</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Required Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<dl>
<dt>
name
</dt>
<dd>
Defines the name of this attribute set.
<P></p>
</dl>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Optional Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<dl>
<dt>
use-attribute-sets
</dt>
<dd>
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
<span class="LITERAL">
&lt;
xsl:attribute-set
&gt;
</span>
s in this one, but be aware that an
<span class="LITERAL">
&lt;
xsl:attribute-set
&gt;
</span>
that directly or indirectly embeds itself results in an error. In other words, if attribute set
<span class="LITERAL">
A
</span>
embeds attribute set
<span class="LITERAL">
B
</span>
, which in turn embeds attribute set
<span class="LITERAL">
C
</span>
, which in turn embeds attribute set
<span class="LITERAL">
A
</span>
, the XSLT processor will signal an error.
<P></p>
</dl>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Content</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>One or more <span class="LITERAL">&lt;xsl:attribute&gt;</span> elements.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Appears in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>
<span class="LITERAL">&lt;xsl:stylesheet&gt;</span>. <span class="LITERAL">&lt;xsl:attribute-set&gt;</span> is a top-level element and can only appear as a child of <span class="LITERAL">&lt;xsl:stylesheet&gt;</span>.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Defined in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>XSLT section 7.1.4, Named Attribute Sets.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Example</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>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:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;

  &lt;xsl:output method="html"/&gt;

  &lt;xsl:attribute-set name="regular-text"&gt;
    &lt;xsl:attribute name="font-size"&gt;12pt&lt;/xsl:attribute&gt;
    &lt;xsl:attribute name="font-family"&gt;sans-serif&lt;/xsl:attribute&gt;
  &lt;/xsl:attribute-set&gt;

  &lt;xsl:attribute-set name="emphasized-text" use-attribute-sets="regular-text"&gt;
    &lt;xsl:attribute name="font-style"&gt;italic&lt;/xsl:attribute&gt;
  &lt;/xsl:attribute-set&gt;

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

  &lt;xsl:template match="/"&gt;
    &lt;fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;
      &lt;fo:layout-master-set&gt;
        &lt;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"&gt;
          &lt;fo:region-before extent="25pt"/&gt;
          &lt;fo:region-body margin-top="50pt" margin-bottom="50pt"/&gt;
          &lt;fo:region-after extent="25pt"/&gt;
        &lt;/fo:simple-page-master&gt;
        &lt;fo:page-sequence-master master-name="standard"&gt;
          &lt;fo:repeatable-page-master-alternatives&gt;
            &lt;fo:conditional-page-master-reference master-name="main" 
              odd-or-even="any"/&gt;
          &lt;/fo:repeatable-page-master-alternatives&gt;
        &lt;/fo:page-sequence-master&gt;
      &lt;/fo:layout-master-set&gt;
      
      &lt;fo:page-sequence master-name="standard"&gt;
        &lt;fo:flow flow-name="xsl-region-body"&gt;
          &lt;xsl:apply-templates select="list"/&gt;
        &lt;/fo:flow&gt;
      &lt;/fo:page-sequence&gt;
    &lt;/fo:root&gt;
  &lt;/xsl:template&gt;

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

&lt;/xsl:stylesheet&gt;</pre></span>
<p>Notice that both the <span class="LITERAL">emphasized-text</span> and <span class="LITERAL">large-text</span> attribute sets use the <span class="LITERAL">regular-text</span> attribute set as a base.  In the case of <span class="LITERAL">large-text</span>, the <span class="LITERAL">font-size</span> attribute defined in the <span class="LITERAL">large-text</span> attribute set overrides the <span class="LITERAL">font-size</span> attribute included from the <span class="LITERAL">regular-text</span> attribute set.  We'll apply our stylesheet to the following XML document:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;list&gt;
  &lt;title&gt;A few of my favorite albums&lt;/title&gt;
  &lt;listitem&gt;A Love Supreme&lt;/listitem&gt;
  &lt;listitem&gt;Beat Crazy&lt;/listitem&gt;
  &lt;listitem&gt;Here Come the Warm Jets&lt;/listitem&gt;
  &lt;listitem&gt;Kind of Blue&lt;/listitem&gt;
  &lt;listitem&gt;London Calling&lt;/listitem&gt;
  &lt;listitem&gt;Remain in Light&lt;/listitem&gt;
  &lt;listitem&gt;The Joshua Tree&lt;/listitem&gt;
  &lt;listitem&gt;The Indestructible Beat of Soweto&lt;/listitem&gt;
&lt;/list&gt;</pre></span>
<p>The stylesheet generates this messy-looking file of formatting objects, which describe how the text of our XML source document should be rendered:  </p>
<span class="PROGRAMLISTING"><pre>
&lt;fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;
&lt;fo:layout-master-set&gt;
&lt;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"&gt;
&lt;fo:region-before extent="25pt"/&gt;
&lt;fo:region-body margin-bottom="50pt" margin-top="50pt"/&gt;
&lt;fo:region-after extent="25pt"/&gt;
&lt;/fo:simple-page-master&gt;
&lt;fo:page-sequence-master master-name="standard"&gt;
&lt;fo:repeatable-page-master-alternatives&gt;
&lt;fo:conditional-page-master-reference odd-or-even="any" master-name="main"/&gt;
&lt;/fo:repeatable-page-master-alternatives&gt;
&lt;/fo:page-sequence-master&gt;
&lt;/fo:layout-master-set&gt;
&lt;fo:page-sequence master-name="standard"&gt;
&lt;fo:flow flow-name="xsl-region-body"&gt;
&lt;fo:block font-size="18pt" font-family="sans-serif" 
font-weight="bold" space-after.optimum="21pt"&gt;A few of my 
favorite albums&lt;/fo:block&gt;
&lt;fo:list-block provisional-label-separation="0.15cm" 
provisional-distance-between-starts="0.4cm"&gt;
&lt;fo:list-item space-after.optimum="17pt" start-indent="0.5cm"&gt;
&lt;fo:list-item-label&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif"&gt;*&lt;/fo:block&gt;
&lt;/fo:list-item-label&gt;
&lt;fo:list-item-body&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif" 
font-style="italic"&gt;A Love Supreme&lt;/fo:block&gt;
&lt;/fo:list-item-body&gt;
&lt;/fo:list-item&gt;
&lt;fo:list-item space-after.optimum="17pt" start-indent="0.5cm"&gt;
&lt;fo:list-item-label&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif"&gt;*&lt;/fo:block&gt;
&lt;/fo:list-item-label&gt;
&lt;fo:list-item-body&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif" 
font-style="italic"&gt;Beat Crazy&lt;/fo:block&gt;
&lt;/fo:list-item-body&gt;
&lt;/fo:list-item&gt;
&lt;fo:list-item space-after.optimum="17pt" start-indent="0.5cm"&gt;
&lt;fo:list-item-label&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif"&gt;*&lt;/fo:block&gt;
&lt;/fo:list-item-label&gt;
&lt;fo:list-item-body&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif" 
font-style="italic"&gt;Here Come the Warm Jets&lt;/fo:block&gt;
&lt;/fo:list-item-body&gt;
&lt;/fo:list-item&gt;
&lt;fo:list-item space-after.optimum="17pt" start-indent="0.5cm"&gt;
&lt;fo:list-item-label&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif"&gt;*&lt;/fo:block&gt;
&lt;/fo:list-item-label&gt;
&lt;fo:list-item-body&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif" 
font-style="italic"&gt;Kind of Blue&lt;/fo:block&gt;
&lt;/fo:list-item-body&gt;
&lt;/fo:list-item&gt;
&lt;fo:list-item space-after.optimum="17pt" start-indent="0.5cm"&gt;
&lt;fo:list-item-label&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif"&gt;*&lt;/fo:block&gt;
&lt;/fo:list-item-label&gt;
&lt;fo:list-item-body&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif" 
font-style="italic"&gt;London Calling&lt;/fo:block&gt;
&lt;/fo:list-item-body&gt;
&lt;/fo:list-item&gt;
&lt;fo:list-item space-after.optimum="17pt" start-indent="0.5cm"&gt;
&lt;fo:list-item-label&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif"&gt;*&lt;/fo:block&gt;
&lt;/fo:list-item-label&gt;
&lt;fo:list-item-body&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif" 
font-style="italic"&gt;Remain in Light&lt;/fo:block&gt;
&lt;/fo:list-item-body&gt;
&lt;/fo:list-item&gt;
&lt;fo:list-item space-after.optimum="17pt" start-indent="0.5cm"&gt;
&lt;fo:list-item-label&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif"&gt;*&lt;/fo:block&gt;
&lt;/fo:list-item-label&gt;
&lt;fo:list-item-body&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif" 
font-style="italic"&gt;The Joshua Tree&lt;/fo:block&gt;
&lt;/fo:list-item-body&gt;
&lt;/fo:list-item&gt;
&lt;fo:list-item space-after.optimum="17pt" start-indent="0.5cm"&gt;
&lt;fo:list-item-label&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif"&gt;*&lt;/fo:block&gt;
&lt;/fo:list-item-label&gt;
&lt;fo:list-item-body&gt;
&lt;fo:block font-size="12pt" font-family="sans-serif" 
font-style="italic"&gt;The Indestructible Beat of Soweto&lt;/fo:block&gt;
&lt;/fo:list-item-body&gt;
&lt;/fo:list-item&gt;
&lt;/fo:list-block&gt;
&lt;/fo:flow&gt;
&lt;/fo:page-sequence&gt;
&lt;/fo:root&gt;</pre></span>
<p>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:</p>
<span class="PROGRAMLISTING"><pre>
java org.apache.fop.apps.CommandLine test.fo test.pdf</pre></span>
<p>The FOP tool creates a PDF that looks like <link linkend="xslt-appa-a4">Figure A-4</link>.</p>
<figure label="A-4" id="xslt-appa-a4">
        <p class="TITLE">PDF generated from an XSL-FO file</p>
        <graphic depth="309" width="455" fileref="figs/xslt.aa04.gif"/>
      </figure>
</td>
</tr>
</table>
</div>
</body>
</html>