Cover Image for XSLT xsl:value-of
125 views

XSLT xsl:value-of

In XSLT (Extensible Stylesheet Language Transformations), the xsl:value-of element is used to output the value of a selected node in the input XML document. It is one of the primary elements used to generate text or data in the output of an XSLT transformation.

The basic syntax of the xsl:value-of element is as follows:

<xsl:value-of select="xpath-expression" [disable-output-escaping="yes|no"] />
  • select: The XPath expression that selects the node whose value will be output in the result. The expression should evaluate to a single node or a node-set.
  • disable-output-escaping: This attribute is optional and can have the values “yes” or “no.” If set to “yes,” any special characters in the output (e.g., &, <, >) will be replaced by their corresponding character entities. If set to “no” (default), the characters will be output as is.

Here’s an example of using xsl:value-of to output the titles of all books in an HTML list:

<!-- Input XML Document -->
<bookstore>
  <book>
    <title>Book 1</title>
    <author>Author 1</author>
  </book>
  <book>
    <title>Book 2</title>
    <author>Author 2</author>
  </book>
</bookstore>

<!-- XSLT Stylesheet -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <body>
        <ul>
          <xsl:for-each select="bookstore/book">
            <li><xsl:value-of select="title" /></li>
          </xsl:for-each>
        </ul>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

In this example, the XSLT transformation will create an HTML list (<ul>) containing list items (<li>) for each book title extracted from the input XML document.

xsl:value-of is a versatile element in XSLT used to extract and display data from the input XML document in the desired output format. It is commonly used with xsl:for-each, xsl:if, and other control structures to generate dynamic content based on the input data.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS