xsl:attribute
xsl:copy
xsl:element
ELEMENT: xsl:attribute-set
<xsl:attribute-set
name="qname"
use-attribute-sets="qnames"
>
</xsl:attribute-set>
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.
name="qname"
The mandatory
name
attribute is the name of the attribute set. It must be a qname. A qname is a qualified name that is composed of an optional namespace prefix, a colon, which is only present if there is a prefix, and a mandatory XML name (for example, xsl:zipcode or zipcode).
use-attribute-sets="qnames"
The optional
use-attribute-sets
attribute is a white-space-delimited list of one or more qnames of attribute sets. In other words, it is a collection of attribute set names. Each of the
xsl:attribute
elements in all of the attribute sets are applied to the output in the order in which they occur in the
use-attribute-sets
attribute. This is done by adding the
use-attribute-sets
attribute to the HTML tag or XSLT element using the following syntax:
<table
xsl:use-attribute-sets="name"
>
<xsl:copy
use-attribute-sets="name"
> ... </xsl:copy>
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"?>
and we name it: xslt_example_attributeset.xml
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.
Code for xslt_example_attributeset.xsl:
<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>
Output:
Click to view output in separate window
- requires Internet Explorer
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information