以下は、動作保証をしないので、自己責任で確認のこと。プログラム等その他により生じたいかなる損害等その他について、責任を負いませんので、予めご了承してください。
■XMLファイルでXSLTファイルをリンクする書き方
<?xml version="1.0" encoding="Shift_JIS"?>
<?xml-stylesheet type="text/xsl" href="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="要素">
変換内容
</xsl:template>
</xsl:stylesheet>
■ルートノード
<xsl:template match="/">
■要素の選択設定
xsl:value-of
(例)
<xsl:value-of select="pagenum" />
■属性の生成
xsl:attribute
(例:画像)
<img>
<xsl:attribute name="src">
<xsl:value-of select="image" />
</xsl:attribute>
</img>
(例:リンク)
<a>
<xsl:attribute name="href">https://sites.google.com/view/cyberdesignstation/
<xsl:value-of select="@url" />
</xsl:attribute>
番号: <xsl:value-of select="pagenum" />
</a>
補足:属性内容を抽出する場合、属性名の前に@を付ける。
【basic_01.xml】
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="basic_01.xsl"?>
<datalist>
<dictionary no="1">
<datapage>
<pagenum>1</pagenum>
<data>AAA</data>
<note>test</note>
<wrdate>2020/09/01</wrdate>
<writer>A00A</writer>
<image>image/test.jpg</image>
</datapage>
</dictionary>
</datalist>
【basic_01.xsl】
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>サンプル 01</title>
</head>
<body>
<p align="center">表示</p>
<p><xsl:value-of select="datalist" /></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
【basic_02.xml】
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="basic_02.xsl"?>
<datalist>
<dictionary no="1">
<datapage url="SampleData001.html" pagenum="1">
<data>AAA</data>
<note>test</note>
<wrdate>2020/09/01</wrdate>
<writer>A00A</writer>
<image>image/test.jpg</image>
</datapage>
</dictionary>
</datalist>
【basic_02.xsl】
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>サンプル02 XSLTスタイルシート</title>
<link rel="stylesheet" type="text/css" href="Sample.css" />
</head>
<body>
<p align="center">要素表示</p>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="poem">
<table border="0" width="500" align="center">
<tr>
<th>
<a>
<xsl:attribute name="href">https://sites.google.com/view/cyberdesignstation/
<xsl:value-of select="@url" />
</xsl:attribute>
番号: <xsl:value-of select="pagenum" />
</a>
</th>
<th><xsl:value-of select="writer" /></th>
<th><xsl:value-of select="wrdate" /></th>
</tr>
<tr>
<td colspan="2">Data: <xsl:value-of select="data" /></td>
</tr>
<tr>
<td colspan="2">備考: <xsl:value-of select="note" /></td>
</tr>
<tr>
<td>図</td>
<td>
<img>
<xsl:attribute name="src">
<xsl:value-of select="image" />
</xsl:attribute>
</img>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
©Hirotoshi Takano