XSLT <xsl:value-of> 元素
<xsl:value-of> 元素用于提取所选节点的值。
<xsl:value-of> 元素
<xsl:value-of> 元素可用于提取 XML 元素的值,并将其添加到转换的输出流中。
示例
<?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>
<body>
<h2>我的 CD 收藏</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>标题</th>
<th>艺术家</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>
自己动手试一试 »
示例解释
注意: 上例中的 select 属性包含一个 XPath 表达式。XPath 表达式的工作方式类似于导航文件系统;正斜杠 (/) 用于选择子目录。
上一个示例的结果有点令人失望;只有一行数据从 XML 文档复制到输出中。在下一章中,您将学习如何使用 <xsl:for-each> 元素来遍历 XML 元素,并显示所有记录。