Latest web development tutorials

XSLT <xsl:value-of> 元素

XSLT 元素參考手冊 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",则 "<" 将输出为 "&lt;"。默认是 "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>

嘗試一下»

下面的實例循環遍歷每個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>

嘗試一下»


XSLT 元素參考手冊 XSLT元素參考手冊