R: [jdom-interest] XML and XSL, fine using xt command line parser, but java.util.EmptyStackException in JDom

daniele rizzi daniele.rizzi at ls.largesys.it
Fri Jul 20 02:10:59 PDT 2001


shouldn't you put a </xsl:stylesheet> at the end of .xsl file?

daniele.rizzi at largesys.it :-(


-----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(TransformerImpl.j
ava: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.templates.ElemTextLiteral.execute(ElemTextLiteral.java:233)
        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)

+++++++++++++++++++++++++++++++++++++++
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/youraddr@yourhos
t.com




More information about the jdom-interest mailing list