The JAXP 1.2 Transformation API for XML (TrAX) defines objects and
methods for processing input and producing
output in a variety of formats, including character streams, SAX event streams, and DOM Documents.
You can use the
TransformerFactory.getFeature(String)
method to return a boolean indicating whether the implementation you are using supports the use of one of these objects or methods. For the String argument, provide the static String variable or literal URI String as detailed below.
Xalan-Java supports all TransformerFactory features.
The implementation supports the processing of StreamSource input objects.
To determine whether your implementation supports this feature (Xalan-Java does), you can use the static StreamSource.FEATURE variable (equivalent to the URI String above) as follows:
import javax.xml.transform.TransformerFactory;
import javax.xml.stream.StreamSource;
TransformerFactory tFact = TransformerFactory.newInstance();
if (tFact.getFeature(StreamSource.FEATURE)){
// Can process a StreamSource.
..
}
The implementation supports the production of transformation output in the form of StreamResult objects.
To determine whether your implementation supports this feature (Xalan-Java does), you can use the static StreamResult.FEATURE variable (equivalent to the URI String above) as follows:
import javax.xml.transform.TransformerFactory;
import javax.xml.stream.StreamResult;
..
TransformerFactory tFact = TransformerFactory.newInstance();
if (tFact.getFeature(StreamResult.FEATURE)){
// Can generate a StreamResult.
..
}
The implementation supports the processing of XML input in the form of DOMSource objects.
To determine whether your implementation supports this feature (Xalan-Java does), you can use the static DOMSource.FEATURE string variable (equivalent to the URI String above) as follows:
import javax.xml.transform.TransformerFactory;
import javax.xml.dom.DOMSource;
..
TransformerFactory tFact = TransformerFactory.newInstance();
if (tFact.getFeature(DOMSource.FEATURE)){
// Can process DOM input
..
}
For a example that uses this feature, see DOM2DOM.
The implementation supports the production of transformation output in the form of DOMResult objects.
To determine whether your implementation supports this feature (Xalan-Java does), you can use the static DOMResult.FEATURE variable (equivalent to the URI String above) as follows:
import javax.xml.transform.TransformerFactory;
import javax.xml.dom.DOMResult;
..
TransformerFactory tFact = TransformerFactory.newInstance();
if (tFact.getFeature(DOMResult.FEATURE)){
// Can generate DOM output.
..
}
For a example that uses this feature, see DOM2DOM.
The implementation supports the processing of XML input in the form of SAXSource objects.
To determine whether your implementation supports this feature (Xalan-Java does), you can use the static SAXSource.FEATURE string variable (equivalent to the URI String above) as follows:
import javax.xml.transform.TransformerFactory;
import javax.xml.sax.SAXSource;
..
TransformerFactory tFact = TransformerFactory.newInstance();
if (tFact.getFeature(SAXSource.FEATURE)){
// Can process SAX events.
..
}
The implementation supports the production of transformation output in the form of SAXResult objects.
To determine whether your implementation supports this feature (Xalan-Java does), you can use the static SAXResult.FEATURE variable (equivalent to the URI String above) as follows:
import javax.xml.transform.TransformerFactory;
import javax.xml.sax.SAXResult;
..
TransformerFactory tFact = TransformerFactory.newInstance();
if (tFact.getFeature(SAXResult.FEATURE)){
// Can output SAX events.
..
}
For a example that uses this feature, see SAX2SAX.
The implementation provides a SAXTransformerFactory.
You may safely cast the TransformerFactory returned by TransformerFactory.newInstance() to a SAXTransformerFactory.
To determine whether your implementation supports this feature (Xalan-Java does), you can use the static SAXTransformerFactory.FEATURE
variable (equivalent to the URI String above) as follows:
The implementation supports the use of XMLFilter to use the output of one
transformation as input for another transformation. The SAXTransformerFactory newXMLFilter(Source) and newXMLFilter(Templates) methods
are supported.
To determine whether your implementation supports this feature (Xalan-Java does), you can use the static
SAXTransformerFactory.FEATURE_XMLFilter variable (equivalent to the URI String above) as follows:
import javax.xml.transform.TransformerFactory;
import javax.xml.sax.SAXTransformerFactory;
..
TransformerFactory tFact = TransformerFactory.newInstance();
if (tFact.getFeature(SAXTransformerFactory.FEATURE_XMLFILTER))){
// Can use SAXTransformerFactory to get XMLFilters.
..
}
For an example that uses this feature to chain together a series of transformations, see
UseXMLFilters.
Xalan-Java TransformerFactory attributes
A given implementation may provide TransformerFactory attributes for which you can set and get values. Xalan-Java uses the
DTM (Document Table Model) to support three attributes which can be set to true or false:
To get an attribute setting, use the TransformerFactory.getAttribute(String) method, which returns an Object. For these three Xalan-Java
attributes, you can cast the return value to a boolean. To set an attribute, use the TransformerFactory.setAttribute(String, Object) method.
For the String argument, provide the static String variable or literal URI String as detailed below. For the Object argument, use
Boolean.TRUE or Boolean.FALSE (or the Strings "true" or "false").
optimize attribute
URI: "http://apache.org/xalan/features/optimize"
Optimize stylesheet processing. By default, this attribute is set to true. You may need to set it to false for tooling applications.
For more information, see DTM optimize.
To turn optimization off, you can use the TransformerFactoryImpl.FEATURE_OPTIMIZE static variable (equivalent to the URI String above)
as follows:
Produce output incrementally, rather than waiting to finish parsing the input before generating any output. By default this attribute is set
to false. You can turn this attribute on to transform large documents where the stylesheet structure is optimized to execute individual templates
without having to parse the entire document. For more information, see DTM incremental.
To turn incremental transformations on, you can use the TransformerFactoryImpl.FEATURE_INCREMENTAL static variable (equivalent to the URI String above) as follows:
Provide a SourceLocator that can be used during a transformation
to obtain the location of individual nodes in a source document (system ID, line number, and column number).
By default, this attribute is set to false. Setting this attribute to true involves a substantial increase in storage cost per source
document node. If you want to use the NodeInfo extension functions (or some other mechanism)
to provide this information during a transform, you must set the attribute to true before generating the Transformer and processing the
stylesheet.
The command-line utility -L flag sets this attribute to true. To set the source_location attribute
programmatically, you can use the TransformerFactoryImpl.FEATURE_SOURCE_LOCATION static variable (equivalent to the URI String above)
as follows: