[jdom-interest] JDOM, problems when transforming to HTML using XSL

Jacques Capesius jacques_capesius at cnt.com
Wed Mar 19 15:16:12 PST 2003


Hi folks, 

I'm using the following lines of code to try to transform a JDOM document
using XSL, then sending it over the wire as an HTML document:

PrintWriter out = response.getWriter();
StreamSource xsl = new StreamSource(new java.io.File(xslFile));
Transformer transformer =
TransformerFactory.newInstance().newTransformer(xsl);
org.jdom.transform.JDOMResult output = new org.jdom.transform.JDOMResult();
transformer.transform(new org.jdom.transform.JDOMSource(psq), output);
org.jdom.output.XMLOutputter dump = new org.jdom.output.XMLOutputter();
dump.output(output.getDocument(),out);

It outputs it to HTML alright, but not without problems. XSLT requires the
HTML tags within the XSL document to conform to XML standards, hence be
closed, thus..

<input type="radio" value="yes"> needs to be <input type="radio"
value="yes"/>

.. the only thing is, the transformer spits out the tag, still in XML
format. As a result, I can't check the radio button!

another thing it does which I find perplexing is that when I do something
like..

<textarea rows="3" cols="4" name="address">
<xsl:value-of select="/question/answer"/>
</textarea>

and the value-of doesn't find anything, the transformer outputs 
<textarea rows="3" cols="4" name="address"/> and omits the closing
</textarea> tag. The result, as you can guess, is that everything after the
tag is viewed as a part of the text area.

I have a <xsl:output method="html" indent="yes" encoding="ISO-8859-1" /> tag
at the top of the XSL document, but that doesn't seem to help.

I s'pose I could get around these two problems by switching the JDOM
document back to a DOM document, then using the DOM transformer, which works
fine for me, but I'd really like to fix this within the JDOM.

Does anybody know of ways to deal with this behavior and get the stuff to
output as true HTML?

Thanks for whatever help you can give.

-jacques :)

Jacques Capesius
CNT Senior E-Business Developer
jacques_capesius at cnt.com
(763) 268-6749



More information about the jdom-interest mailing list