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

ITOH Kazuhiro itoh at ipc.kajima.co.jp
Tue Feb 6 16:18:33 PST 2001

Dear ALL.
||I just took a cursory look, but I would say that your code needs to be
||multi-threaded. When using piped streams, you need to use separate
||threads for writing to one stream and reading from the other. If you
||don't, the result is typically a deadlock situation.
Thank you for your suggestion. Then I changed my code from using pipedIO using
jdom.output.DOMOut method.
Then I met a problem...

case1(comment outed portion with comment "work well")
In this case, I created StreamSource for xsl file.
this worked well.

I changed xsl file into org.w3c.dom.Document using org.jdom.output#DOMOutputter
as same as xml file.
Then I got error message as below:
"Parser error: stylesheet requires attribute: version"
at the sentense
  Transformer transformer = tFactory.newTransformer(new DOMSource(xslDoc));
I need this way using JDOM Document of xsl. Because I want to change it to
match user interactions and apply it to JDOM Document of xml.

Could you tell me some suggestions.

#I used birds.xml and birds.xsl including Xalan2 samples.


my code is here.
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 javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import org.jdom.*;
import org.jdom.output.XMLOutputter;
import org.jdom.output.DOMOutputter;
import org.jdom.input.SAXBuilder;

public class ApplyXalan2 {

  public ApplyXalan2() {
  public static void main(String[] args) {
    try {
      //JDOM Document
      SAXBuilder builder = new SAXBuilder(false);
      Document docXML = builder.build("data/birds.xml");
      DOMOutputter jdomOuter = new DOMOutputter();
      org.w3c.dom.Document xmlDoc=jdomOuter.output(docXML);

      File f = new File("data/birds.xsl");
      Document docXSL = builder.build(f);
      org.w3c.dom.Document xslDoc=jdomOuter.output(docXSL);
      //apply xslt using xalan2
      TransformerFactory tFactory = TransformerFactory.newInstance();
      Transformer transformer = tFactory.newTransformer(new DOMSource(xslDoc));
      transformer.transform(new DOMSource(xmlDoc), new StreamResult("data/out2.html" ));

      /* --------------------------------Work well
      TransformerFactory tFactory = TransformerFactory.newInstance();
      Transformer transformer =
        tFactory.newTransformer(new StreamSource("data/birds.xsl"));
      transformer.transform(new DOMSource(xmlDoc), new StreamResult("data/out2.html" ));
    } catch (Exception e) {

mailto:itoh at ipc.kajima.co.jp
Kazuhiro Itoh

More information about the jdom-interest mailing list