移転しました。

XSL 基本

ヘッダを書く。

<?xml version="1.0" encoding="UTF-8" ?>

最上位のタグを配置。

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

XML側のルートタグの出力を定義する。別の定義(テンプレート)を埋め込みたい時は<xsl:apply-templates />を挿入しておく。

<xsl:template match="/">
  <html>
    <head>
    <title>HelloWorld</title>
    </head>
    <body>
      <xsl:apply-templates />
    </body>
  </html>
</xsl:template>

<xsl:apply-templates />で適用されるテンプレートを書く。

<xsl:template match="message[@name='hello']">
  <xsl:value-of select="." />
</xsl:template>

上のようにするとルート直下の<message>タグのname属性"hello"のinnerTextが配置される。
XMLのルートタグ以下に<message>タグしかなければこれでもいいけれど、いっぱいタグがあると全部出力されてしまう。回避方法は

<xsl:template match="/">
  <html>
    <head>
    <title>HelloWorld</title>
    </head>
    <body>
      <xsl:apply-templates select="message[@name='hello']" />
    </body>
  </html>
</xsl:template>

というように<xsl:apply-templates />のselect属性で指定する。
<img>や<a>タグのようなinnerTextではなく属性値に設定したい場合は

<xsl:template match="message[@name='src']">
  <img>
  <xsl:attribute name="src"><xsl:value-of select="." /></xsl:attribute>
  </img>
</xsl:template>

というようにattributeで設定する。
XMLのネスト先を指定する時は

<xsl:template match="message/foo/hoge">

というようにそのままスラッシュ区切りで降りていけば指定できる。