IBM Version 5 Universal Remote User Manual


 
230 The XML Files: Development of XML/XSL Applications Using WebSphere Studio
}
CustomerXSLServlet: This is responsible for applying the XSL to the DOM
generated from the CustomerXML. This process transforms and formats the
DOM information into a rendered result. This is called styling. For the styling
to be possible, two components come together: XSL Transormations (XSLT),
which allows for a reorganization of information; and XSL, which specifies the
formatting of the information for rendering. A XSL processor takes a
stylesheet consisting of a set of XSL commands, and transforms an input
XML document. Studying the code for this servlet, we noticed the following:
The init method does the necessary configuration and initialization for the
sevlet's operation. For the servlet to handle the process of transforming
the XML data to the desirable format, based on an XSL stylesheet, the
servlet needs to do some configuration steps before invoking the XSLT
processor. The init method first creates a new instance of the
TransformerFactory class.
Having the stylesheet XSL files present in the file system, the Transformer
factory instance needs to reference them. So the servlet creates the
templates objects using the XSL files. A templates object is a compiled
representation of a XSL file. Compilation of XSL is provided by JAXP.
Invoking the newTemplates method of the TransformerFactory, and
passing to it an XSL file, it processes the file, and generates a compiled
representation of that XSL file in the form of the templates object.
This templates object may then be used concurrently across multiple
threads. Creating a templates object allows the TransformerFactory to do
detailed performance optimization of transformation instructions, without
penalizing runtime transformation. As shown in Example 10-2, the init
method retrieves the files using the path specifies in the begining of the
method, and creates the templates objects using the transformer factory.
The XSLT processor should used these compiled instances of the style
sheets to transform a XML document. Exceptions are thrown if the servlet
cannot locate the XSL files in the specified location, or if the files contain
errors.
Example 10-2 Source code for CustomerXSLServlet init method
public void init(ServletConfig config)
throws ServletException
{ super.init(config);
TransformerFactory transFact =
TransformerFactory.newInstance();
String xslName = "/WEB-INF/xsl/Customer.xsl";
String xslResult = "/WEB-INF/xsl/CustomerResult.xsl";
try
{ URL stylesheetURL =