org.jdom.transform
Class XSLTransform

java.lang.Object
  |
  +--org.jdom.transform.XSLTransform
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class XSLTransform
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

This class serves as an interface to a TrAX aware XSLT processor such as Xalan or Saxon.

The following example shows how to apply an XSL Transformation to a JDOM document and get the transformation result in the form of another JDOM Document:

 public static Document transform(Document in) 
   throws XSLException {
     XSLTransform stylesheet = new XSLTransform("mystylesheet.xsl"); 
     return stylesheet.transform(doc);
 } 

JDOM relies on TrAX to perform the transfromation. The javax.xml.transform.TransformerFactory Java system property determines which XSLT engine TrAX uses. Its value should be the fully qualified name of the implementation of the abstract javax.xml.transform.TransformerFactory class. Possible values of this property include:

This property can be set in all the usual ways a Java system property can be set. TrAX picks from them in this order:

  1. Invoking System.setProperty( "javax.xml.transform.TransformerFactory", "classname")
  2. The value specified at the command line using the -Djavax.xml.transform.TransformerFactory=classname option to the java interpreter
  3. The class named in the lib/jaxp.properties properties file in the JRE directory, in a line like this one:
    javax.xml.parsers.DocumentBuilderFactory=classname
  4. The class named in the META-INF/services/javax.xml.transform.TransformerFactory file in the JAR archives available to the runtime
  5. Finally, if all of the above options fail, a default implementation is chosen. In Sun's JDK 1.4, this is Xalan 2.2d10.

Version:
$Revision: 1.0 $, $Date: 2002/04/26 16:19:10 $
Author:
Elliotte Rusty Harold
See Also:
Serialized Form

Constructor Summary
XSLTransform(Document stylesheet)
           This will create a new XSLTransform by reading the stylesheet from the specified Document.
XSLTransform(java.io.File stylesheet)
           This will create a new XSLTransform by reading the stylesheet from the specified File.
XSLTransform(java.io.InputStream stylesheet)
           This will create a new XSLTransform by reading the stylesheet from the specified InputStream.
XSLTransform(java.io.Reader stylesheet)
           This will create a new XSLTransform by reading the stylesheet from the specified Reader.
XSLTransform(java.lang.String systemID)
           This will create a new XSLTransform by reading the stylesheet from the specified URL.
 
Method Summary
 java.lang.Object clone()
           This will create a copy of this XSLTransform object.
 boolean equals(java.lang.Object o)
           
 int hashCode()
           This returns the hash code for this XSLTransform.
 java.lang.String toString()
           This returns a String form of this XSLTransform, suitable for debugging.
 Document transform(Document in)
           This will create a new Document from the input Document by applying this object's stylesheet.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XSLTransform

public XSLTransform(java.io.InputStream stylesheet)
             throws XSLException

This will create a new XSLTransform by reading the stylesheet from the specified InputStream.

Parameters:
stylesheet - InputStream from which the stylesheet is read.
Throws:
XSLException - when an IOException, format error, or something else prevents the stylesheet from being compiled

XSLTransform

public XSLTransform(java.io.Reader stylesheet)
             throws XSLException

This will create a new XSLTransform by reading the stylesheet from the specified Reader.

Parameters:
stylesheet - Reader from which the stylesheet is read.
Throws:
XSLException - when an IOException, format error, or something else prevents the stylesheet from being compiled

XSLTransform

public XSLTransform(java.io.File stylesheet)
             throws XSLException

This will create a new XSLTransform by reading the stylesheet from the specified File.

Parameters:
stylesheet - File from which the stylesheet is read.
Throws:
XSLException - when an IOException, format error, or something else prevents the stylesheet from being compiled

XSLTransform

public XSLTransform(Document stylesheet)
             throws XSLException

This will create a new XSLTransform by reading the stylesheet from the specified Document.

Parameters:
stylesheet - Document containing the stylesheet.
Throws:
XSLException - when the supplied Document is not syntactically correct XSLT

XSLTransform

public XSLTransform(java.lang.String systemID)
             throws XSLException

This will create a new XSLTransform by reading the stylesheet from the specified URL.

Parameters:
systemID - URL from which the stylesheet is read.
Throws:
XSLException - when an IOException, format error, or something else prevents the stylesheet from being compiled
Method Detail

transform

public Document transform(Document in)
                   throws XSLException

This will create a new Document from the input Document by applying this object's stylesheet. The original Document is not changed.

Parameters:
in - Document to transform.
Throws:
XSLException - if the transformation fails, normally due to an XSLT error.

clone

public java.lang.Object clone()

This will create a copy of this XSLTransform object. To be honest, I can't imagine why you'd want to do this. This class is thread-safe. Perhaps this mthod should be deleted?

Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

This returns the hash code for this XSLTransform.

Overrides:
hashCode in class java.lang.Object
Returns:
int - hash code.

toString

public java.lang.String toString()

This returns a String form of this XSLTransform, suitable for debugging.

Overrides:
toString in class java.lang.Object
Returns:
String - debugging string.


Copyright © 2002 Jason Hunter, Brett McLaughlin. All Rights Reserved.