This section provides a tutorial example on how to write a simple program, XSLClassChecker.java, to view implementation classes of XSL (Extensible Stylesheet Language) in JDK.
JDK (J2SDK) 1.4.1_01 offers the following interfaces to support XSL (Extensible Stylesheet Language):
javax.xml.transform.TransformerFactory: The transformer factory class to help to create a transformer object.
javax.xml.transform.Transformer: The abstract class representing a transformer.
javax.xml.transform.Source: The interface representing source objects for the transformer to process.
javax.xml.transform.Result: The interface representing result objects produced by the transformer.
One thing is missing here: who represents the transformation style rules? The answer
is that javax.xml.transform.Source also represents transformation style rules, because
they written in XML.
I have a simple program here, XSLClassChecker.java, to show what are the XSL
implementation classes:
/**
* XSLClassChecker.java
* Copyright (c) 2002 by Dr. Herong Yang
*/
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());
}
}
}
Output:
org.apache.xalan.processor.TransformerFactoryImpl@119298d
org.apache.xalan.transformer.TransformerIdentityImpl@1f33675
javax.xml.transform.stream.StreamSource@1690726
javax.xml.transform.stream.StreamResult@9931f5
javax.xml.transform.TransformerException: No output specified
Note that:
So J2SDK 1.4.1_01 is using the org.apache.xalan package for XSL transformation.
The Identity transformer was used, because the program is specify any transformation rules.
I got the "No output specified" exception, because the program was transforming from nothing
(empty source object) to nowhere (empty result object).