Parts 1 and 2 of this series introduced you to the idea of personalizing your site by creating different looks using XSL style sheets. In this article, we begin to turn control over to the user, enabling you to choose the style sheet to be used. In Part 2, transformations were performed in the browser, but now we will look at transforming pages on the server, eliminating browser incompatibilities. We will discuss sample code for both Active Server Page and Java implementations.
Configure the Server
The first step is to establish server-side transformation in your environment of choice. A plethora of choices exists, but the code samples for this article assume that you are using one of the following two configurations. Feel free to use your favorite language, Web server, and XSLT processorand adapt the code accordingly.
The ASP installation we will use in this article is implemented in Active Server Pages 3.0 pages on Internet Information Server 4.0 or above, and MSXML3 or above.
On Windows9x systems, you can download and install Personal Web Server. At the time of this writing, the Windows NT4 Option Pack (which provides the version-appropriate software) is available from http://www.microsoft.com/ntserver/nts/downloads/recommended/NT4OptPk/default.asp. (Note that PWS is not supported for Windows ME.)
MSXML is installed as part of the latest Microsoft browsers, or you can download MSXML3 directly from http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/772/msdncompositedoc.xml.
Before proceeding, make sure that both packages are installed and working properly. Download XSLTPersSource3.zip, and copy the contents of the aspgeneral folder to the Web server's main directory or document root. If you'd rather skip to the completed pages instead of following along, they are contained in the asppages folder.
The Java language installation uses the Tomcat Web server with Xalan as the XSL processor. For simplicity's sake, the examples will use servlets, but the same concepts can be easily adapted for Java Server Pages.
All software necessary for server-side transformations using Java are available from the Apache project. Download Tomcat from http://jakarta.apache.org/tomcat/index.html and Xalan from http://xml.apache.org/xalan-j/index.html.
Before proceeding, make sure that both packages are installed and working properly, and that your classpath information has been set in the control panel or autoexec.bat file so Tomcat can find the Xalan files.
Download XSLTPersSource3.zip, and copy the contents of the javageneral folder to the Web server's main directory in webapps/root. If you'd rather skip to the completed servlets instead of following along, they are contained in the javaclasses folder. These files should be placed in the application's classes folder. If you've just installed Tomcat, the easiest way to run them is to put them in the webapps/examples/web-inf/classes folder. We will also assume that that's where you put the servlets if you follow along.