[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: RE: RE: multi-phase transformations (was untitled)
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Wed, 14 Mar 2001 15:25:28 -0000
phase transform
> 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.