XSLT <xsl:value-of>要素
XSLT 要素リファレンス
定義と使い方
<xsl:value-of> 要素は、選択されたノードの値を抽出できます。
<xsl:value-of> 要素は、XML 要素の値を選択して出力するために使用できます。
構文
<xsl:value-of
select="expression"
disable-output-escaping="yes|no" />
属性
| 属性 | 值 | 説明 |
|---|---|---|
| select | expression | 必須。どのノード/属性から値を抽出するかを指定する XPath 式。スラッシュ(/)でサブディレクトリを選択するファイルシステムのナビゲーションと同様に機能します。 |
| disable-output-escaping | yes no |
省略可能。値が "yes" の場合、<xsl:text> 要素をインスタンス化して生成されたテキストノードは、出力時にエスケープされません。たとえば、"<" は "<" として出力されます。値が "no" の場合、"<" は "<" として出力されます。デフォルトは "no" です。 |
例
次の例は、最初の title 要素と artist 要素の値を取得し、テーブルに配置します:
例 1
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td><xsl:value-of select="catalog/cd/title" /></td>
<td><xsl:value-of select="catalog/cd/artist" /></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td><xsl:value-of select="catalog/cd/title" /></td>
<td><xsl:value-of select="catalog/cd/artist" /></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
試してみる »
次の例は、各 cd 要素をループし、各 cd 要素の title と artist の値を持つテーブルの行を作成します:
例 2
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
試してみる »
XSLT 要素リファレンス その他の拡張