Latest web development tutorials

XSLT <xsl: value-of> element

XSLT Elements Reference Manual XSLT Elements Reference Manual

Definition and Usage

<Xsl: value-of> element can extract the value of the selected node.

<Xsl: value-of> element can be used to select the value of an XML element, and outputs it.


grammar

<xsl:value-of select="expression" disable-output-escaping="yes|no" />

Attributes

属性 描述
select expression 必需。一个 XPath 表达式,规定了从哪个节点/属性来提取值。它的工作原理与通过正斜杠(/)选择子目录的导航文件系统类似。
disable-output-escaping yes
no
可选。如果值为 "yes",通过实例化 <xsl:text> 元素生成的文本节点在输出时将不进行任何转义。比如 "<" 将输出为 "<"。如果值为 "no",则 "<" 将输出为 "&lt;"。默认是 "no"。


Examples

The following examples Gets the value of the first title and artist elements, and placed in the table:

Example 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>

try it"

The following example loops through each cd element, and create a table with a row for each cd element of the title and artist of values:

Example 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>

try it"


XSLT Elements Reference Manual XSLT Elements Reference Manual