XSLT <xsl:value-of>
❮ XSLT 元素參考
定義和用法
The <xsl:value-of> element extracts the value of a selected node.(<xsl:value-of> 元素提取所選節點的值。)
The <xsl:value-of> element can be used to select the value of an XML element and add it to the output.(<xsl:value-of> 元素可用於選擇 XML 元素的值並將其新增到輸出中。)
語法
<xsl:value-of select="expression" disable-output-escaping="yes|no" />
屬性
Attribute | 值 | 描述 |
---|---|---|
select | expression | Required. An XPath expression that specifies which node/attribute to extract the value from. It works like navigating a file system where a forward slash (/) selects subdirectories.(必需。一個 XPath 表示式,用於指定要從中提取值的節點/屬性。它的工作方式類似於導航檔案系統,其中正斜槓 (/) 選擇子目錄。) |
disable-output-escaping | 是 no |
Optional. "yes" indicates that special characters (like "<") should be output as is. "no" indicates that special characters (like "<") should be output as "<". Default is "no"(可選。“yes”表示特殊字元(如“<”)應按原樣輸出。“no”表示特殊字元(如“<”)應輸出為“<”。預設值為“no”) |
示例
The example below puts the values from the first title and artist elements and puts it in a table(下面的示例將第一個 title 和 artist 元素的值放入表格中)
示例 1
<?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>
<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>
自己動手試一試 »The example below loops trough each cd element and creates a table row with the values from title and artist for each cd element(下面的示例迴圈遍歷每個 cd 元素,併為每個 cd 元素建立包含 title 和 artist 值的表格行)
示例 2
<?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>
<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 元素參考