Java Reference
In-Depth Information
Figure 15-2: Search-results page
As you may have noticed in Listing 15-4 , the images are obtained from a servlet that returns Blobs from
the Photos Table in the database. This servlet is derived from the Large Object servlet example of
Chapter 14 , Listing 14-8 .
If you refer to Listing 15-4 , you will notice that the images can be clicked to access a detail page for the
vehicle. The next section discusses the creation of both the detail page and an edit page from the same
XML formatted result set using an XSL transform
Using XSL to Create a Web Page from a SQL Query
The previous example shows how to create a Web page using JSP to manage its formatting. This
approach has the disadvantage that you have to understand how to use Java Server Pages to modify
your display format. Another way to manage database-driven Web page formatting is to use an XSL
stylesheet to transform XML data into HTML. A simple change to the XSLT transforms the same page
of XML into a completely different HTML page.
How XSLT Works
Extensible Stylesheet Language (XSL) provides the user with a means of transforming XML documents
from one form to another. In practice, this means you can retrieve information from a database as basic,
content-oriented XML and use an XSL stylesheet to convert it into a human-readable document.
XSL actually combines two major components: a transformation language and a formatting language.
Each of these is an XML dialect. The transformation language, XSLT, is used to define rules for the
conversion of one XML document into another, and the formatting component deals with formatting the
output.
From the viewpoint of generating HTML, the important component is the XSL Transformation Language
(XSLT). To perform a transformation, an XSLT processor reads both an XML document and an XSLT
stylesheet and outputs a new XML document.
Applying an XSL transform in Java is very simple, as you can see from the example in Listing 15-5 . The
xalan library methods do most of the work.
Search WWH ::




Custom Search