- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use a value of XPath expression result in JSP in a variable?
The <x:set> tag sets a variable to the value of an XPath expression.
If the XPath expression results in a boolean, <x:set> tag sets a java.lang.Boolean object; for a string, java.lang.String; and for a number, java.lang.Number.
Attribute
The <x:set> tag has the following attributes −
Attribute | Description | Required | Default |
---|---|---|---|
var | A variable that is set to the value of the XPath expression | Yes | Body |
select | The XPath expression to be evaluated | No | None |
scope | Scope of the variable specified in the var attribute | No | Page |
Example
Following example will show how to use the <x:set> tag −
<%@ 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>Books Info:</h3> <c:set var = "xmltext"> <books> <book> <name>Padam History</name> <author>ZARA</author> <price>100</price> </book> <book> <name>Great Mistry</name> <author>NUHA</author> <price>2000</price> </book> </books> </c:set> <x:parse xml = "${xmltext}" var = "output"/> <x:set var = "fragment" select = "$output//book"/> <b>The price of the second book</b>: <c:out value = "${fragment}" /> </body> </html>
Access the above JSP, the following result will be displayed −
Books Info: The price of the second book:[[book: null], [book: null]]
- Related Articles
- How to print XPath Expression result in JSP?
- How to print result of a java expression in JSP?
- How to set result of a java expression in a property in JSP?
- Can we test XPath expression in JSP?
- Can we have a switch statement in JSP for XPath expression?
- How to write a JSP Expression?
- How to use a filter in JSP?
- How to use a final or effectively final variable in lambda expression in Java?
- How to pass a date variable in sql query in a JSP?
- How to use time zone in a JSP?
- How to store Query Result in a variable using MySQL?
- How to remove a java variable from current scope in JSP?
- How to print a date using JSP Expression?
- How can we use SET statement to assign a SELECT result to a MySQL user variable?
- Set the result of a query to a variable in MySQL?

Advertisements