All of Session 8 — the tag libraries, the two APIs, and the places the slides need a correction.

The two tag libraries

PrefixURIGives you
x http://java.sun.com/jsp/jstl/xml x:transform, x:parse, x:set, x:eval, x:output
c http://java.sun.com/jsp/jstl/core c:set and c:import, which feed the XML library its input

These are the JSTL 1.2 URIs, matching the rest of the course. Tomcat ships the implementation, so there is nothing to install — but the jstl-1.2.jar API jar is in WEB-INF/lib so the pages compile.

Two ways to get XML into a JSP

TagsAPI
For output — contentType="text/xml" on the page directive
For formatting x:transform JAXP TransformerFactory
For reading values x:parse / x:eval JAXP DocumentBuilderFactory and DOM

Choosing between them is the whole of Session 8. If you want HTML on the page, transform. If you want individual values — a title, a count, a total — parse and read them.

Slide corrections

Xerces and Xalan are not needed. Slide 13 says to copy XercesImpl.jar and xalan.jar into Tomcat's lib folder. That instruction dates from the Java 1.4 era. Since Java 9 an XML parser and an XSLT processor are part of the JDK itself, and DocumentBuilderFactory.newInstance() and TransformerFactory.newInstance() find them automatically. This project runs on Java 21 with nothing copied anywhere. s8-04 is the example that would have needed Xerces.

x:transform does not need docId or a var here. The slide calls it bare, and that is correct: with no var, the result document is written to the response, which is exactly what a formatting demo wants. Add var="out" if you would rather capture the HTML in a variable and decide later.

The slide's c:import URL is hard-coded. http://localhost:8086/JSPDemo/style.xsl only resolves on one machine. Use a context-relative URL.

Do not prepend the context path to a c:import URL. c:import already prepends it to a /-rooted URL, so writing ${pageContext.request.contextPath}/xml/style.xsl produces /jsp-demo/jsp-demo/xml/style.xsl and a 404. This is the same trap as s7-03.

XML output rules (s8-03)

Reading values: the traps

Where things live

FilePurpose
xml/books.xml the source document; the xml-stylesheet instruction at its top makes a browser transform it directly
xml/style.xsl the stylesheet: identity-plus-HTML, with sum(book/price) for the total row

Back to the example index