[jdom-interest] JDOM -> Xalan using PipedStreams

Karachiwala, Aslam Aslam.Karachiwala at tfn.com
Thu Aug 2 14:04:59 PDT 2001

Problem solved! Here's what I did...

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;

import com.tfm.util.DefaultLog;

public class AKServlet extends HttpServlet
	static final boolean IS_DEBUG = true;
	public void doGet(HttpServletRequest request, HttpServletResponse
	throws ServletException, IOException 
     	doPost(request, response);
    public void doPost(HttpServletRequest request, HttpServletResponse
	throws ServletException, IOException 
		ServletOutputStream svltout = response.getOutputStream();
	private void DbListPage(OutputStream out) 
logDebug("DBListPage: get data from db...");
			OracleRetainer or = new OracleRetainer();

logDebug("DBListPage: Piped I/O streams...");
			PipedOutputStream pos = new PipedOutputStream();
			PipedInputStream pis = new PipedInputStream(pos);
			StreamSource src = new StreamSource(pis);
logDebug("DBListPage: get data as XML stream...");
logDebug("DBListPage: XLS StreamSource...");
			File xlsf = new
			StreamSource srcxls = new StreamSource(xlsf);
logDebug("DBListPage: TransformerFactory.newInstance()...");
			TransformerFactory transformerFactory 
				= TransformerFactory.newInstance();
logDebug("DBListPage: transformerFactory.newTransformer()...");
			Transformer xformer =
logDebug("DBListPage: xformer.transform()...");		
			xformer.transform(src, new StreamResult(out));
logDebug("DBListPage: ...xformer.transform() done!");		

		catch (Exception e)
	static void logDebug(String logMsg)
		if (IS_DEBUG) DefaultLog.logDebug(logMsg);
-----Original Message-----
From: Karachiwala, Aslam 
Sent: Wednesday, August 01, 2001 6:04 PM
To: 'jdom-interest at jdom.org'
Subject: [jdom-interest] JDOM -> Xalan using PipedStreams


Re. the thread included below, Markus, I'd appreciate your updated sample. 

Here's what we're trying to do w/ JDOM & Xalan (rls jdom-b7)...

- construct XML output from a JDBC resultset via JDOM & write it to a
PipedOutputStream (pos)

- connect pos to the PipedInputStream (pis) from which I create a
StreamSource (srcxml)

- create new Transformer instance (xformer) from TransformerFactory for the
StreamSource created from the stylesheet file (srcxls)

- call xformer.transform(srcxml, streamResult)

We find that the above call to transform() simply "hangs." The only case in
which it succeeds is when srcxls & srcxml are created from filepaths of
actual files on disk (doing this with even File objects didn't work). We've
verified that all's OK with the XML constructed and fed to the transformer.
We've been able to successfully write to streamResult instances created from
File as well as FileOutputStream objects.

BTW, I also tried mimicking the example in Brett's tip --
http://www-106.ibm.com/developerworks/java/library/x-tipjdom.html -- without

Any ideas, anyone?


Aslam Karachiwala
Online Development
Thomson Financial Insurance Solutions
One Alewife Center, Suite 460
Cambridge, MA 02140
phone: 617-441-5918
fax: 617-864-2396
<mailto:aslam.karachiwala at tfn.com>
From: markus_tripp at sonynetservices.com (markus_tripp at sonynetservices.com)
Date: Wed, 7 Feb 2001 09:38:34 +0100
Subject: [jdom-interest] Help XSLT/Piped Streams?

Hi Charlie,

I know the problem. I posted the below message two or three months ago and
since then there have been some major changes in the package structure of
the xalan 2 xlst framework. I used Xalan-Java version 2.0.D01 which had an
own trax package. I have not updated my sample because there was no reason

If you would like to read the reason for the changes go to:

If someone wants an update of the sample please let me know.


Charlie Wu <daydayup at pabell.net> on 07.02.2001 08:50:22

An:   markus_tripp at sonynetservices.com
Kopie:    jdom-interest at jdom.org
Thema:    Re: [jdom-interest] Help XSLT/Piped Streams?

Hi Markus:

I'm trying to compile your JDOMSimpleXSLTProcessor.java but somehow the
can't seem to be able to find these org.apache.trax.* files.. I have the
latest xalan-j_2_0_0
installed along with the latest xerces.jar, and I even un-jarred xalan.jar
but under org/apache
there is no trax directory.. only xml, xpath and xalan..

Any ideas what I'm missing here?



----- Original Message -----
From: <markus_tripp at sonynetservices.com>
To: <Nick at neoworks.com>
Cc: <jdom-interest at jdom.org>
Sent: Tuesday, November 14, 2000 7:27 AM
Subject: Re: [jdom-interest] Help XSLT/Piped Streams?

> Hello,
> for test purposes it is often useful to process a XSLT transformations
> directly from a JDOM document using a XSL stylesheet. I know that a
> integration of XSLT into JDOM would be much better - and I think Bob is
> working on this - but sometimes a version which pipes the output to an
> external XSLT processor like Xalan would help for the moment. I wrote
> a simple class which uses Apache Xalan 2 (http://xml.apache.org). I have
> attached the source file "JDOMSimpleXSLTProcessor.java" to this email.
> Within my project I placed the file into the package
> "org.jdom.contrib.xslt" because did not find a better place for now.
> Because I am behind a firewall I cannot place it directly to the CVS.
> Requirements:
> =============
> xalan.jar and xerces.jar in the classpath (make sure to have the latest
> Xalan 2 version in the classpath).
> Sample Code of using JDOMSimpleXSLTProcessor
> (TestJDOMSimpleXSLProcessor.java):

> import org.jdom.Document;
> import org.jdom.Element;
> import org.jdom.contrib.xslt.JDOMSimpleXSLTProcessor;
> import org.xml.sax.InputSource;
> import org.apache.trax.Result;
> public class TestJDOMSimpleXSLTProcessor {
>   public static void main(String[] args) {
>     Document document;
>     Element element;
>     InputSource xsl = new InputSource("foo.xsl");
>     Result out = new Result(System.out);
>     element = new Element("doc");
>     element.setText("Hello");
>     document = new Document(element);
>     try {
>       JDOMSimpleXSLTProcessor.process(document, xsl, out);
>     }
>     catch(Exception e) {
>       e.printStackTrace();
>     }
>   }
> }
> XSL file (foo.xsl):
> ===================
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   <xsl:template match="doc">
>     <out><xsl:value-of select="."/></out>
>   </xsl:template>
> </xsl:stylesheet>
> Markus Tripp
> (See attached file: JDOMSimpleXSLTProcessor.java)
> Nick Vincent <Nick at neoworks.com>@jdom.org on 13.11.2000 18:35:32
> Gesendet von:  jdom-interest-admin at jdom.org
> An:   "'jdom-interest at jdom.org'" <jdom-interest at jdom.org>
> Kopie:
> Thema:    [jdom-interest] Help XSLT/Piped Streams?
> Hi,
> I'm using JDOM at the moment, and am trying to pipe an output stream into
> Xalan, as per the instructions in the JDOM FAQ.  I have tried to get this
> working a lot of ways, but when I attempt to pipe the input the XSLT
> hangs, as if it is still waiting for input from the input stream.
> The same code works if replace the input stream with othewr stream types
> (i.e. strings, files), and I have tried flushing the streams everywhere I
> can to no avail.  Is there any sample code of this working (I have
> out CVS today to see if this example has been added, but could not find
> it)?
> Many thanks,
> Nick Vincent
> NeoWorks

To control your jdom-interest membership:

More information about the jdom-interest mailing list