10.2 XML Actions Overview

   

The JSTL XML actions are listed in Table 10.1.

Table 10.1. XML Actions

Action

Description

<x:choose>

XML version of <c:choose>

<x:forEach>

XML version of <c:forEach>

<x:if>

XML version of <c:if>

<x: otherwise >

XML version of <c:otherwise>

<x:out>

XML version of <c:out>

<x:param>

XML version of <c:param>; specifies a transformation parameter for an <x:transform> action

<x:parse>

Parses an XML document

<x:set>

XML version of <c:set>

<x:transform>

Transforms an XML document

<x:when>

XML version of <c:when>

Many of the actions listed in Table 10.1 access information stored in XML files. [2] Those actions access that information with XPath expressions, all of whichs are specified with attributes named select ; for example, the following code fragment displays all of the first and last names from the Rolodex XML file listed in Listing 10.1 on page 424:

[2] Those actions are <x:forEach>, <x:if>, <x:out>, <x:set>, and <x:when>.

 <x:forEach  select  ='$document//contact'>     <x:out  select  ='lastName'/>, <x:out  select  ='firstName'/>    <br> </x:forEach> 

In the preceding code fragment, the <x:forEach> action iterates over all of the Rolodex contacts with the XPath expression $document//contact , where $document represents the parsed XML file. Inside the body of that <x:forEach> action, <x:out> actions access the first and last names for each contact with the XPath expressions firstName and lastName , respectively.

Notice that most of the actions listed in Table 10.1 are XML counterparts of the JSTL Core actions; for example, the <x:forEach> and <x:out> actions are counterparts of the <c:forEach> and <c:out> actions. The main difference between the XML actions and their Core counterparts are the XML actions' select attributes, which specify an XPath expression. The only JSTL XML actions that do not have Core counterparts are <x:parse>, which parses an XML document, and <x:transform>, which uses XSLT to transform XML documents.

The following section provides a brief overview of XPath. If you are already familiar with XPath, you can commence reading at "Parsing XML" on page 432.

   


Core JSTL[c] Mastering the JSP Standard Tag Library
Core JSTL[c] Mastering the JSP Standard Tag Library
ISBN: 131001531
EAN: N/A
Year: 2005
Pages: 124

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net