@634

XSLT - テンプレート(xsl:template)

Advertisement

書式

<xsl:template match="パターン">
    テンプレート
</xsl:template>

<xsl:template match="title">
    <h1>
        <xsl:apply-templates/>
    </h1>
</xsl:template>
参照元 XML 内の title というノードに <h1>〜</h1> という書式を適用する。

サンプルコード

sample.xml
<?xml version="1.0" encoding="Shift_JIS"?>
<?xml-stylesheet type="text/xsl" href="./style.xsl"?>

<document>
    <title>XSLT</title>
    <body>XSLT&amp;XML</body>
</document>
style.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="title">
    <h1>
        <xsl:value-of select="."/>
    </h1>
</xsl:template>

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

</xsl:stylesheet>
生成されるコード
<h1>XSLT</h1>
<p>XSLT&XML</p>

Advertisement

ショートカット

634
634ブログ
このカテゴリのトップページに戻る
Incubator(Pukiwiki)
634ラボ
   UIコレクションギャラリー
   ZO-3ジェネレーター

サイト検索


Y!ログール