Etiqueta <x:set>
Biblioteca de etiquetas estándar de JSP
La etiqueta <x:set> establece una variable para el valor de una expresión XPath.
Si el valor de la expresión XPath es booleano, <x:set> configurará un objeto java.lang.Boolean; si es una cadena, configurará un objeto java.lang.String; si es un número, configurará un objeto java.lang.Number.
Formato de sintaxis
<x:set var="<string>" select="<string>" scope="<string>"/>
Atributos
La etiqueta <x:set> tiene los siguientes atributos:
| Atributo | Descripción | ¿Requerido? | Valor predeterminado |
|---|---|---|---|
| var | La variable que representa el valor de la expresión XPath. | Sí | Body |
| select | La expresión XPath que se debe evaluar. | no | Ninguno |
| scope | El ámbito del atributo var. | no | Page |
Demostración de ejemplo
El siguiente ejemplo nos muestra cómo usar la etiqueta <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>
El resultado de la ejecución es el siguiente:
BOOKS INFO: The price of the second book:[[book: null], [book: null]]
Otras extensiones