Skip to main content

XSLT <xsl:value-of> Element

The <xsl:value-of> element is used to extract the value of a selected node.

<xsl:value-of> Element

The <xsl:value-of> element can be used to extract the value of an XML element and add it to the output stream of the transformation:

Syntax

The syntax of <xsl:value-of> is as follows:

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

Attributes

The table describes the meaning of the attributes of <xsl:value-of>:

NameDescription
selectXPath Expression to be evaluated in current context.
disable-output-escapingDefault-"no". If "yes", output text will not escape xml characters from text.

Example

Let's see an example:

books.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="books.xsl"?>

<bookstore>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery Tips</title>
<author>Tom Nolan</author>
<year>2022</year>
<price>39.99</price>
</book>
<book category="web">
<title lang="en">Learn XML</title>
<author>Tutorial Reference</author>
<year>2022</year>
<price>9.99</price>
</book>
</bookstore>
books.xsl
<?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>The Bookstore</h2>
<table border="1">
<tr bgcolor="#6565d5">
<th>Title</th>
<th>Author</th>
<th>Year</th>
<th>Price</th>
</tr>
<xsl:for-each select="bookstore/book">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="year"/></td>
<td><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
note

The select attribute contains an XPath expression.

An XPath expression works like navigating a file system and a forward slash (/) selects subdirectories.

note

In the next chapter you will learn how the <xsl:for-each> element works to loop through the XML elements and display all the records.