Core JSTL[c] Mastering the JSP Standard Tag Library
The JSTL XML actions are listed in Table 10.1. Table 10.1. XML Actions
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. |