• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

JSTL XML x:set Tag

February 27, 2014 //  by Krishna Srinivasan//  Leave a Comment

The <x: set> tag is used to store the result of xml path expression in scoped variable.

Syntax of <x: set> Tag

<x: set attributes/>

Attributes of <x: set> Tag

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>JSTL Tags</title>
</head>
<body>

<h3>Fruits Information:</h3>

<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"/>
<x:set var="fragment" select="$output/fruits/fruit[3]/price"/>

<b>The price of the Apple</b>:
<x:out select="$fragment" />

</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:parse xml=”${fruit}” var=”output”/> tag is used to parse the xml content and the result is been stored in specified variable.
  • <x:set var=”fragment” select=”$output/fruits/fruit[3]/price”/> tag is used to store the result in xml path expression using the attribute var and select.
  • <x:out select=”$output/fruits/fruit[3]/price” /> tag is used to display the price of the particular fruit which we want.

Steps for ExecutionBefore executing the xml programs we should add jar files in eclipse 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

OutputThe below is screen shot of the output.x set tag output

Attributes Description
select To evaluate the particular object it specifies xml Xpath expression.
var It specifies the variable name which stores parse xml document.
scope The Scope into which the variable attribute has to be set.

 

Previous Tutorial : JSTL XML x:if  Tag :: Next Tutorial : JSTL XML x:parse Tag

Category: Java EETag: JSTL Tutorials

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.

Previous Post: « JSTL XML x:if Tag
Next Post: JSTL XML x:parse Tag »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

EJB 3.0 Timer Services

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact