XSLT Implementations in JDK 1.4

This section describes the Java implementation classes of XSLT in JDK 1.4. XSLT interfaces are defined in the javax.xml.transform package: TransformerFactory, Transformer, Source, Result. JDK 1.4 actually uses org.apache.xalan package for XSLT transformation.

JDK offers the following interfaces to support XSLT:

One thing seems to be missing here: who represents the transformation stylesheet? The answer is that the stylesheet will be read in when you instantiate a Transformer object.

I have a simple test program here, XSLClassChecker.java, to show what are the XSLT implementation classes included in JDK:

/* XSLClassChecker.java
 - Copyright (c) 2014, HerongYang.com, All Rights Reserved.
 */
import javax.xml.transform.Source;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
class XSLClassChecker {
   public static void main(String[] args) {
      try {
         TransformerFactory f = TransformerFactory.newInstance();
         System.out.println(f.toString());
         Transformer t = f.newTransformer();
         System.out.println(t.toString());
         Source s = new StreamSource();
         System.out.println(s.toString());
         Result r = new StreamResult();
         System.out.println(r.toString());
         t.transform(s,r);
      } catch (TransformerConfigurationException e) {
         System.out.println(e.toString()); 	
      } catch (TransformerException e) {
         System.out.println(e.toString()); 	
      }
   }
}

Compile and run this example program with JDK 1.8:

C:\herong>java XSLClassChecker

com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImp...
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl@25154f
javax.xml.transform.stream.StreamSource@10dea4e
javax.xml.transform.stream.StreamResult@647e05
javax.xml.transform.TransformerException: Result object passed to 
''{0}'' is invalid.

Note that:

Last update: 2014.

Table of Contents

 About This Book

 Introduction of XML (eXtensible Markup Language)

 XML File Syntax

 XML File Browsers

 DOM (Document Object Model) Programming Interface

 SAX (Simple API for XML) Programming Interface

 DTD (Document Type Definition) Introduction

 Syntaxes of DTD Statements

 Validating an XML Document against the Specified DTD Document Type

 XSD (XML Schema Definition) Introduction

 Syntaxes of XSD Statements

 Validating XML Documents Against Specified XML Schemas

 XSL (Extensible Stylesheet Language) Introduction

 XSLT (XSL Transformations) Introduction

Java Implementation of XSLT

XSLT Implementations in JDK 1.4

 XSLTransformer.java - A Simple XSLT Transformation Program

 XPath (XML Path) Language

 XSLT Elements as Programming Statements

 Control and Generate XML Element in the Result

 XML Notepad - XML Editor

 XML Tools Plugin for Notepad++

 XML 1.1 Changes and Parsing Examples

 Outdated Tutorials

 References

 PDF Printing Version