Something Odd in JDomResult (StreamResult works fine) (?) was R: [jdom-interest] XML and XSL, fine using xt command line parser, but java.util.EmptyStackException in JDom

John caron caron at unidata.ucar.edu
Tue Aug 7 12:12:03 PDT 2001


Some more info on this error trying to use XSLT through JDomResult.

When I try to reproduce this error in Windows with the xalan that comes with jdom b7, I get a strange "java.lang.NoSuchMethodError", which i dont understand at all, see output (1) below. Under Solaris, I get a "java.util.EmptyStackException" but from some other Thread than the main, which I dont think i understand (see output 2). If I switch to using the latest xalan release (2.2 D6) (xerces version doesnt seem to matter), then I get the "java.util.EmptyStackException" from the main thread, which is what i expect (See output 3).

As danielle rizzi previously noted, if I switch to using a javax.xml.transform.stream.StreamResult instead of a JDomResult, then the transform succeeds. The actual code I used is at the bottom in case its useful.


(1) ---- output : Windows 2000 with xalan 1.3p (came with jdom b7)

+ java -classpath E:/metapps/src/test/jdom/jar;E:/lib/jdom/build/jdom.jar;E:/lib/jdom/lib/jaxp.jar;E:/lib/jdom/lib/crimson.jar;E:/lib/jdom/lib/xalan.jar; test.jdom.TestXSL

Opening XML http://www.unidata.ucar.edu/projects/THREDDS/xml/InvCatalog.xml
SAXBuilder ok
StyleSheet URL = <http://www.unidata.ucar.edu/projects/THREDDS/xml/InvCatalog.xsl>
TransformerFactory ok
java.lang.NoSuchMethodError
at org.apache.xpath.axes.ChildIterator.nextNode(ChildIterator.java:140)
at org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.java:428)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:193)
at org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.java:495)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:193)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2154)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2097)
at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2029)
at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1189)
at org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:2894)
at java.lang.Thread.run(Thread.java:484)
transform ok
$

(2) ---- output: solaris ------

/home/caron/temp/test% sh run
Opening XML http://www.unidata.ucar.edu/projects/THREDDS/xml/InvCatalog.xml
SAXBuilder ok
StyleSheet URL = <http://www.unidata.ucar.edu/projects/THREDDS/xml/InvCatalog.xsl>
TransformerFactory ok
javax.xml.transform.TransformerException
at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1212)
at org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:2894)
at java.lang.Thread.run(Thread.java:484)
---------
java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:82)
at org.jdom.input.SAXHandler.characters(SAXHandler.java:483)
at org.xml.sax.helpers.XMLFilterImpl.characters(XMLFilterImpl.java:614)
at org.apache.xalan.transformer.ResultTreeHandler.characters(ResultTreeHandler.java:446)
at org.apache.xalan.stree.TextImpl.dispatchCharactersEvent(TextImpl.java:157)
at org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.java:449)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:193)
at org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.java:495)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:193)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2154)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2097)
at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2029)
at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1189)
at org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:2894)
at java.lang.Thread.run(Thread.java:484)


-----------
(3) -- output Win2000 with xalan 2_2_D6

+ java -classpath E:/metapps/src/test/jdom/jar;E:/lib/jdom/build/jdom.jar;E:/lib/jdom/lib/jaxp.jar;E:/lib/jdom/lib/crimson.jar;E:/java/xalan-j_2_2_D6/bin/xalan.jar test.j
dom.TestXSL
Opening XML http://www.unidata.ucar.edu/projects/THREDDS/xml/InvCatalog.xml
SAXBuilder ok
StyleSheet URL = <http://www.unidata.ucar.edu/projects/THREDDS/xml/InvCatalog.xsl>
TransformerFactory ok
XSLT transform failed: javax.xml.transform.TransformerException: java.util.EmptyStackException
javax.xml.transform.TransformerException: java.util.EmptyStackException
at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1151)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:590)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1037)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1015)
at test.jdom.TestXSL.<init>(test/jdom/TestXSL.java:45)
at test.jdom.TestXSL.main(test/jdom/TestXSL.java:63)
---------
java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:82)
at org.jdom.input.SAXHandler.characters(SAXHandler.java:483)
at org.xml.sax.helpers.XMLFilterImpl.characters(XMLFilterImpl.java:614)
at org.apache.xalan.transformer.ResultTreeHandler.characters(ResultTreeHandler.java:471)
at org.apache.xml.utils.FastStringBuffer.sendSAXcharacters(FastStringBuffer.java:969)
at org.apache.xml.dtm.ref.sax2dtm.SAX2DTM.dispatchCharactersEvents(SAX2DTM.java:479)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:356)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:226)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:423)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:226)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2096)
at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:1927)
at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1120)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:590)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1037)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1015)
at test.jdom.TestXSL.<init>(test/jdom/TestXSL.java:45)
at test.jdom.TestXSL.main(test/jdom/TestXSL.java:63)


---- test code -----

package test.jdom;

import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import org.jdom.transform.*;

import java.io.*;
import java.net.*;
import java.util.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;

public class TestXSL {

  public TestXSL( String xmlURL, String styleSheet) throws MalformedURLException, IOException {

    System.out.println(" Opening XML "+xmlURL);
    URL u = new URL( xmlURL);

    Document doc = null;
    try {
      SAXBuilder builder = new SAXBuilder( true);
      doc = builder.build( u);
      System.out.println(" SAXBuilder ok");
    } catch (JDOMException e) {
      System.out.println("***SAXBuilder Parsing error= "+ e.getMessage());
      return;
    }

    System.out.println("StyleSheet URL = <"+styleSheet+">");
    Transformer transformer;
    try {
      TransformerFactory factory = TransformerFactory.newInstance();
      transformer = factory.newTransformer(new StreamSource(styleSheet));
      System.out.println(" TransformerFactory ok");
    } catch (Exception e) {
      System.out.println("TransformerFactory failed: "+e);
      return;
    }

    /* THIS WORKS
    try {
      StreamResult out = new StreamResult( System.out);
      transformer.transform(new JDOMSource(doc), out);
      System.out.println(" transform ok");
    } catch (Exception e) {
      System.out.println("XSLT transform failed: "+e);
      e.printStackTrace();
      return;
    } */


    Document tDoc = null;
    try {
      JDOMResult out = new JDOMResult();
      transformer.transform(new JDOMSource(doc), out);
      System.out.println(" transform ok");
      tDoc = out.getDocument();
    } catch (Exception e) {
      System.out.println("XSLT transform failed: "+e);
      e.printStackTrace();
      return;
    }

    if (tDoc != null) {
      System.out.println( "================================================================");
      System.out.println( "Transformed = ");
     // System.out.println( getSerializedForm(tDoc));
    }
  }

  public static void main(String[] args) {
    try {
      new TestXSL("http://www.unidata.ucar.edu/projects/THREDDS/xml/InvCatalog.xml",
               "http://www.unidata.ucar.edu/projects/THREDDS/xml/InvCatalog.xsl");
    } catch (Exception e) {
      System.out.println("Main exception = \n"+ e.getMessage());
      e.printStackTrace();
    }
  }
}



More information about the jdom-interest mailing list