Introduction
This tutorial is for developers who want to create content that can be repurposed for a variety of presentations without affecting the original data. It explains how to create a Java servlet that determines the means by which the data is being viewed and uses XML and XSLT to provide the appropriate presentation. It also includes information on using the servlet as the basis for a Web service.
This tutorial uses Java to transform XML data, but the XSLT concepts are common to other languages as well. It assumes that you are familiar with XML and with XSL Transformations, but the actual transformations themselves are a minor part of the tutorial. An understanding of Java development is helpful, but not required.
As the Web grows, it is increasingly being pulled in opposite directions. On the desktop, Web pages and the browsers that display them are becoming more and more complex as companies strive for presentations that are eye-catching while still being functional. At the same time, Web content is increasingly being repurposed for devices such as pagers and mobile phones that, while more robust than they used to be, are still incapable of handling some of these more complex pages. In addition, the future will see more and more content accessed as Web services, which typically requires an entirely different structure.
This tutorial takes a series of headlines stored in an XML file and explains how to automatically choose the proper XSLT style sheet to display them in a traditional browser or a mobile browser, and to return them as the response for a Web service, both through a proxy created in WebSphere Studio V5 and directly.
The tutorial covers:
- The basic environment
- Creating a servlet
- Performing a transformation
- Selecting the appropriate style sheet
- Creating and accessing the Web service
You can gain a good understanding of the concepts behind this tutorial without actually executing the examples, but should you choose to follow along, the following tools should be installed and tested prior to starting the tutorial:
- Although not required, all of the necessary tools for creating XML and XSLT files and Java classes, as well as creating the Web service proxy, are available within IBM's WebSphere Studio V5. WebSphere Studio also includes a test server environment for running the servlet, so you can accomplish all of the development in this tutorial with this one tool.
- To see the mobile phone examples, you can download the Openwave SDK, which includes a simulator that works over HTTP. Download the SDK at http://developer.openwave.com/download/product_62.html. The examples use only HTTP, so the WAP extension is not necessary for this tutorial. (Phone screenshots provided by Openwave.)
If you choose not to use WebSphere Studio or another development environment, you can also complete the examples using:
- A text editor to create and XML and XSLT files.
- A Java development environment such as Sun's Java 2 Standard Edition version 1.4, available at http://java.sun.com/j2se/1.4/. Version 1.4 has built-in XML support.
- A servlet-capable Web server such as IBM's WebSphere Application Server, or Apache Tomcat, available at http://tomcat.apache.org/tomcat-4.1-doc/. (Even if you use WebSphere Studio to create and test the application, you'll need a server on which to deploy your production application.)




