XSLT and lt;xsl: value-of-the-gt; elements
May 28, 2021
XSL T
Table of contents
XSLT
and lt;xsl: value-of-the-gt;
elements
The XSLT-lt;xsl:value-of-gt; element has two functions that you can learn about through the content of this section.
XSLT element reference manual
Definitions and usages
The value-of-of-content element extracts the value of the selected node.
The value-of-content element can be used to pick the value of an XML element and output it.
Grammar
<xsl:value-of select="expression" disable-output-escaping="yes|no" />
Property
Attributes
|
value
|
describe
|
select
|
expression
|
Required.An XPath expression specifies which node / attribute to extract values.It works similar to the navigation file system that selects subdirectory through the forward slash (/).
|
disable-output-escaping
|
yes
no
|
可选。如果值为 "yes",通过实例化 <xsl:text> 元素生成的文本节点在输出时将不进行任何转义。比如 "<" 将输出为 "<"。如果值为 "no",则 "<" 将输出为 "<"。默认是 "no"。
|
The following example gets the value of the first title and artist elements and places them in the table:
Instance 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>
The following instance loops through each cd element and creates a table row with the values of title and artist for each cd element:
Instance 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 element reference manual
Related articles
XML elements