<x:set> Tag

JSP 标准标签库JSP Standard Tag Library

The <x:set> tag sets a variable to the value of an XPath expression.

If the value of the XPath expression is a boolean type, <x:set> will set a java.lang.Boolean object; if it is a string, it sets a java.lang.String object; if it is a number, it sets a java.lang.Number object.

Syntax

<x:set var="<string>" select="<string>" scope="<string>"/>

Attributes

The <x:set> tag has the following attributes:

Attribute Description Required Default Value
var The variable representing the value of the XPath expression Yes Body
select The XPath expression to evaluate no None
scope The scope of the var attribute no Page


Example

The following example shows us 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>

The output is as follows:

BOOKS INFO:
The price of the second book:[[book: null], [book: null]]

JSP 标准标签库JSP Standard Tag Library

Other Extensions