ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button O'Reilly Book Excerpts: Java and XSLT

XSLT Processing with Java

Related Reading

Java and XSLT
By Eric M. Burke

by Eric M. Burke

This excerpt is Chapter 5 from Java and XSLT, to be published in September 2001 by O'Reilly.

Since many of the XSLT processors are written in Java, they can be directly invoked from a Java application or servlet. Embedding the processor into a Java application is generally a matter of including one or two JAR files on the CLASSPATH and then invoking the appropriate methods. This chapter shows how to do this, along with a whole host of other programming techniques.

When invoked from the command line, an XSLT processor such as Xalan expects the location of an XML file and an XSLT stylesheet to be passed as parameters. The two files are then parsed into memory using an XML parser such as Xerces or Crimson, and the transformation is performed. But when the XSLT processor is invoked programmatically, you are not limited to using static files. Instead, you can send a precompiled stylesheet and a dynamically generated DOM tree directly to the processor, or even fire SAX events as processor input. A major goal is to eliminate the overhead of parsing, which can dramatically improve performance.

This chapter is devoted to Java and XSLT programming techniques that work for both standalone applications as well as servlets, with a particular emphasis on Sun's Java API for XML Processing (JAXP) API. In Chapter 6, we will apply these techniques to servlets, taking into account issues such as concurrency, deployment, and performance.

In this chapter:

A Simple Example

The Design

Xalan 1 Implementation

SAXON Implementation

SAXON, Xalan, or TrAX?

Introduction to JAXP 1.1

JAXP 1.1 Implementation

XSLT Plugability Layer

The Transformer Class


Input and Output

System Identifiers, Files, and URLs

JAXP I/O Design

JAXP Stream I/O



Feeding JDOM Output into JAXP

Stylesheet Compilation

Templates API

A Stylesheet Cache

Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9

Next Pagearrow