[jdom-interest] clarification of an FAQ...

Wayne Buckhanan buck at andrews.edu
Wed Feb 14 10:56:26 PST 2001

I'm trying to use JDOM to read in my XML document and modify it then run
it through Xalan's XSL transform, but it isn't working and I'm not
catching on why it isn't giving me any output.
I did a transform on my unmodified XML file by just having Xalan read
the file directly, so I'm guessing my trouble is in the PipedI/OStream
suggestion in the FAQ.
any feedback would be wonderful.

--->8--- start working.jsp ---8<---

String xmlFileName = "template.xml";
String xslFileName = "html.xsl";

	// 1. Instantiate a TransformerFactory.
javax.xml.transform.TransformerFactory tFactory =
	// 2. Use the TransformerFactory to process the stylesheet Source and
	//    generate a Transformer.
javax.xml.transform.Transformer transformer = tFactory.newTransformer
                (new javax.xml.transform.stream.StreamSource(xslFileName));
javax.xml.transform.Source inXML = new javax.xml.transform.stream.StreamSource(xmlFileName);
javax.xml.transform.Result outXML = new javax.xml.transform.stream.StreamResult( out );
	// 3. Use the Transformer to transform an XML Source and send the
	//    output to a Result object.
transformer.transform( inXML, outXML );

--->8--- end working.jsp ---8<---

--->8--- start non-working.jsp ---8<---
<%@ page import="org.jdom.*" %>
<%@ page import="java.io.*" %>
<%@ page import="org.jdom.input.*" %>
<%@ page import="org.jdom.output.*" %>
<%@ page import="javax.xml.transform.*" %>
<%@ page import="javax.xml.transform.stream.*" %>

String xmlFileName = "template.xml";
String xslFileName = "html.xsl";

SAXBuilder builder = new SAXBuilder(false);
Document doc = builder.build(xmlFileName);
XMLOutputter outputter = new XMLOutputter();
PipedOutputStream toXSL = new PipedOutputStream();
PipedInputStream fromJDOM = new PipedInputStream( toXSL );

outputter.output(doc, toXSL);

javax.xml.transform.TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer (new StreamSource(xslFileName));
Source inXML = new StreamSource( fromJDOM );
Result outHTML = new StreamResult( out );
transformer.transform( inXML, outHTML );

catch(JDOMException e)
{ // this space intentionally left blank
	out.println( e.getMessage() );
--->8--- end non-working.jsp ---8<---

Wayne Buckhanan					buck at andrews.edu
Piro:				Largo:
"Why are you naked?"		"One must take drastic measures to prevent 
				static discharge.  Care must be taken to 
(Visit Piro and Largo at	preserve the purity of these components."

More information about the jdom-interest mailing list