XSLT - コメントの生成 (xsl:comment)

Advertisement

書式

<xsl:comment>
    コメント文
</xsl:comment>
コメント(<!-- -->)を生成する

<xsl:comment>
    コメント
</xsl:comment>

サンプルコード

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:comment>タイトル</xsl:comment>
            <xsl:apply-templates select="title"/>
            <xsl:comment>内容</xsl:comment>
            <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!ログール