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

Bruno Antunes bantunes at whateversoft.com
Thu Jun 21 12:29:18 PDT 2001


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.
---------------------------------------------------------------------




More information about the jdom-interest mailing list