XML technologies / XSLT / Java and XSLT / Introduction / Before you begin ...

(Excerpt from “Java und XSLT” by Eric M. Burke)

Experimenting is the best way to learn a new technology. If XSLT is new to you, try many stylesheets as you work through the next two chapters. Besides trying the book’s examples, create a simple XML file about something you enjoy, such as your music collection or family tree. Then use stylesheets to create websites displaying your data in various formats.

Once you understand XSLT basics, servlets are the next challenge. Their API is not especially hard to learn, but configuration and deployment details can complicate debugging and testing. Start with a small application confirming that your environment works before attempting complex examples. Apache Tomcat is probably the best servlet container for beginners: free, easy to configure and Sun’s official Servlet API reference implementation. A servlet container is the server running servlets. The section Servlet basics and XSLT covers Servlet API basics. For details, consult Java Servlet-Programmierung by Jason Hunter, also published by O’Reilly. Choose the second edition, covering the extensive changes introduced in Servlet API 2.2.

Choosing a Java XSLT processor

Although this book primarily uses Sun’s JAXP and Apache’s Xalan, many other processors exist. Those written in other languages may perform better from the command line because they need not start a Java Virtual Machine first. From a servlet, the JVM already runs, so this delay is irrelevant. Pure Java processors integrate easily into web applications and suit servlets well: simply add a JAR to the CLASSPATH environment variable.

A current processor list in a book soon becomes obsolete. Some popular Java processors follow, but search the web for XSLT processors before committing to a tool, since new ones continually appear. Xalan is covered in the next chapter; here are other candidates:

XT

XT was an early XSLT processor written by James Clark, editor of the XSLT specification. XT evolved alongside the specification, making it a leader in conformance. At the time of writing, however, it was updated less promptly than other Java processors. The XT version 19991105 implements the W3C Proposed Recommendation PR-xslt-19991008. Like the other processors listed, XT is free.

LotusXSL

LotusXSL is a Java XSLT processor from IBM Alphaworks. In November 1999 IBM donated LotusXSL to Apache, forming Xalan’s basis. LotusXSL continued as a separate product, currently wrapping Xalan. Future releases may add functionality, but currently there is little reason to choose LotusXSL unless you already use it.

SAXON

Michael Kay’s SAXON XSLT processor is available at SAXON - The XSLT and XQuery Processor. SAXON is open source under the Mozilla Public License and a popular Xalan alternative. It fully supports the current XSLT specification and is well documented. Added features include multiple result trees from one transformation and updating stylesheet variable values.

To transform a document with SAXON, first add saxon.jar to CLASSPATH. Then enter java com.icl.saxon.StyleSheet -? for available options. Basic transformation syntax is:

java com.icl.saxon.StyleSheet [optionen] quelldokument styledokument [parameter…]

To transform file bundespraesidenten.xml and send the result to standard output, enter:

java com.icl.saxon.StyleSheet bundespraesidenten.xml bundespraesidenten.xslt

JAXP

Unlike earlier versions, Sun’s Java API for XML Processing (JAXP) 1.1 supports XSLT transformations. XML parsing and transformation are not the main functions of JAXP. Its goal is a standard Java interface for multiple parsers and processors. Although it includes reference implementations, its main benefit is letting developers choose their Java tools, such as parsers. JAXP greatly reduces vendor dependence.

Since JAXP is primarily a Java API, we examine its interfaces in detail when discussing XSLT programming in XSLT processing with Java.

   

 

 

 

back to top