07-27-07 12:21 AM
Java XML transformation works :-)
here is the code snippet:
In the doView method of the portlet class
.......................................................................
public void doView(PortletRequest request, PortletResponse response) throws
PortletException, IOException {
....
// Source XML File
StreamSource xmlFile = new StreamSource(new File("xmlpath"));
// Source XSLT Stylesheet
StreamSource xsltFile = new StreamSource(new File("xslpath"));
// result html file path
File resultHTMLFile = new File(path+"resulthtmlpath");
if(resultHTMLFile.exists())
resultHTMLFile.delete();
StreamResult streamResult = new StreamResult(resultHTMLFile);
// Get XML, apply Transformation, save results
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xsltFile);
transformer.transform(xmlFile, streamResult);
getPortletConfig().getContext().include("resulthtmlpath", request, response)
;
}
.......................................................................
[ Post a follow-up to this message ]
|