<s1 title="xsl:attribute">

<p>Stylesheets can calculate attributes using <var/xsl:attribute/>.  Where
xsl:value-of creates text, xsl:attribute creates attributes.  The contents of
the xsl:attribute element will become the value of the attribute.  This
differs from xsl:value-of which uses a select pattern to create text.
Typically, the contents of an xsl:attribute will be a combination of
text and xsl:value-of elements.</p>

<p>The following example creates a useful tag, the &lt;box> tag.
The contents of the tag are placed in an HTML table to format a box.  The
CSS style of the table is specified by an attribute in the source XTP.  Tags
like &lt;box> are very useful examples of XSL.  Instead of hard-coding HTML
tables in a JSP file, the page can specify boxes.  If the site wants to
change the look, it's simple to change the stylesheet and modify the entire
site at once.</p>

<example title='default.xsl'>
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

&lt;xsl:template match="box">
  &lt;table>
    &lt;xsl:attribute name="class">
      &lt;xsl:value-of select="@class"/>
    &lt;/xsl:attribute>
    &lt;tr>
      &lt;td>
        &lt;xsl:apply-templates/>
      &lt;/td>
    &lt;/tr>
  &lt;/table>
&lt;/xsl:template>

&lt;/xsl:stylesheet>
</example>

<p>As mentioned above, the xsl:attribute uses xsl:value-of to compute the
value of the <var/@class/> attribute.  The results below shows how much
easier the XTP file will be when you use a &lt;box> tag instead of creating
the table directly.</p>

<example title='hello.xtp'>
&lt;box class="example">
This is an example.
&lt;/box>
</example>
<results>
&lt;table class="example">
&lt;tr>
  &lt;td>This is an example&lt;/td>
&lt;/tr>
&lt;/table>
</results>

<s2 title="StyleScript">

<p>The StyleScript equivalent for xsl:attribute uses <var/name/> as its
primary argument.  The value of the attribute is defined
within <var/&lt;&lt;...>>/> tags as usual.  The stylesheet shows how
to combine text with the value-of expression.</p>

<example title='default.xsl'>
$template(example) &lt;&lt;
&lt;table>
  $attribute("class") &lt;&lt;$(@class)>>
&lt;tr>
  &lt;td>
    $apply-templates();
  &lt;/td>
&lt;/tr>
&lt;/table>
>>
</example>

</s2>

<s2 title="Summary">

<ul>
<li>Tags in stylesheets are parsed, not raw text.  So you can add attributes
to elements.
<li><var/xsl:attribute name="my-name">/> adds an attribute to the
current element.
<li><var/$attribute(my-name)/> expands to <var/xsl:attribute name="my-name"/>.
</ul>

</s2>
</s1>
