Open In App

XSLT <value-of> Element

XSLT <value-of> Element is used to extract value from a node selected through name or expression. It is used to get value from XML and then display or output it. In this tutorial, we will learn to implement it.

XSLT is a programming language used to convert XML documents into other forms such as HTML, PDF, JPEG, PNG, etc.



Syntax

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

Attributes

Let us implement it in the following examples:

Example 1: Selecting from a single node.




<!--Tutorials.xml-->
  
<?xml version="1.0" encoding="UTF-8"?>
<tutorials>
  <programming>
    <title>Java</title>
    <description>Java is a programming language</description>
  </programming>
</tutorials>




<!-- index.xslt-->
  
<?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>
    <h1>Welcome to GeeksforGeeks</h1>
    <h3>XSLT value-of Element</h3>
  
    <b><p><xsl:value-of select="tutorials/programming/title"/></p></b>
    <p><xsl:value-of select="tutorials/programming/description"/></p>
  </body>
  </html>
</xsl:template>
  
</xsl:stylesheet>

Output:



Example 2: Displaying a list using value of.




<!--Tutorials.xml-->
  
<?xml version="1.0" encoding="UTF-8"?>
<tutorials>
  <programming>
    <title>Java</title>
    <description>Java is a programming language</description>
  </programming>
  <programming>
    <title>Python</title>
    <description>Python is a programming language</description>
  </programming>
  <programming>
    <title>PHP</title>
    <description>PHP is a programming language</description>
  </programming>
  <programming>
    <title>JavaScript</title>
    <description>JavaScript is a programming language</description>
  </programming>
  <programming>
    <title>C++</title>
    <description>C++ is a programming language</description>
  </programming>
</tutorials>




<!--index.xslt-->
  
<?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>
    <h1>Welcome to GeeksforGeeks</h1>
    <h3>XSLT value-of Element</h3>
  
    <ul>
    <xsl:for-each select="tutorials/programming">
    <li><b><xsl:value-of select="title"/></b>: <xsl:value-of select="description"/></li>
  
    </xsl:for-each>
    </ul>
  </body>
  </html>
</xsl:template>
  
</xsl:stylesheet>

Output:


Article Tags :