xml
  1. xml-xsl-value-of

XML xsl:value-of

The xsl:value-of element is used to output the value of a selected node.

Syntax

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

Example

<xsl:value-of select="title" />

Output

The Hobbit

Explanation

The xsl:value-of element takes an xpath_expression as the value of the select attribute, which selects the node to be outputted. The value of the selected node is then outputted as text.

The disable-output-escaping attribute can be used to output special characters such as <, >, and & as is, rather than as their corresponding HTML entities. This is useful when the output is intended to be used as raw text and not as HTML.

Use

xsl:value-of is primarily used to output the value of a node in the final output. It is commonly used in conjunction with xsl:for-each to iterate over a set of nodes and output their values.

Important Points

  • xsl:value-of only outputs the value of the selected node, and not any of its attributes or child nodes.
  • xsl:value-of automatically disables output escaping for certain characters such as quotes and apostrophes, so it is generally not necessary to use the disable-output-escaping attribute.
  • The select attribute can also take complex xpath expressions, allowing for more specific node selection.

Summary

xsl:value-of is an important core element in XSLT that is used to output the value of a selected node. It is commonly used in conjunction with xsl:for-each to iterate over a set of nodes and output their values. The select attribute takes an xpath expression that selects the node to be outputted, and the optional disable-output-escaping attribute can be used to output special characters as is.

Published on: