Horje
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

  • select (expression): It is a required field and we need to provide the path or node to select and extract the data from. “/” is used to select data from subdirectories.
  • disable-output-escaping (yes/no): It is an optional parameter with a default value as yes. If yes, expressions like “<” will be displayed as it is. Otherwise, the expression would be displayed as “&lt;”.

Let us implement it in the following examples:

Example 1: Selecting from a single node.

XML

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

XML

<!-- 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:

Screenshot-2023-09-25-073740

Example 2: Displaying a list using value of.

XML

<!--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>

XML

<!--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:

Screenshot-2023-09-25-074511




Reffered: https://www.geeksforgeeks.org


Data Formats

Related
XSLT &lt;if&gt; Element XSLT &lt;if&gt; Element
XSLT &lt;key&gt; Element XSLT &lt;key&gt; Element
XPath Relative Path XPath Relative Path
XSLT &lt;sort&gt; Element XSLT &lt;sort&gt; Element
AIML &lt;set&gt; &amp; &lt;get&gt; Tags AIML &lt;set&gt; &amp; &lt;get&gt; Tags

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
14