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.


  • 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 −

selectCondition to evaluateYesNone


<%@ taglib prefix = "c" uri = "" %>
<%@ taglib prefix = "x" uri = "" %>
     <title>JSTL x:choose Tags</title>
      <h3>Books Info:</h3>
      <c:set var = "xmltext">
               <name>Padam History</name>
               <name>Great Mistry</name>
      <x:parse xml = "${xmltext}" var = "output"/>
         <x:when select = "$output//book/author = 'ZARA'">
            Book is written by ZARA
          <x:when select = "$output//book/author = 'NUHA'">
             Book is written by NUHA
             Unknown author.

The following result will be displayed −

Books Info:
Book is written by ZARA
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know