Transform Features

Transform features are identified by URI Strings and fall into the following categories: Standard TransformationFactory features Implementation-specific TransformerFactory attributes
| Standard TransformerFactory features |
| Java API for XML Processing (JAXP) 1.3 defines objects and methods for processing input and producing output in a variety of formats, including character streams, SAX event streams, and DOM Documents. JAXP 1.3 defines the following features: StreamSource feature StreamResult feature DOMSource feature DOMResult feature SAXSource feature SAXResult feature SAXTransformerFactory feature XMLFilter feature Secure processing feature 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. You can use the TransformerFactory.setFeature(String, boolean) method to set the value of a feature. Xalan-Java only supports setting of the XMLConstants.FEATURE_SECURE_PROCESSING feature. For all other features, TransformerFactory exposes their values, but cannot change their states. Xalan-Java supports all TransformerFactory features.
| StreamSource feature |
| URI: "http://javax.xml.transform.stream.StreamSource/feature" 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.
      ..
    }
For a example that uses this feature, see SimpleTransform.
| StreamResult feature |
| URI: "http://javax.xml.transform.stream.StreamResult/feature" 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.
      ..
    }
For a example that uses this feature, see SimpleTransform.
| DOMSource feature |
| URI: "http://javax.xml.transform.dom.DOMSource/feature" 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.
| DOMResult feature |
| URI: "http://javax.xml.transform.dom.DOMResult/feature" 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.
| SAXSource feature |
| URI: "http://javax.xml.transform.dom.SAXSource/feature" 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.
      ..
    }
| SAXResult feature |
| URI: "http://javax.xml.transform.dom.SAXResult/feature" 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.
| SAXTransformerFactory feature |
| URI: "http://javax.xml.transform.sax.SAXTransformerFactory/feature" 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:
    import javax.xml.transform.TransformerFactory;
    import javax.xml.sax.SAXTransformerFactory;
    ..
    TransformerFactory tFact = TransformerFactory.newInstance();
    if (tFact.getFeature(SAXTransformerFactory.FEATURE)){
      SAXTransformerFactory saxTFact = (SAXTransformerFactory)tFact;
      ..
    }
For a example that uses this feature, see SAX2SAX.
| XMLFilter feature |
| URI: "http://javax.xml.transform.sax.SAXTransformerFactory/feature/xmlfilter" 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.
| Secure processing feature |
| URI: "http://javax.xml.XMLConstants/feature/secure-processing" Xalan-Java supports the secure processing feature in both the interpretive and XSLTC processors. When this feature is set to true, the implementation will apply a set of limits on the XSLT/XML processing behavior to make the XSLT processor behave in a secure fashion. The limits are implementation dependent. Xalan-Java applies the following limits when the secure processing feature is set to true: extension functions and extension elements are disabled. parsers created by the XSLT processors will also have the secure processing feature set to true.
| 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: optimize attribute incremental attribute source_location attribute 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://xml.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:
    import javax.xml.transform.TransformerFactory;
    import org.apache.xalan.processor.TransformerFactoryImpl;
    ..
    TransformerFactory tFact = TransformerFactory.newInstance();
    if (tFact instanceof TransformerFactoryImpl) {
      tFact.setAttribute(TransformerFactoryImpl.FEATURE_OPTIMIZE,
                         Boolean.FALSE);
    }
| incremental attribute |
| URI: "http://xml.apache.org/xalan/features/incremental" 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:
    import javax.xml.transform.TransformerFactory;
    import org.apache.xalan.processor.TransformerFactoryImpl;
    ..
    TransformerFactory tFact = TransformerFactory.newInstance();
    if (tFact instanceof TransformerFactoryImpl) {
      tFact.setAttribute(TransformerFactoryImpl.FEATURE_INCREMENTAL,
                         Boolean.FALSE);
    }
| The incremental feature is not currently supported by XSLTC.
| source_location attribute |
| URI: "http://xml.apache.org/xalan/properties/source-location" 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:
    import javax.xml.transform.TransformerFactory;
    import org.apache.xalan.transformer.TransformerImpl;
    import org.apache.xalan.transformer.XalanProperties;
    ..
    TransformerFactory tFact = TransformerFactory.newInstance();
    if (tFact instanceof TransformerFactoryImpl) {
      tFact.setAttribute(TransformerFactoryImpl.FEATURE_SOURCE_LOCATION,
                         Boolean.TRUE);
    }

Copyright © 2006 The Apache Software Foundation. All Rights Reserved.