XSLT <值>
XSLT <xsl:value-of> 元素
<xsl:value-of> 元素用於提取某個選定節點的值。
<xsl:value-of> 元素
<xsl:value-of> 元素用來擷取某個XML 元素的值,並將值加到轉換的輸出流中:
實例
<?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>
<h2>My CD Collection</h2>
<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>
<h2>My CD Collection</h2>
<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>
試試看»
#實例解釋
注意:在上面的實例中,select 屬性的值是一個XPath 表達式。這個 XPath 表達式的工作方式類似於定位某個檔案系統,在其中正斜線(/)可選擇子目錄。
上面實例的結果有一點小缺陷,只有一行資料從 XML 文件被複製到輸出。在下一章中,您將學習如何使用 <xsl:for-each> 元素來循環遍歷 XML 元素,並顯示所有的記錄。