[jdom-interest] JDOMSource and JDOMResult can produce nothing!

Laurent Bihanic laurent.bihanic at atosorigin.com
Fri Jun 22 01:11:15 PDT 2001


You stylesheet generates ill-formed XML: The output misses a document root 
element as signaled by the java.util.EmptyStackException thrown by SAXHandler. 
Thus, JDOMResult is unable to build a JDOM document from the XLST processor 
output.

Once I changed the first template to:
   <xsl:template match="/">
<root>
    <xsl:apply-templates/>
</root>
   </xsl:template>
your example runs fine.

Please note that XMLOutputter can not output HTML, only XML, and that the 
<xsl:output ... /> tag only applies when the XSLT processor performs itself 
the output to a StreamResult.

Laurent


Bruno Antunes wrote:

> Hi. I am getting no output from a XSLT transformation using JDOM beta 6,
> and using the latest version in CVS repositories.
> 
> Using this code to transform the Document, gives no output:
> 
> public Document transformDoc(Document in, String stylesheet)
>         throws JDOMException {
>     try {
>         Transformer transformer = TransformerFactory.newInstance()
>                 .newTransformer(new
> StreamSource(getXSLStream(stylesheet)));
>         JDOMResult out = new JDOMResult();
>         transformer.transform(new JDOMSource(in), out);
>         return out.getDocument();
>     } catch (TransformerException e) {
>         throw new JDOMException("XSLT Transformation failed", e);
>     } catch (IOException ioe) {
>         throw new JDOMException("XSLT Transformation failed", ioe);
>     }
> }
> 
> public void transform(Document doc, String xslName, Writer w) throws
> IOException, JDOMException {
>     Document doc2 = transformDoc(doc, xslName);
>     XMLOutputter out = new XMLOutputter();
>     out.setOmitEncoding(true); // i can comment this having the same
> results
>     out.output(doc2, w);
> }
> 
> However, if I convert the JDOM Document to a String, everything works::
> 
> private static void transformDocTemporary(Document in, String
> stylesheet, Writer writer)
>         throws JDOMException {
>     try {
>         Transformer transformer = TransformerFactory.newInstance()
>                 .newTransformer(new
> StreamSource(getXSLStream(stylesheet)));
>         XMLOutputter out = new XMLOutputter();
>         StringReader reader = new StringReader(out.outputString(in));
>         transformer.transform(new StreamSource(reader), new
> StreamResult(writer));
>     } catch (TransformerException e) {
>         throw new JDOMException("XSLT Transformation failed", e);
>     } catch (IOException ioe) {
>         throw new JDOMException("XSLT Transformation failed", ioe);
>     }
> }
> 
> I tried all the Xerces, Xalan, Crimson that I could think of, none of
> them worked.
> 
> I am using this xml document that I have created with JDOM API
> 
> <?xml version="1.0">
> <products>
>   <product>
>     <PRODUCTID>226</PRODUCTID>
>     <VERSIONID>1</VERSIONID>
>     <NAME>df</NAME>
>     <COMERCIALDESC>sdf</COMERCIALDESC>
>     <VERSION>0.1</VERSION>
>   </product>
>   <product>
>     <PRODUCTID>221</PRODUCTID>
>     <VERSIONID>5</VERSIONID>
>     <NAME>ewe</NAME>
>     <COMERCIALDESC>wewe</COMERCIALDESC>
>     <VERSION>0.1</VERSION>
>   </product>
>   <product>
>     <PRODUCTID>235</PRODUCTID>
>     <VERSIONID>1</VERSIONID>
>     <NAME>ooo</NAME>
>     <COMERCIALDESC>oooo</COMERCIALDESC>
>     <VERSION>0.1</VERSION>
>   </product>
>   <product>
>     <PRODUCTID>229</PRODUCTID>
>     <VERSIONID>3</VERSIONID>
>     <NAME>produto spa1</NAME>
>     <COMERCIALDESC>descrição produto spa1</COMERCIALDESC>
>     <VERSION>0.1</VERSION>
>   </product>
> </products>
> 
> I am using this XSL:
> 
> <?xml version="1.0" encoding="iso-8859-1"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>     <xsl:output method="html" indent="yes" />
>     <xsl:template match="/">
>         <xsl:apply-templates/>
>     </xsl:template>
> 
>     <xsl:template match="products">
>         <xsl:apply-templates/>
>     </xsl:template>
> 
>     <!--xsl:template match="product">
>       <xsl:apply-templates select="component"/>
>     </xsl:template-->
> 
>     <xsl:template match="product">
>         <font face="Verdana, Arial, Helvetica, sans-serif" size="1"
> color="#000000">
>             <a href="javascript:visualizarProduto('{PRODUCTID}')">
>                 <xsl:value-of select="NAME"/>
>             </a>
>         </font>
>         <br/>
>     </xsl:template>
> </xsl:stylesheet>
> 
> Note: If I remove the <br/> from XSL. I can see transformed the first
> xml product entry.
> 
> --
> Bruno Antunes,
> Java Software Engineer
> 
> email: mailto:bruno.antunes at whateversoft.com
> Phone: +351.21.7994200
> Fax  : +351.21.7994242
> 
> WhatEverSoft - Java Center
> Centro de Competencia Java
> Praca de Alvalade, 6 - Piso 4
> 1700-036 Lisboa - Portugal
> URL: http://www.whatevernet.com
> 
> 
> 
> _____________________________________________________________________
>                       INTERNET MAIL FOOTER 
> A presente mensagem pode conter informação considerada confidencial.
> Se o receptor desta mensagem não for o destinatário indicado, fica
> expressamente proibido de copiar ou endereçar a mensagem a terceiros.
> Em tal situação, o receptor deverá destruir a presente mensagem e por
> gentileza informar o emissor de tal facto.
> ---------------------------------------------------------------------
> Privileged or confidential information may be contained in this
> message. If you are not the addressee indicated in this message, you
> may not copy or deliver this message to anyone. In such case, you
> should destroy this message and kindly notify the sender by reply
> email.
> ---------------------------------------------------------------------
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com


-- 

                  wWw
                 (o o)
-------------ooO-(_)-Ooo-----------------------------------------------
Laurent Bihanic           | Tel: +33 (0)1 55.91.21.93  (Direct line)
Atos Origin               |      +33 (0)1 55.91.20.00
Intégration - e-Business  | Fax: +33 (0)1 55.91.22.31
Les Miroirs - Bat. C      |
18, avenue d'Alsace       |
F-92926 La Defense Cedex  | e-Mail: laurent.bihanic at atosorigin.com
-----------------------------------------------------------------------

"Microsoft isn't the answer. Microsoft is the question and the answer
  is no."


DISCLAIMER:
The opinions expressed are entirely my own and may not necessarily be
those of my employer.  Also, I am not now nor have I ever been a
lawyer.  My opinions are provided as-is with absolutely no warrantee of
merchantability or fitness for any particular use.  Besides, you can't
prove I typed this.  No body saw me type this.  Who says I typed this?




More information about the jdom-interest mailing list