<要素 属性="属性値">の記述形式で、属性値には直接文字列しか記述できない。しかしXPath式を{}で囲って指定すれば、XPath式の評価結果(オブジェクト)が値として使える。評価結果が文字列以外の場合、string関数の定義に従い暗黙裡に文字列変換される。
・属性値テンプレートが使用できる場所
リテラル結果要素(XSLT命令要素<xsl:〜>以外の文字列で、そのまま出力される)
<xsl:attribute>のname/namespace属性
<xsl:element>のname/namespace属性
<xsl:number>のformat/lang/letter-value/grouping-separator/grouping-size属性
<xsl:processing-instruction>のname属性
<xsl:sort>のlang/data-type/order/case-order属性
[サンプルXML文書を表示](下のフレームに)
XMLソース
<?xml version="1.0" encoding="Shift_JIS" ?>
<?xml-stylesheet type="text/xsl" href="attribute04.xsl"?>
<root>
<title スタイル="color:green;font:bold italic 26px">{}を利用したHTML属性の生成</title>
<画像>
<imgfile width="103" height="116">../../images/cut/025.gif</imgfile>
<alt>{}を利用しHTML属性を生成する</alt>
</画像>
<link>
<title>大阪日本橋DOS/Vプロムナード</title>
<url>../../dosv/dosv.htm</url> <window>_self</window>
</link> <link2>
<title>ヤフー・ジャパン</title>
<url>www.yahoo.co.jp/</url>
<window>_blank</window>
</link2>
<end>以上です(2004/4/14)</end>
</root>
XSLソース
<?xml version="1.0" encoding="Shift_Jis"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="Shift_JIS"/>
<xsl:template match="/">
<H3 style="{root/title/@スタイル}"><xsl:value-of select="root/title"/></H3>
<img border="0" src="{root/画像/imgfile}" width="{root/画像/imgfile/@width}"
height="{root/画像/imgfile/@height}" alt="説明:-→「{root/画像/alt}」"></img>
<hr/>
<a href="{root/link/url}" target="{root/link/window}"> <xsl:value-of select="root/link/title" /></a><br/>
<a href="http://{root/link2/url}" target="{root/link2/window}"> <xsl:value-of select="root/link2/title" /></a> </xsl:template>
</xsl:stylesheet>
end(04/4/14、04/5/13修正)