<x:choose>就像一个Java的switch语句,它可以让你在一些替代之间作选择。switch语句中有case语句,<x:choose>标签具有<x:when>标签。switch语句中有默认的子句来指定一个默认的行为,类似方式如:<x:choose>有<x:otherwise>作为default语句。
<x:choose>标签没有任何属性。
<x:when>标签有一个属性,将在下文列出。
<x:otherwise> 标签没有任何属性。
<x:when>标签具有以下属性:
属性 | 描述 | 必须 | 默认 |
---|---|---|---|
select | 条件评估 | Yes | None |
<%@ 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>这将产生以下输出结果:
BOOKS INFO:Book is written by ZARA |