Accessing Node Values

You can access the value of a node with the <xsl:value-of> element. This element has two possible attributes:

  • select (mandatory). The value that will be output. Set to an expression.

  • disable-output-escaping (optional). Indicates that characters such as “>” should be sent to the output as is, without being changed to “&gt”. Set to “yes” or “no”.

The <xsl:value-of> element is always empty.

You can use the select attribute to indicate which node you want to get the value. For example, you might want to get the value of the <NAME> node in each <PLANET> element, which is the text enclosed in that node. You can do that like this:

Listing 2.4. Using <xsl:value-of>
 <?xml version="1.0"> <xsl:stylesheet version="1.0" xmlns::xsl="http://www.w3.org/1999/XSL/Transform"> ...

Get Inside XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.