list4xt : Mailing list for the XT users community.
[list4xt] XT calls in Java method
Subject: [list4xt] XT calls in Java method
User: Website From: Paul Cooper (pcooper@llan.net)
Date: 05/02/2001 - 23:05
Hi, I'm new to using XT and I'm therefore probably missing some fundemantal
concept, however I would reall appreciate some help.
I'm trying to develop a general purpose Java method which takes a XSL file
and an XML document object as input parameters, could someone therefore
please point out the flaws in the following code which simply results in the
original XML document as an output (parsed nicley I might add :-) ) string?
/**
* Uses XT to XSL-transform the given XML document using the style sheet
at the given URI.
* The result is written to the given ServletResponse instance.
*
* @param xmlDoc org.w3c.dom.Document the XML document to be transformed
* @param stylesheetURI String location of the XSL style sheet to be used.
* @param response javax.servlet.ServletResponse response object.
*/
public String transform2(Document xmlDoc, String stylesheetURI) throws
Exception
{
// locate style sheet
org.xml.sax.InputSource inputXSL = new
org.xml.sax.InputSource(stylesheetURI);
if(inputXSL == null)
{
throw new Exception("Can't locate style sheet " + stylesheetURI );
}
// create xsl processor
XSLProcessorImpl xslProcessor = new
com.jclark.xsl.sax.XSLProcessorImpl();
org.apache.xerces.parsers.SAXParser parser = new
org.apache.xerces.parsers.SAXParser();
xslProcessor.setParser(parser);
// load style sheet
xslProcessor.loadStylesheet(inputXSL);
// Write the XML document to a String so we can read it as a stream
StringWriter sw = new StringWriter();
XMLSerializer ser = new XMLSerializer(sw,new OutputFormat(xmlDoc));
ser.serialize(xmlDoc.getDocumentElement());
// create an input source for the XML document
StringReader sr = new StringReader(sw.toString());
org.xml.sax.InputSource inputXML = new org.xml.sax.InputSource(sr);
// Wrap the output stream into something the XSL processor can handle
java.io.StringWriter output = new java.io.StringWriter();
HTMLOutputHandler docHand = new HTMLOutputHandler(output);
xslProcessor.setDocumentHandler( docHand );
// Finally do the transformation. The output handler automatically
// writes the result to the
// servlet response stream
xslProcessor.parse(inputXML);
return output.toString();
}
Thanks in advance.
Paul Cooper - pcooper@llan.net
--
Mailing list for the XT users community. (http://veterancentral.org)
(mailto:list4xt-request@4xt.org?Subject=unsubscribe to unsubscribe)
Archive générée par hypermail 2b28 le 25/04/2001 - 07:16 CEST
webmaster@4xt.org
|