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

Kevin Williams kwilliams at effsols.com
Fri Jul 20 09:45:48 PDT 2001


I do have an </xsl:stylesheet> in the code, I just forgot to copy it into
the email.

I changed my code to use a StreamResult instead of a JDom result (which is
better for my code anyway, thanks).  But now I get a new error.  I'm using
the xalan.jar that came with jdomb7.  Any more clues?

Thanks!

Kevin


java.lang.NoSuchMethodError
        at
org.apache.xpath.axes.ChildIterator.nextNode(ChildIterator.java:140)
        at
org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.ja
va:428)
        at
org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.jav
a:193)
        at
org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.ja
va:495)
        at
org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.jav
a:193)
        at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2154)
        at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2097)
        at
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:
739)
        at
org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.ja
va:495)
        at
org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.jav
a:193)
        at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2154)
        at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(Transform
erImpl.java:2097)
        at
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(Transformer
Impl.java:2029)
        at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.j
ava:1189)
        at
org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.java:2894)
        at java.lang.Thread.run(Thread.java:484)



> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of daniele rizzi
> Sent: Friday, July 20, 2001 2:45 AM
> To: Kevin Williams; jdom-interest at jdom.org
> Subject: 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
>
>
>
> Dear all,
> if you mind running the following code, you'll be amazed discovering
> that a Transform into StreamResult works fine but the very same Transform
> into a JDomResult falls into a java.util.EmptyStackException
>
> any hint ?
> daniele.rizzi at largesys.it (ps. SAXResult works!, but it's not so useful)
>
>
> ---- begin of code ----
>
> package dany;
>
> import org.jdom.*;
> import org.jdom.input.*;
> import org.jdom.output.*;
> import org.jdom.transform.*;
>
> import org.xml.sax.*;
> import org.xml.sax.helpers.*;
>
> import java.io.*;
> import java.util.*;
> import java.sql.*;
>
> import javax.xml.transform.*;
> import javax.xml.transform.sax.*;
> import javax.xml.transform.dom.*;
> import javax.xml.transform.stream.*;
>
> import oracle.xml.parser.v2.* ;
>
> public class ErrorXsl  {
>
> public String xmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " +
>    "<TemplateBody><Free_Form_Text>Ref#: </Free_Form_Text>" +
>    "end of template</TemplateBody>";
>
> public String xslData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " +
>    "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" " +
>        " version=\"1.0\"> " +
>        "<xsl:template match=\"TemplateBody\"> "+
>        " Dear , <xsl:apply-templates/> Thank you for your
> business.</xsl:template> "+
>        " </xsl:stylesheet>";
>
>   /**
>    * Constructor
>    */
>
>   public ErrorXsl() {
>
>
>     try {
>
>        //1_ open xml
>
>          StringReader sr = new StringReader(xmlData);
>          SAXBuilder saxbuilder = new SAXBuilder(
>               "oracle.xml.parser.v2.SAXParser", false);
>
>          Document docXml = saxbuilder.build(sr);
>          sr.close();
>
>          System.out.println(printDocument(docXml));
>
>        //2_ open xsl
>
>        sr = new StringReader(xslData);
>
>        SAXSource ss = new SAXSource( new InputSource(sr));
>        Transformer transformer =
>             TransformerFactory.newInstance().newTransformer(ss);
>
>
>        // this works
>        //StreamResult outDoc = new StreamResult(new
> File("c:\\pippo.txt"));
>
>        // this works too!
>        //SAXResult  outDoc = new SAXResult(new DefaultHandler());
>
>        // this not!
>        JDOMResult outDoc = new JDOMResult();
>
>
>        transformer.transform(new JDOMSource(docXml), outDoc);
>
>     }
>     catch(Exception ex) {
>         System.out.println("EX:"+ex.getMessage());
>         ex.printStackTrace();
>
>     }
>
>   }
>
>
>  }
>
>   /**
>    * main
>    */
>   public static void main(String[] args) {
>     ErrorXsl errorXsl = new ErrorXsl();
>   }
> }
> ---- end of code ----
>
>
> -----Messaggio originale-----
> Da: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]Per conto di Kevin Williams
> Inviato: venerdì 20 luglio 2001 0.42
> A: jdom-interest at jdom.org
> Oggetto: [jdom-interest] XML and XSL, fine using xt command line parser,
> but java.util.EmptyStackException in JDom
>
>
> Sorry for the length, but I wanted to make sure there was enough
> information
> to determine what the error is.  When I transform the xml with
> the xsl from
> the command line, it works fine.  When using JDom (code snippet
> at bottom) I
> get an exception.  I'm new to XSL (started yesterday :) ) so it may be a
> simple error.  Thanks for your help.
>
> Here is the error I get when attempting to transform an xml string using a
> simple stylesheet:
>
> javax.xml.transform.TransformerException: java.util.EmptyStackException
>         at
> org.apache.xalan.transformer.TransformerImpl.transformNode(Transfo
rmerImpl.j
> ava:1212)
>         at
> org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.j
ava: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(ResultTr
eeHandler.
> java:446)
>         at
> org.apache.xalan.templates.ElemTextLiteral.execute(ElemTextLiteral
.java:233)
>         at
> org.apache.xalan.templates.ElemForEach.transformSelectedNodes(Elem
ForEach.ja
> va:495)
>         at
> org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTem
plates.jav
> a:193)
>         at
> org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
> (Transform
> erImpl.java:2154)
>         at
> org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
> (Transform
> erImpl.java:2097)
>         at
> org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(T
ransformer
> Impl.java:2029)
>         at
> org.apache.xalan.transformer.TransformerImpl.transformNode(Transfo
rmerImpl.j
> ava:1189)
>         at
> org.apache.xalan.transformer.TransformerImpl.run(TransformerImpl.j
ava:2894)
>         at java.lang.Thread.run(Thread.java:484)
>
> +++++++++++++++++++++++++++++++++++++++
> the XML source:
> <?xml version="1.0" encoding="UTF-8"?>
> <TemplateBody><Free_Form_Text>Ref#: </Free_Form_Text><ref_number>
>          #[ref_number]
>          <!-- This displays the reference number. -->
>       </ref_number><Free_Form_Text>
> </Free_Form_Text><Free_Form_Text>PositionType:
> </Free_Form_Text><position_type>
>          #[position_type]
>          <!-- This displays the current position type. -->
>       </position_type><Free_Form_Text>
> </Free_Form_Text><Free_Form_Text>Product ID: </Free_Form_Text><product_id>
>  #[product_id]
>          <!-- This displays the current product ID. -->
>       </product_id><Free_Form_Text>
> </Free_Form_Text><Free_Form_Text>Product Type:
> </Free_Form_Text><product_type>
>          #[product_type]
>          <!-- This displaysthe current product type. -->
>       </product_type><Free_Form_Text>
> </Free_Form_Text><Free_Form_Text>Ref# (again):
> </Free_Form_Text><ref_number>
>   #[ref_number]
>          <!-- This displays the reference number. -->
>       </ref_number><Free_Form_Text>
> </Free_Form_Text><Free_Form_Text>Product ID (again):
> </Free_Form_Text><product_id>
>          #[product_id]
>          <!-- This displays the current product ID. -->
>       </product_id><Free_Form_Text>
> </Free_Form_Text><Free_Form_Text>Ref# (yet again):
> </Free_Form_Text><ref_number>
>          #[ref_number]
>          <!-- This displays the reference number. -->
>       </ref_number><Free_Form_Text>
> </Free_Form_Text><Free_Form_Text>
> </Free_Form_Text></TemplateBody>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
> XSL template:
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:template match="TemplateBody">
> Dear #[customer],
>
> <xsl:apply-templates/>
>
> Thank you for your business.
>
> Sincerely,
>
> #[Preparer]
> </xsl:template>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
> and the code that runs it:
>       org.jdom.Document jdom =
> ((JDomStyledDocument)bodyTextArea.getDocument()).generateJDom();
>
>       StringReader stylesheet = new StringReader(letterLayout);
>
>       try {
>          Transformer transformer = TransformerFactory.newInstance()
>                              .newTransformer(new
> StreamSource(stylesheet));
>          JDOMResult out = new JDOMResult();
>          transformer.transform(new JDOMSource(jdom), out);
>          org.jdom.Document outdoc = out.getDocument();
>
>
>          ESIJDomTreeModel tempModel = new ESIJDomTreeModel(outdoc);
>          try {
>             String xmlStr = tempModel.generateXMLString();
>             letterTextPane.setText(xmlStr);
>          } catch (ESIException ex) {
>             new ESIExceptionDialog(null, ex);
>          }
>
>       } catch (TransformerException e) {
>          //throw new JDOMException("XSLT Trandformation failed", e);
>          ESILog.getLog().trace("XXXXXXXXXXXXX transform failed", e);
>       }
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yourad
dr at yourhos
t.com

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com




More information about the jdom-interest mailing list