XML Tutorials - Herong's Tutorial Examples - v5.21, by Dr. Herong Yang
XSLT Implementations in JDK 1.4 and Higher
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) 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 10 and 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:
Table of Contents
Introduction of XML (eXtensible Markup Language)
DOM (Document Object Model) Programming Interface
SAX (Simple API for XML) Programming Interface
DTD (Document Type Definition) Introduction
Validating an XML Document against the Specified DTD Document Type
XSD (XML Schema Definition) Introduction
Validating XML Documents Against Specified XML Schemas
XSL (Extensible Stylesheet Language) Introduction
XSLT (XSL Transformations) Introduction
►XSLT Implementations in JDK 1.4 and Higher
XSLTransformer.java - A Simple XSLT Transformation Program
XSLT Elements as Programming Statements
Control and Generate XML Element in the Result
PHP Extensions for XML Manipulation
XML Tools Plugin for Notepad++
XML Plugin Packages for Atom Editor