nu.xom.xslt
Class XSLTransform

java.lang.Object
  extended bynu.xom.xslt.XSLTransform

public final class XSLTransform
extends java.lang.Object

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 XOM document and get the transformation result in the form of a XOM Nodes:

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

XOM relies on TrAX to perform the transformation. 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. Values of this property for popular XSLT processors 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.0 and 1.4.1, this is Xalan 2.2d10. In Java 1.4.2, this is Xalan 2.4.

Version:
1.0d23
Author:
Elliotte Rusty Harold

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
 void setNodeFactory(NodeFactory factory)
           Sets the factory used to construct nodes in the output tree.
 java.lang.String toString()
           This returns a String form of this XSLTransform, suitable for debugging.
 Nodes transform(Document in)
           This will create a new Nodes from the input Document by applying this object's stylesheet.
 Nodes transform(Nodes in)
           This will create a new Nodes from the input Nodes by applying this object's stylesheet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, 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 Nodes transform(Document in)
                throws XSLException

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

Parameters:
in - Document to transform
Returns:
a Nodes containing the result of the transformation
Throws:
XSLException - if the transformation fails, normally due to an XSLT error

transform

public Nodes transform(Nodes in)
                throws XSLException

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

Parameters:
in - Document to transform
Returns:
a Nodes containing the result of the transformation
Throws:
XSLException - if the transformation fails, normally due to an XSLT error

setNodeFactory

public void setNodeFactory(NodeFactory factory)

Sets the factory used to construct nodes in the output tree. Passing null uses the default factory.

Parameters:
factory - the NodeFactory used to construct nodes in the output tree

toString

public java.lang.String toString()

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

Returns:
debugging string


Copyright 2002-2004 Elliotte Rusty Harold
elharo@metalab.unc.edu