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

Lukas Hazlehurst hazlehurst at paradise.net.nz
Wed Mar 19 17:50:04 PST 2003


Hi,

i'm using something similiar to the following code which outputs directly to
an output stream, without going thru the XMLOutputter. The "rs" variable is
a ResultSet which contains the XLST code, "data" is a Document which is the
xml to do the xslt transform against, "out" is the output stream.

Transformer transformer;
TransformerFactory tFactory = TransformerFactory.newInstance();
Templates t = tFactory.newTemplates(new StreamSource( new
ByteArrayInputStream( rs.getBytes("data") )));
transformer = t.newTransformer();
transformer.transform( new JDOMSource(data) , new StreamResult( out ));

In this case the xslt template has the <xsl:output method="html"
indent="yes" encoding="iso-8859-1"/> element.

This seems to work well form what i'm doing, producing the appropriate HTML
tags and so forth. Also, i can cache the transformer so subsequent
transforms are a bit quicker.

Lukas
Sofnology Ltd

> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Jacques Capesius
> Sent: Thursday, 20 March 2003 11:16 a.m.
> To: 'JDOM'
> Subject: [jdom-interest] JDOM, problems when transforming to HTML using
> XSL
>
>
> 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
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yourad
dr at yourhost.com




More information about the jdom-interest mailing list