[jdom-interest] JDOM to XSLT

Itai Erner itaie at bigfoot.com
Sun Aug 27 01:52:08 PDT 2000


Hi,
Heres the solution I found in the archive .. (sorry I dont have the name of 
the one who initially wrote it .. )

public Document process( Document xmlin, StylesheetRoot ssr )
	throws JDOMException, IOException {
		
	// jdom -> xalan -> jdom
	// this method pipes a jdom tree into the xslt processor and
	// the resulting stream is piped into a jdom SAXBuilder again

	// pipe JDOM output to Xalan input
	final Document xml = xmlin;
	final StylesheetRoot xslprocessor = ssr;

	final PipedInputStream xis = new PipedInputStream();
	final PipedOutputStream pos = new PipedOutputStream(xis);

	// call a new thread which pipes the outputstream given to the
	// JDOM outputter into our inputstream.
	new Thread() {
		public void run() {
			try {
				new XMLOutputter("", false, "ISO-8859-1").output( xml, pos );
				pos.close();
			}
			catch(Exception e) {
			}
		}
	}
	.start();

	// now do the xsl transformation
	final PipedInputStream pis = new PipedInputStream();
	final PipedOutputStream xos = new PipedOutputStream(pis);

	// make a new thread which calls the xalan processor
	new Thread() {
		public void run() {
			try {
				xslprocessor.process( new XSLTInputSource( xis ), new XSLTResultTarget( 
xos ) );
				xos.close();
			}
			catch(Exception e) {
				// FIXME: do some error handling
			}
		}
	}
	.start();
	// and finaly build your resulting JDOM tree from the pipe.
	Document xmlout = new SAXBuilder().build( pis );
	
	return xmlout;
}

============================

         Valis - The Cellular Cult

============================




More information about the jdom-interest mailing list