The xsl:attribute-set element defines and names a set containing zero or more xsl:attribute elements. Each of the xsl:attribute elements are applied to the output in the order that they occur inside the xsl:attribute-set element. An xsl:attribute element allows you to create an attribute node, define a value, and add it to the output.
The xsl:attribute-set element can only be a child of the xsl:stylesheet or the xsl:transform elements.
The concept is that you can create a set of attributes that can be applied more than once by simply calling the attribute set by name.
This is not a self-closing element. The separate closing element is mandatory.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:attribute-set name="set_table">
<xsl:attribute name="border">
5
</xsl:attribute>
<xsl:attribute name="cellpadding">
15
</xsl:attribute>
<xsl:attribute name="cellspacing">
10
</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="/">
<html>
<body>
<table xsl:use-attribute-sets="set_table">
<xsl:for-each select="devguru_staff/programmer">
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="age" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Name
Age
Bugs Bunny
31
Daisy Duck
51
Minnie Mouse
24
Pluto
21
Porky Pig
44
Road Runner
48
This is the code for xslt_example_attributeset.xsl
In this example we set the border, cellpadding, and cellspacing values for a table. We only apply the attribute set to one table, but it can be applied to any number of tables to give a similar look. This is the code for xslt_example_attributeset.xsl.
We use the DevGuru Staff List XML file for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_attributeset.xsl"?>