By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,271 Members | 1,413 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,271 IT Pros & Developers. It's quick & easy.

XSLT on 2 XML files, after passing one thru a SAX filter

P: n/a
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

Mar 29 '06 #1
Share this Question
Share on Google+
2 Replies

P: n/a
I'd suggest: Filter the first, use it as your input document, and have
the stylesheet explicit access the second via paths based on the
document() function. (Or, if you already have the second in memory as a
DOM tree, your XSLT processor *may* let you pass it in as a stylesheet
parameter and treat it as a nodeset -- but that's getting into
non-standardized stuff.)

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Mar 29 '06 #2

P: n/a

Joseph Kesselman wrote:
I'd suggest: Filter the first, use it as your input document, and have
the stylesheet explicit access the second via paths based on the
document() function. (Or, if you already have the second in memory as a
DOM tree, your XSLT processor *may* let you pass it in as a stylesheet
parameter and treat it as a nodeset -- but that's getting into
non-standardized stuff.)

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden


Thanks, that sounds like a good strategy.
--Jeff

Mar 31 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.