Hello everyone
I have sucessfully implemented a SAX filter to take a large
XML data file, and strip it down to its essential elements,
and then pass that on to an XSL transformer. (A bare bones example
of the java code is listed at the end) I also need another XML file, a
list of all possible records, which I use for getting additional
information by cross referencing with xsl:key.
The list file only has one type of element, and I need to write
some output for each of them. So if I don't filter the data file
and start running the XSLT on the List file, and iterating through
every element, I can get the data from the Data file easily, by
accessing it via document().
But to use the filter, I seem to have to START processing with the Data
file
and then *it* is what gets passed to the transformer. I don't know how
to immediately switch to the list file, iterate through each of its
elements and refer back to the data file as needed...
I guess I could template-match on the root element of the filtered
data file and jump from that over to the list file...?
Anyway, here is the rudiments of how I am doing the SAX filtering,
and passing to the XSLT:
- - - - - - - - - - - - - - - - - - - -- - - - - - -
FileReader r = new FileReader( xmlDataFile );
XMLReader xr =
XMLReaderFactory.createXMLReader("org.apache.xerce s.parsers.SAXParser");
KeepSpecificEltsFilter kFilter = new KeepSpecificEltsFilter( xr,
elementsToKeep );
TransformerFactory tFactory = TransformerFactory.newInstance();
SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
XMLFilter xmlFilter2 = saxTFactory.newXMLFilter( new StreamSource(
xsltFile ) );
xmlFilter2.setParent( kFilter );
java.util.Properties xmlProps =
OutputPropertiesFactory.getDefaultMethodProperties ("xml");
Serializer serializer = SerializerFactory.getSerializer( xmlProps );
xmlFilter2.setContentHandler( serializer.asContentHandler() );
xmlFilter2.parse( new InputSource(xmlDataFile) );
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
I am open to any ideas...
--Jeff