<X: set> tag
<X: set> tag to set the value of a variable XPath expressions.
If the value of the XPath expression is boolean type, then <x: set> java.lang.Boolean will set a target, if the string, set a java.lang.String object, and if the figures, set a java.lang .Number object.
Syntax
<x:set var="<string>" select="<string>" scope="<string>"/>
Attributes
<X: set> tag has the following attributes:
Attributes | description | If necessary | Defaults |
---|---|---|---|
var | On behalf of worthy variable XPath expression | Yes | Body |
select | XPath expression to be calculated | no | no |
scope | Scope var attribute | no | Page |
Examples Demo
The following example demonstrates how to use the <x: set> tag:
<%@ 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>
Results are as follows:
BOOKS INFO: The price of the second book:[[book: null], [book: null]]