Posted By:
Fredrik_Andersson
Posted On:
Thursday, April 19, 2001 01:17 AM
TempXSL Hola! I need to merg some XML-content, styled with XSL to a JSP-file. But my code only results in XSL-content in the JSP-file. This is how it should work: 1 I recive data from a form to a Servlet, and store that in a XML-file: //method in the servlet: public void createXMLFile() { data = " <?xml version="1.0"?>" + " " + " <?xml-stylesheet type="text/xsl" href="xsl/tempxsl.xsl"?>" + " " + " " + " " + " " + " " + "
More>>
TempXSL
Hola!
I need to merg some XML-content, styled with XSL to a JSP-file.
But my code only results in XSL-content in the JSP-file.
This is how it should work:
1 I recive data from a form to a Servlet, and store that in a XML-file:
//method in the servlet:
public void createXMLFile()
{
data = "
<?xml version="1.0"?>" + "
" +
"
<?xml-stylesheet type="text/xsl" href="xsl/tempxsl.xsl"?>" + "
" +
"
" +
"
" + "
" +
" " + "
" + header + "
" + "
" +
" " + "
" + text + "
" + "
" +
"
";
try
{
xmlFile = new File(System.getProperty("user.dir") + "\applications\develop\htdocs\allerTest", fileName + ".xml");
FileWriter fileWriter = new FileWriter(xmlFile);
fileWriter.write(data, 0, data.length());
fileWriter.flush();
}
catch(IOException ioe)
{
}
}
2 Then I have to merg this new XML-file with a XSL-file into a JSP-file:
//method in the servlet:
public void createJSPFile()
{
try
{
XMLFileMerger xMLFileMerger = new XMLFileMerger();
xslFile = new File(System.getProperty("user.dir") + "\applications\develop\htdocs\allerTest\xsl", "tempxsl" + ".xsl");
jspFile = new File(System.getProperty("user.dir") + "\applications\develop\htdocs\allerTest", "tempjsp" + ".jsp");
FileOutputStream fileOutputStream = new FileOutputStream(jspFile);
xMLFileMerger.transform(xmlFile.getAbsolutePath(), xslFile.getAbsolutePath(), fileOutputStream);
}
catch(FileNotFoundException fne)
{
}
}
3 This method above uses a bean called xMLFileMerger, and calls a method in that bean called transform:
//method in the XMLFileMerger:
public void transform(String xmlURI, String xslURI, java.io.OutputStream target)
{
try
{
XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
processor.process(new XSLTInputSource(xmlURI), new XSLTInputSource(xslURI), new XSLTResultTarget(target));
}
catch(Exception e)
{
}
}
4 All this just result in a jsp-file with the same content as the xsl-fil.
My ide were that it shuld be a HTML-content with the data from the XML-file inserted in a JSP-file.
Hope some one can help me!
PS I just show the xsl-file and the xml-file:
XML, created by the servlet:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="xsl/tempxsl.xsl"?>
Sagan om..
Bla bla bla bla
XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
-->
Best Regards
Fredrik