<x:set >
《x:set》标记将变量设置为XPath表达式的值。
如果XPath表达式导致布尔值,则《x:set》标记设置java.lang.Boolean对象; 对于字符串,java.lang.String; 对于一个数字,java.lang.Number。
属性 (Attribute)
《x:set》标签具有以下属性 -
属性 | 描述 | 需要 | 默认 |
---|---|---|---|
var | 一个设置为XPath表达式值的变量 | Yes | Body |
select | 要评估的XPath表达式 | No | None |
scope | var属性中指定的变量的范围 | No | Page |
例子 (Example)
以下示例将说明如何使用《x:set》标记 -
<%@ 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>
访问上面的JSP,将显示以下结果 -
<h3>Books Info:</h3>
<b class="notranslate">The price of the second book</b>:[[book: null], [book: null]]