XSLT - 次のテンプレートへ処理を送る (xsl:apply-templates)

Advertisement

書式

<xsl:apply-templates select="次に処理をするノード"/>
xsl:apply-templates は xsl:template の子要素として指定する。指定したノードに対して処理を移動する(サンプルコード参照)

<xsl:apply-templates select="."/>

サンプルコード

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="document">
	<html>
	<head>
	<title>XSLT</title>
	</head>
	<body>
	<xsl:apply-templates select="title"/>
	<xsl:apply-templates select="body"/>
	</body>
	</html>
</xsl:template>

<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>
生成されるコード
<html>
<head>
<title>XSLT</title>
</head>
<body>
<h1>XSLT</h1>
<p>XSLT&XML</p>
</body>
</html>

Advertisement

ショートカット

634トップページ
このカテゴリのトップページに戻る
634ラボ

サイト検索

Google

Web サイト内

Y!ログール