Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] Re: Output method html

From: Per Norrman <per.norrman@---------->
To:
Date: 9/6/2004 12:06:00 PM
Hi,



Carefully read this from the XSLT spec (http://www.w3.org/TR/xslt#output):



   If an XSLT processor outputs the result tree, it should do so as specified by
   the xsl:output element; however, it is not required to do so.

The <xsl:ouput> element is applicable only when the XSLT processor is
controlling the serialization to XML (i.e. generating bytes from the result
tree). JDOM's XMLOutputter have no idea that the document is a result from
a transformation that included an <output> element.

In your case, transform directly to the servlet output stream, something
along these lines:

   FileInputStream xslt = new FileInputStream(xsltpath);
   Templates tp = TransformerFactory.getTemplates(xsltpath);
   Source source = new JDOMSource(doc);
   result = new StreamResult(resp.getOutputStream());
   tp.newTransformer(source, result);

/pmn



Kaarle Kaila wrote:



hi,



I have created using JDOM an xml-structure inside my application in tomcat
5.0.
Finally I want to output the xml-structure in html-format using xslt
transformation. Else this works nicely but I cannot get the <xsl:output
method="html"/> to work.

If I get the same xml-structure in an XML-file and convert it to html using
the same xslt stylesheet using xmlstart (I believe uses libxslt) the result
is what I ask. The output encoding is iso-8859-1 and the <br/> has become
<br> etc.
When I use JDOM command to do this I get it with xml-headers, <br/> etc

Here is the code in my servlet that does the transformation:
---------------------
FileInputStream xslt = new FileInputStream(xsltpath);
XSLTransformer trans = new XSLTransformer(xslt);
Document htm = trans.transform(doc);
XMLOutputter out = new XMLOutputter();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
out.output(htm,bout);
ServletOutputStream sos = resp.getOutputStream();
sos.write(bout.toByteArray());
---------------------------

I don't know what xslt processor uses as a default. I have tried by adding
saxon.jar or saxon8.jar to the WEB-INF/lib directory with the same result.

The xslt sheet I have begins like this:



<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'

<xsl:output method="html" encoding="iso-8859-1"/>
<xsl:template match="/miniproject">
<xsl:variable name="lcopy"><xsl:value-of
select="header/copyright"/></xsl:variable>
..............
Any help would be appreciated.

Kaarle Kaila









--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
--+--


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent