テンプレートの活用:本文中の装飾

文章中のある部分を装飾したり、リンクを張ったり、また文章中に画像を挿入するなどに活用できる。

[サンプルXML文書を表示](下のフレームに)

XMLソース

<?xml version="1.0" encoding="Shift_JIS" ?>
<?xml-stylesheet type="text/xsl" href="temp06.xsl"?>
<root>
<title>テンプレートの活用:本文中の装飾</title>
<本文><太字>KodayanのHomePage</太字>には<赤>大阪日本橋</赤>のパソコン関連の
<リンク url="../../dosv/dosv.htm">マップ</リンク>を掲載しています。
<画像 src="../../images/linkdosv.gif">リンクバナー</画像>をご利用になって、
ご自由にリンクをはってください。
</本文>
<end>以上です(2004/4/8)</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="/">
<center><H3><xsl:value-of select="root/title"/></H3></center>
<xsl:apply-templates select="root/本文"/>
</xsl:template>

<!--本文全体を表示する-->
<xsl:template match="本文">
<xsl:apply-templates />
</xsl:template>

<!--以下、本文内の装飾・リンク・画像などを指定するテンプレート-->
<xsl:template match="太字">
<span style="font:bold 30px"><xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="赤">
<span style="color:red"><xsl:value-of select="."/></span>
</xsl:template>
<xsl:template match="リンク">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="@url"/>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="画像">
<xsl:value-of select="."/>
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="@src"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

end(04/4/9)