- 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
Can we have a switch statement in JSP for XPath expression?
The <x:choose> tag works like a Java switch statement. With this, you can choose between a number of alternatives. Where the switch statement has the case statements, the <x:choose> tag has the <x:when> tags. In a similar way, a switch statement has the default clause to specify a default action and the <x:choose> tag has the <x:otherwise> tag as the default clause.
Attribute
The <x:choose> tag does not have any attribute.
The <x:when> tag has one attributes which is listed below.
The <x:otherwise> tag does not have any attribute.
The <x:when> tag has the following attributes −
Attribute | Description | Required | Default |
---|---|---|---|
select | Condition to evaluate | Yes | None |
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 x:choose 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:choose> <x:when select = "$output//book/author = 'ZARA'"> Book is written by ZARA </x:when> <x:when select = "$output//book/author = 'NUHA'"> Book is written by NUHA </x:when> <x:otherwise> Unknown author. </x:otherwise> </x:choose> </body> </html>
The following result will be displayed −
Books Info: Book is written by ZARA
- Related Articles
- Can we test XPath expression in JSP?
- Can we have a return statement in a JavaScript switch statement?
- How to print XPath Expression result in JSP?
- How to write a switch statement in a JSP page?
- Can we use Switch statement with Strings in java?
- How to use a value of XPath expression result in JSP in a variable?
- Can we have a return statement in the catch or, finally blocks in Java?
- Can you use a switch statement around an enum in Java?
- Switch Statement in Java
- PHP switch Statement
- Java switch statement
- Switch case statement in C
- What are JSP declarations? In how many ways we can write JSP declarations?
- How to write a JSP Expression?
- Why can't variables be declared in a switch statement in C/C++?

Advertisements