動作確認

wrote2008.07.02

実際に、簡単なサンプルを用いて、xml文書がどのように変化するのか見てみます。

sample.xml

<?xml version="1.0" encoding="Shift_JIS"?>
<?xml-stylesheet href="sample.xsl" type="text/xsl"?>
<CD>
<title>to tell the truth</title>
<song>all in the mind</song>
<type>エモ・哀愁</type>
</CD>

sample.xsl

<?xml version="1.0" encoding="Shift_JIS"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="CD">
<html>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>

<xsl:template match="title">
<h1><xsl:value-of select="." /></h1>
</xsl:template>

<xsl:template match="song">
<p><xsl:value-of select="." /></p>
</xsl:template>

<xsl:template match="type">
<p><xsl:value-of select="." /></p>
</xsl:template>

</xsl:stylesheet>

出力結果

<html>
<body>
<h1>to tell the truth</h1>
<p>all in the mind</p>
<p>エモ・哀愁</p>
</body>
</html>