I am trying to convert an XML document using XSLT. As input, I have the source code www.wordpress.org XHTML, and XSLT is a fictitious example of getting the site title (in fact, it could not do anything - it does not change anything).
Each conversion or API I use takes about 2 minutes to convert! If you look at the source of wordpress.org, you will notice that these are just 183 lines of code. Since I googled, this is probably related to building the DOM tree. No matter how simple it is in XSLT, it is always 2 minutes, so it confirms the idea that this is related to building the DOM, but in any case it will not take 2 minutes, in my opinion.
Here is a sample code (nothing special):
TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = null; try { transformer = tFactory.newTransformer( new StreamSource("/home/pd/XSLT/transf.xslt")); } catch (TransformerConfigurationException e) { e.printStackTrace(); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); System.out.println("START"); try { transformer.transform(new SAXSource(new InputSource( new FileInputStream("/home/pd/XSLT/wordpress.xml"))), new StreamResult(outputStream)); } catch (TransformerException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println("STOP"); System.out.println(new String(outputStream.toByteArray()));
This is between START and STOP, where java "pause" for 2 minutes. If I look at processor or memory usage, nothing increases. It looks like the JVM has stopped ...
Do you have experience converting XML that is longer than 50 (this is a random number;))? Since I'm reading XSLT, you always need to build a DOM tree in order to do its job. Fast conversion is crucial to me.
Thanks in advance, Peter
source share