Name
<xsl:attribute> — Allows you to create an attribute in the output document. The advantage of <xsl:attribute>
is that it allows you to build the attribute’s value from parts of the input document, hardcoded text, values returned by functions, and any other value you can access from your stylesheet.
Category
Instruction
Required Attributes
- name
The
name
attribute defines the name of the attribute created by the<xsl:attribute>
element. (No matter how you try to say this, talking about the attributes of the<xsl:attribute>
element is confusing, isn’t it?)
Optional Attributes
- namespace
The
namespace
attribute defines the namespace URI that should be used for this attribute in the output document. You don’t have control over the namespace prefix used; the only thing you specify with thenamespace
attribute is the URI of the namespace.
Content
An XSLT template. In other words, you can build the contents of an attribute with <xsl:choose>
elements, <xsl:text>
, and <xsl:value-of>
elements.
Appears in
<xsl:attribute>
appears inside a template.
Defined in
XSLT section 7.1.3, Creating Attributes with xsl:attribute
.
Example
For this example, we want to create an HTML table from the following XML document:
<?xml version="1.0"?> <list xml:lang="en"> <title>Albums I've bought recently:</title> <listitem>The Sacred Art of Dub</listitem> <listitem>Only the Poor Man Feel It</listitem> <listitem>Excitable Boy</listitem> <listitem xml:lang="sw">Aki Special</listitem> <listitem xml:lang="en-gb">Combat Rock</listitem> ...
Get XSLT now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.