An implementation of the TrAX TransformerFactory class and
SAXTransformerFactory classes.
import java.io.*;
import javax.xml.transform.*;
...
System.setProperty("javax.xml.transform.TransformerFactory",
"jd.xml.xslt.trax.TransformerFactoryImpl");
TransformerFactory tfactory = TransformerFactory.newInstance();
Source stylesheetSource = ...
Transformer transformer = tfactory.newTransformer(stylesheetSource);
transformer.transform(...);
getAssociatedStylesheet
public Source getAssociatedStylesheet(Source source,
java.lang.String media,
java.lang.String title,
java.lang.String charset)
throws TransformerConfigurationException
Get the stylesheet specification(s) associated
via the xml-stylesheet processing instruction (see
http://www.w3.org/TR/xml-stylesheet/) with the document
document specified in the source parameter, and that match
the given criteria. Note that it is possible to return several
stylesheets, in which case they are applied as if they were
a list of imports or cascades.
source
- The XML source document.media
- The media attribute to be matched. May be null, in which
case the prefered templates will be used (i.e. alternate = no).title
- The value of the title attribute to match. May be null.charset
- The value of the charset attribute to match. May be null.
- A Source object suitable for passing to the TransformerFactory.
getAttribute
public Object getAttribute(String name)
throws IllegalArgumentException
Throws an IllegalArgumentException since attributes are not supported.
getErrorListener
public ErrorListener getErrorListener()
Get the error event handler for the TransformerFactory.
- The current error handler, which should never be null.
getFeature
public boolean getFeature(String name)
Look up the value of a feature.
The feature name is any absolute URI.
name
- The feature name, which is an absolute URI.
- The current state of the feature (true or false).
getReader
public XMLReader getReader(Source source)
throws Exception
getURIResolver
public URIResolver getURIResolver()
Return the URIResolver that was set with setURIResolver.
the object that is used by default during the
transformation to resolve URIs used in document(),
xsl:import, or xsl:include.
newTemplates
public Templates newTemplates(Source source)
throws TransformerConfigurationException
Process the Source into a Templates object, which is a
a compiled representation of the source.
newTemplatesHandler
public TemplatesHandler newTemplatesHandler()
throws TransformerConfigurationException
Get a TemplatesHandler object that can process SAX ContentHandler events into a
Templates object.
- A non-null reference to a TemplatesHandler, that may be used as a
ContentHandler for SAX parse events.
newTransformer
public Transformer newTransformer()
throws TransformerConfigurationException
Create a new Transformer object that performs a copy
of the source to the result.
- A Transformer object that may be used to perform a transformation
in a single thread, never null.
newTransformer
public Transformer newTransformer(Source source)
throws TransformerConfigurationException
Process the Source into a Transformer object.
newTransformerHandler
public TransformerHandler newTransformerHandler()
throws TransformerConfigurationException
newTransformerHandler
public TransformerHandler newTransformerHandler(Source source)
throws TransformerConfigurationException
newTransformerHandler
public TransformerHandler newTransformerHandler(Templates templates)
throws TransformerConfigurationException
newXMLFilter
public XMLFilter newXMLFilter(Source source)
throws TransformerConfigurationException
newXMLFilter
public XMLFilter newXMLFilter(Templates templates)
throws TransformerConfigurationException
setAttribute
public void setAttribute(String name,
Object value)
throws IllegalArgumentException
Throws an IllegalArgumentException since attributes are not supported.
setErrorListener
public void setErrorListener(ErrorListener listener)
throws IllegalArgumentException
Set the error event listener for the TransformerFactory, which
is used for the processing of transformation instructions,
setFeature
public void setFeature(String name,
boolean value)
throws TransformerConfigurationException
setURIResolver
public void setURIResolver(URIResolver uriResolver)
Set the URIResolver.