You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by "Fitzharris, Walter M. (LNG-DAY)" <Wa...@lexisnexis.com> on 2003/06/20 16:29:41 UTC

xmlfilters with parameters

What happens if you want to use a chain of filters, but you want to pass a
parameter to one of the stylesheets?

1) Here's some code that works, but my question is: why doesn't it need to
recurse a la the xml filter example?
Notice that in this code, the reader, not the last filter in the chain,
calls parse().  I really didn't understand why the last filter in the chain
called parse() anyway (see xmlfilter example in xalan release)...it's
non-intuitive for me...it would seem that if they were truly chained, the
front guy in the chain would read (parse) and the last guy in the chain
would write...like the old "telephone game".

2) Another question: does this code retain the benefits of being able to
process huge XML docs, or has it been tainted by the rewiring to add the
transformer con parameter?

      // Create an XMLFilter for each stylesheet
      XMLFilter xmlFilter1 = saxTFactory.newXMLFilter(new
StreamSource("filter1.xsl"));
      XMLFilter xmlFilter2 = saxTFactory.newXMLFilter(new
StreamSource("filter2.xsl"));
      XMLFilter xmlFilter3 = saxTFactory.newXMLFilter(new
StreamSource("filter3.xsl"));

      // Get a transformer for this xsl, so can set the parm for it.
      TransformerHandler tHandler = saxTFactory.newTransformerHandler(new
StreamSource("filter4p.xsl"));
      Transformer t = tHandler.getTransformer();
      t.setParameter("fParam", "FormatterFunctions");
      
      // Create a serializer for the final output of the chain of xsls.
      Serializer serializer = SerializerFactory.getSerializer
 
(OutputPropertiesFactory.getDefaultMethodProperties("xml"));        
      serializer.setOutputStream(System.out);

      // Link up the chain
	XMLReader reader = XMLReaderFactory.createXMLReader();
      xmlFilter1.setParent(reader);
      xmlFilter2.setParent(xmlFilter1);
      xmlFilter3.setParent(xmlFilter2);
      xmlFilter3.setContentHandler(tHandler);
      tHandler.setResult(new SAXResult(serializer.asContentHandler()));
      
      // Now go!
      reader.parse(new InputSource("input.xml"));


Walt Fitzharris
Lexis Nexis
937-865-6800 X54641