<x:set>-Tag
Das <x:set>-Tag setzt eine Variable auf den Wert eines XPath-Ausdrucks.
Wenn der Wert des XPath-Ausdrucks ein boolescher Typ ist, setzt <x:set> ein java.lang.Boolean-Objekt; wenn er eine Zeichenkette ist, setzt es ein java.lang.String-Objekt; wenn er eine Zahl ist, setzt es ein java.lang.Number-Objekt.
Syntax
<x:set var="<string>" select="<string>" scope="<string>"/>
Attribute
Das <x:set>-Tag hat die folgenden Attribute:
| Attribute | Beschreibung | Erforderlich | Standardwert |
|---|---|---|---|
| var | Die Variable, die den Wert des XPath-Ausdrucks darstellt | Ja | Body |
| select | Der auszuwertende XPath-Ausdruck | nein | Keine |
| scope | Der Gültigkeitsbereich des var-Attributs | nein | Page |
Beispiel
Das folgende Beispiel zeigt uns, wie man das <x:set>-Tag verwendet:
<%@ 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>
Die Ausgabe sieht wie folgt aus:
BOOKS INFO: The price of the second book:[[book: null], [book: null]]
Andere Erweiterungen
JSP-Standard-Tag-Bibliothek