I have a performance issue concerning Java and XSLT: my goal is to transform an xml file (source.xml)
by using a given xsl file (transformation.xsl). As result I would like to get a String object, in which the result
of the transformation (html-code) is in, so that I can display it in a browser. The problem is the long time
it takes for the code below to run through.
Before, I made the same transformation in an xml development environment, named Cooktop
(see http://xmlcooktop.com/). The transformation took about 2 seconds. With the code above in Java it
takes about 20 seconds. :?
Is there a way to make the transformation in Java faster?
Thanks in advance,
Marcello
Oldenburg, Germany
xerxez@gmx.de
*****
*****
The idea to load the code before the result is requested I have implemented. But that surprisingly doesn't bring any nameable improvement in the time it takes the code to run through.
Though I think this is very close to the solution already. Next step I will try to find a way to pre-parse the input document and the transform document. Because I think that especially the large input document takes quite a while to get parsed.
Hatte vielleicht jemand schoneinmal ein ähnliches Problem und kann mir da weiterhelfen?
Kann man ein Eingabe-XML-Dokument vorab parsen und dann die Transformation ausführen? Habe bereits versucht ein DOM aus dem Eingabe-XML-Dokument zu erstellen und die Transformation dann auszuführen. Aber das DOM war anscheinend zu gross, denn ich bekam einen java.lang.OutOfMemoryError.
by using a given xsl file (transformation.xsl). As result I would like to get a String object, in which the result
of the transformation (html-code) is in, so that I can display it in a browser. The problem is the long time
it takes for the code below to run through.
Code:
xml = new File("C:\\source.xml");
xmlSource = new StreamSource(xml);
xslt = new File("C:\\transformation.xsl");
StreamSource xsltSource = new StreamSource(xslt);
TransformerFactory transFact = TransformerFactory.newInstance();
trans = transFact.newTransformer(xsltSource);
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
trans.transform(xmlSource, streamResult);
String output = stringWriter.toString();
stringWriter.close();
Before, I made the same transformation in an xml development environment, named Cooktop
(see http://xmlcooktop.com/). The transformation took about 2 seconds. With the code above in Java it
takes about 20 seconds. :?
Is there a way to make the transformation in Java faster?
Thanks in advance,
Marcello
Oldenburg, Germany
xerxez@gmx.de
*****
*****
The idea to load the code before the result is requested I have implemented. But that surprisingly doesn't bring any nameable improvement in the time it takes the code to run through.
Though I think this is very close to the solution already. Next step I will try to find a way to pre-parse the input document and the transform document. Because I think that especially the large input document takes quite a while to get parsed.
Hatte vielleicht jemand schoneinmal ein ähnliches Problem und kann mir da weiterhelfen?
Kann man ein Eingabe-XML-Dokument vorab parsen und dann die Transformation ausführen? Habe bereits versucht ein DOM aus dem Eingabe-XML-Dokument zu erstellen und die Transformation dann auszuführen. Aber das DOM war anscheinend zu gross, denn ich bekam einen java.lang.OutOfMemoryError.