final SAXParserFactory factory = SAXParserFactory.newInstance();
final SAXParser parser = factory.newSAXParser();
final XMLReader reader = parser.getXMLReader();
// Set the DOM's DOM builder as the XMLReader's SAX2 content handler
final DOMImpl dom = new DOMImpl();
reader.setContentHandler(dom.getBuilder());
// Create a DTD monitor and pass it to the XMLReader object
final DTDMonitor dtdMonitor = new DTDMonitor();
dtdMonitor.handleDTD(reader);
_translet = (AbstractTranslet)translet;
dom.setDocumentURI(_fileName);
if (_uri)
reader.parse(_fileName);
else
reader.parse("file:"+(new File(_fileName).getAbsolutePath()));
// Set size of key/id indices
_translet.setIndexSize(dom.getSize());
// If there are any elements with ID attributes, build an index
dtdMonitor.buildIdIndex(dom, 0, _translet);
_translet.setDTDMonitor(dtdMonitor);
// Pass global parameters
int n = _params.size();
for (int i = 0; i < n; i++) {
Parameter param = (Parameter) _params.elementAt(i);
translet.addParameter(param.name, param.value);
}
// Transform the document
String encoding = translet.getOutputEncoding();
if (encoding == null) encoding = "UTF-8";
//TextOutput textOutput = new TextOutput(System.out, encoding);
DefaultSAXOutputHandler saxHandler = new
DefaultSAXOutputHandler(System.out, encoding);
TextOutput textOutput = new TextOutput(saxHandler, encoding);
translet.transform(dom, textOutput);
textOutput.flush();
if (_debug) {
TransletOutputBase handler = new TransletOutputBase();
long start = System.currentTimeMillis();
final int nTimes = 100;
for (int i = 0; i < nTimes; i++)
translet.transform(dom, dom.getIterator(), handler);
long end = System.currentTimeMillis();
System.out.println("total " + (end - start) + " msec for "
+ nTimes + " transformations");
System.out.println(((double)end - start)/nTimes + " msec avg");
}