Home TOC |
![]() ![]() ![]() |
XML Tags
A key aspect of dealing with XML documents is to be able to easily access their content. XPath, a W3C recommendation since 1999, provides an easy notation for specifying and selecting parts of an XML document. The JSTL XML tag set is based on XPath.
The XML tags use XPath as a local expression language; XPath expressions are always specified using attribute
select
. This means that only values specified forselect
attributes are evaluated using the XPath expression language. All other attributes are evaluated using the rules associated with the currently active global expression language.This release of the tutorial summarizes the XML tags but does not illustrate their use in the Duke's Bookstore application.
Table 3 XML Tags Area
Function
Tags
TLD
Prefix
XML
Core
<parse>
<expr>
<set>
/jstl-x
x
Flow Control
<forEach>
<if>
<choose> <when> <otherwise>
Transformation
<transform>
<param>
<transformer>
Core Tags
The core set of XML tags provides the basic functionality to easily parse and access XML data.
The
parse
tag parses an XML document and saves the resulting object in the JSP scoped attribute specified by attributevar
.The
expr
andset
tags parallel the behavior described in Expression Tags for the XPath local expression language.The
expr
tag evaluates an XPath expression on the current context node and outputs the result of the evaluation to the currentJspWriter
object.The
set
tag evaluates an XPath expression and sets the result into a JSP scoped attribute specified by attributevar
.Flow Control Tags
The XML flow control tags parallel the behavior described in Flow Control Tags for the XPath expression language.
<forEach> <if> <choose> <when> <otherwise>Transformation Tags
The
transform
tag applies a transformation, specified by a XSLT stylesheet set by the attributexslt
, to an XML document, specified by the attributexml
. If thexml
attribute is not specified, the input XML document is read from the tag's body content.The
param
subtag can be used along withtransform
to set transformation parameters. The attributesname
andvalue
are used to specify the parameter. The value attribute is optional. If it is not specified the value is retrieved from the tag's body.Sometimes the same stylesheet transformation needs to be applied multiple times to different source XML documents. Instead of processing the stylesheet on each invocation of
transform
, a more efficient approach is to process the transformation stylesheet once, and then save this transformer object for successive transformations. Thetransformer
tag can be used in collaboration with thetransformer
attribute oftransform
to efficiently reuse a transformation stylesheet.
Home TOC |
![]() ![]() ![]() |