[jdom-interest] [Q}How to Applay XSL using Xalan2

ITOH Kazuhiro itoh at ipc.kajima.co.jp
Mon Feb 5 21:43:00 PST 2001


Dear All:

I tried to apply XSL to JDOM Document. I read FAQ about using Xalan.
Then I made small example as follows.
But This programm stops at
     jdomOuter.output(docXSL, poutXSL);
Are there anything wrong in my code ?
Could you tell me them, please

I use JDK1.3 & JDOM-b5 & Xalan2.

Thanks....
------------------------------start ------------------------------
import java.io.*;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.jdom.*;
import org.jdom.output.XMLOutputter;
import org.jdom.input.SAXBuilder;

public class ApplyXalan {

  public ApplyXalan() {
  }
  public static void main(String[] args) {
    try {
      //JDOM Document
      SAXBuilder builder = new SAXBuilder();
      Document docXML = builder.build("data/testSchedule.xml");
      Document docXSL = builder.build("data/dispScheduleSort.xsl");
      //creating Outputter
      XMLOutputter jdomOuter = new XMLOutputter();
      jdomOuter.setEncoding("Shift_JIS");//Japanese encoding

      //creating piped IO for XSLT file
      PipedOutputStream poutXSL = new PipedOutputStream();
      PipedInputStream pinXSL = new PipedInputStream(poutXSL);
      jdomOuter.output(docXSL, poutXSL);//This programm stops here
      poutXSL.flush();

      //creating piped IO for XML file
      PipedOutputStream poutXML = new PipedOutputStream();
      PipedInputStream pinXML = new PipedInputStream(poutXML);
      jdomOuter.output(docXML, poutXML);
      poutXML.flush();
      //Apply XSLT to JDOM using xalan2
      TransformerFactory tFactory = TransformerFactory.newInstance();
      Transformer transformer=
                    tFactory.newTransformer(new StreamSource(pinXSL));
      transformer.transform(new StreamSource(pinXML),
                            new StreamResult("data/out2.html" ));
      pinXML.close();
      pinXSL.close();
      poutXML.close();
      poutXSL.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
------------------------------end------------------------------

      _/_/_/_/_/__/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
mailto:itoh at ipc.kajima.co.jpKazuhiro Itoh



More information about the jdom-interest mailing list