Attribute Value Templates
Although they’re technically defined in the XSLT specification (in
section 7.6.2, to be exact), we’ll discuss attribute value templates here. An attribute value template is an XPath expression that is evaluated, and the result of that evaluation replaces the attribute value template. For example, we could create an HTML <table>
element like this:
<table border="{@size}"/>
In this example, the XPath expression @size
is evaluated, and its value, whatever that happens to be, is inserted into the output tree as the value of the border
attribute. Attribute value templates can be used in any literal result elements in your stylesheet (for HTML elements and other things that aren’t part of the XSLT namespace, for example). You can also use attribute value templates in the following XSLT attributes:
The
name
andnamespace
attributes of the<xsl:attribute>
elementThe
name
andnamespace
attributes of the<xsl:element>
elementThe
format
,lang
,letter-value
,grouping-separator
, andgrouping-size
attributes of the<xsl:number>
elementThe
name
attribute of the<xsl:processing-instruction>
elementThe
lang
,data-type
,order
, andcase-order
attributes of the<xsl:sort>
element
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.