The JavaTM Web Services Tutorial
Home
TOC
PREV TOP NEXT

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 for select attributes are evaluated using the XPath expression language. All other attributes are evaluated using the rules associated with the currently active global expression language.

For information on XPath see:

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 attribute var.

The expr and set 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 current JspWriter object.

The set tag evaluates an XPath expression and sets the result into a JSP scoped attribute specified by attribute var.

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 attribute xslt, to an XML document, specified by the attribute xml. If the xml attribute is not specified, the input XML document is read from the tag's body content.

The param subtag can be used along with transform to set transformation parameters. The attributes name and value 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. The transformer tag can be used in collaboration with the transformer attribute of transform to efficiently reuse a transformation stylesheet.

Home
TOC
PREV TOP NEXT