หากนิพจน์ XPath ให้ผลลัพธ์เป็นบูลีน
คุณสมบัติ
| แอตทริบิวต์ | คำอธิบาย | จำเป็น | ค่าเริ่มต้น |
|---|---|---|---|
| var | ตัวแปรที่ถูกตั้งค่าเป็นค่าของนิพจน์ XPath | ใช่ | ร่างกาย |
| เลือก | นิพจน์ XPath ที่จะประเมิน | ไม่ | ไม่มี |
| ขอบเขต | ขอบเขตของตัวแปรที่ระบุในแอตทริบิวต์ var | ไม่ | หน้า |
ตัวอย่าง
ตัวอย่างต่อไปนี้จะแสดงวิธีการใช้
<%@ 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 ด้านบน ผลลัพธ์ต่อไปนี้จะปรากฏขึ้น -
Books Info: The price of the second book:[[book: null], [book: null]]