<x:set> タグ
<x:set>タグは、XPath式の値に対して変数を設定します。
XPath式の値がboolean型の場合、<x:set>はjava.lang.Booleanオブジェクトを設定します。文字列の場合はjava.lang.Stringオブジェクトを設定し、数値の場合はjava.lang.Numberオブジェクトを設定します。
構文形式
<x:set var="<string>" select="<string>" scope="<string>"/>
属性
<x:set>タグには次の属性があります:
| 属性 | 説明 | 必須かどうか | デフォルト値 |
|---|---|---|---|
| var | XPath式の値を表す変数 | である | Body |
| select | 評価する必要があるXPath式 | 否 | 无 |
| scope | var属性のスコープ | 否 | Page |
実例デモ
次の例では、<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 x:set 标签</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>
実行結果は次のとおりです:
BOOKS INFO: The price of the second book:[[book: null], [book: null]]
その他の拡張機能
JSP 標準タグライブラリ