XSLT - 外部ファイルの取り込み (xsl:include)

Advertisement

書式

<xsl:include href="インクルードするファイル"/>

<xsl:include href="include.xsl"/>
include.xsl の内容を上記コード位置に記述した場合と同じ動作を行う。

サンプルコード

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

<book>
    <title>XML</title>
    <price>1000</price>
</book>
style.xsl
<?xml version="1.0" encoding="Shift_JIS"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:include href="include.xsl"/>

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

<xsl:template match="book">
    <xsl:value-of select="title"/><br/>
    <xsl:value-of select="price"/>
</xsl:template>

</xsl:stylesheet>
生成されるコード
<html>
<head>
<title>XSLT</title>
</head>
<body>
XML<br />
1000
</body>
</html>

Advertisement

ショートカット

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

サイト検索

Google

Web サイト内

Y!ログール