TRAX: Passing parameters to a "pull" transformer
By gjmurphy on Sep 14, 2004
The TRAX API for performing XSL transformations includes a factory extension,
SAXTransformerFactory, which can return a transformer hidden behind a SAX XML Filter. This allows multiple transformations to be easily chained together, as per the Filter design
pattern. Moreover, it allows filters backed by transformations to be intermixed with other types
of filter implementations, which can simplify the code for iterative XML processing.
Unfortunately, returning the transformer as a class that implements only XMLFilter effectively
hides the methods defined by
javax.xml.transform.Transformer, including those
used to pass global parameters to the transformation process. This is unfortunate.
I think a better solution would have been to return an interface that extends both XMLFilter and Transformer, allowing the caller to set up the filter chain, and then pass parameters to some or all of the filters before processing. This is one of the things that I liked about James Clark's XT: his XSLProcessor class extended XMLParser (the SAX 1.0 predecessor of XMLReader), so they could be made easily into filters. Of course, having to wrap processors in XMLReaderAdapators (to allow the SAX 1.0 parser to read from a SAX 2.0 reader) makes for its own headaches.