JSTL XML x:out Tag

The <x: out> tag is used to display the result of xml path expression and writes result to the jsp writer object.

Syntax Of <x: out> Tag

<x: out attributes/>

Attributes Of <x: out> Tag

  • select: To evaluate the particular object it specifies xml Xpath expression.
  • escapeXML: Accepts special character an convert it to their corresponding character entity code. The default value is true.

Example

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>

<html>
<head>

 <title> x:out Tags</title>

</head>
<body>

<h2>Fruits Information:</h2>

<c:set var="fruit">

<fruits>
    <fruit>
      <name>Grapes</name>
      <price>40/kg</price>
    </fruit>

 <fruit>
      <name>Orange</name>
      <price>30/kg</price>
    </fruit>

 <fruit>
      <name>Apple</name>
      <price>90/kg</price>
    </fruit>

</fruits>

</c:set>

<x:parse xml="${fruit}" var="output"/>
<b>The name of the fruit</b>:

<x:out select="$output/fruits/fruit[1]/name" /><br>

<b>The price of the orange</b>:

<x:out select="$output/fruits/fruit[3]/price" />

</body>
</html>

Details of the Code

  • <c:set var=”fruit”> tag is used to set the variable name which we want to display in the output.
  • <x:out select=”$output/fruits/fruit[1]/name” /> tag is used to display the particular fruit name in the output.
  • <x:out select=”$output/fruits/fruit[3]/price” /> tag is used to display the price of the particular fruit which we want.

Steps for Execution

Before executing the xml programs we should add jar files namely: xalan-2.7.0.jar

  • Save this file as example.jsp in your eclipse IDE.
  • Now select this jsp file, right mouse click and select Run as ->Run on server

Output

When the execution process is completed successfully we will get the following output :
x out tag output

Previous Tutorial : JSTL XML Tags Library :: Next Tutorial : JSTL XML x:forEach Tag

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*