This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: RE: multi-phase transformations (was untitled)


> I've been letting this one slip by for months now.
> Mike and his magic (to me) 'sax filters' !
>
> As a java novice, has anyone knowledge of this particular incantation?
>

A SAX filter (class org.xml.sax.XMLFilter) takes SAX events in at one end
(so it looks to the supplier of these events like a ContentHandler) and
pushes SAX events out at the other (so it looks to the consumer of these
events like a parser or org.xml.sax.XMLReader. The nice thing is that they
are composable: you can plug two Sax filters together end to end and what
you get is in effect a composite SAX filter.

The following example from the TrAX spec may help a bit:

TransformerFactory tfactory = TransformerFactory.newInstance();
// Does this factory support SAX features?
if (tfactory.getFeature(SAXTransformerFactory.FEATURE))
{
Templates stylesheet1 = tfactory.newTemplates(new StreamSource(xslID_1));
Transformer transformer1 = stylesheet1.newTransformer();
SAXTransformerFactory stf = (SAXTransformerFactory)tfactory;
XMLReader reader = XMLReaderFactory.createXMLReader();
XMLFilter filter1 = stf.newXMLFilter(new StreamSource(xslID_1));
XMLFilter filter2 = stf.newXMLFilter(new StreamSource(xslID_2));
XMLFilter filter3 = stf.newXMLFilter(new StreamSource(xslID_3));
// transformer1 will use a SAX parser as it's reader.
filter1.setParent(reader);
// transformer2 will use transformer1 as it's reader.
filter2.setParent(filter1);
// transform3 will use transform2 as it's reader.
filter3.setParent(filter2);
filter3.setContentHandler(new ExampleContentHandler());
// filter3.setContentHandler(new org.xml.sax.helpers.DefaultHandler());
// Now, when you call transformer3 to parse, it will set
// itself as the ContentHandler for transform2, and
// call transform2.parse, which will set itself as the
// content handler for transform1, and call transform1.parse,
// which will set itself as the content listener for the
// SAX parser, and call parser.parse(new InputSource(“xml/foo.xml”)).
filter3.parse(new InputSource(sourceID));
}


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]