Converting XML+XSL in HTML using Java

56
September 13, 2017, at 10:07 PM

We have data as XML and there are multiple formatting XSL styles. It was working fine till now in IE.

Then, We needed to display the same content as HTML in Chrome. So, We found an API on server side (Java) to transform XML+XSL to HTML.

public static String convertXMLXSL(String xml, String xsl) throws SQLException {
        System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl");
        TransformerFactory tFactory = TransformerFactory.newInstance();
        String html = "";
        try {
            try {
                StreamResult result = new StreamResult(new StringWriter());
                **Transformer trans = tFactory.newTransformer(new StreamSource(new ByteArrayInputStream(xsl.getBytes("utf-8"))));
                trans.transform(new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8"))), result);**
                html = result.getWriter().toString();
            } catch (TransformerException te) {
                te.printStackTrace();
            }
        } catch (Exception e) {
            AppendExceptionToLog(e);
        }
        return html;
    } 

But, Now after sometime, We see some thread dumps which are blocked at trasform method of javax.xml.transform.Transformer

    Sep 12, 2017 12:07:49 PM org.apache.catalina.valves.StuckThreadDetectionValve notifyStuckThreadDetected
WARNING: Thread "http-8080-12" (id=15800) has been active for 6,516 milliseconds (since 9/12/17 12:07 PM) to serve the same request for
 and may be stuck (configured threshold for this StuckThreadDetectionValve is 5 seconds). 
 There is/are 3 thread(s) in total that are monitored by this Valve and may be stuck.
java.lang.Throwable
    at org.apache.xpath.axes.AxesWalker.getNextNode(AxesWalker.java:333)
    at org.apache.xpath.axes.AxesWalker.nextNode(AxesWalker.java:361)
    at org.apache.xpath.axes.WalkingIterator.nextNode(WalkingIterator.java:192)
    at org.apache.xpath.axes.NodeSequence.nextNode(NodeSequence.java:281)
    at org.apache.xpath.axes.NodeSequence.runTo(NodeSequence.java:435)
    at org.apache.xpath.axes.NodeSequence.setRoot(NodeSequence.java:218)
    at org.apache.xpath.axes.LocPathIterator.execute(LocPathIterator.java:210)
    at org.apache.xpath.XPath.execute(XPath.java:335)
    at org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:278)
    at org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:246)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2281)
    at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1367)
    at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
    at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1284)
    at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1262)
    at Util.processXMLXSL(Util.java:3364)

Here, I wanted to know..

1) Do we have any other known implementation do the same on server side ?

2) Should I consider using client side approach using XSLTProcessor of Mozilla ?

Answer 1

Open this link to the solution http://www.htmlgoodies.com/beyond/xml/converting-xml-to-html-using-xsl.html

READ ALSO
How can I parse a csv in low memory, using some parser in Java?

How can I parse a csv in low memory, using some parser in Java?

I used InputStream, and on parsing, if there is a "," in one column then it considers it as a separate columnex - abc, xyz, "m,n" then the parsed output is abc , xyz, m, n Here m and n are considered as separate columns

34
Spring JdbcTemplate “insert into.. select from..” not working

Spring JdbcTemplate “insert into.. select from..” not working

I am trying to execute following SQL with Spring JdbcTemplate:

41
@RolesAllowed has no effect on my RESTful Service

@RolesAllowed has no effect on my RESTful Service

I'm having some trouble with setting up my secure REST-ServiceI wanted to create a simple login/logout service and mess around with it

31
How can I examine external source code for incidence of dead code? [on hold]

How can I examine external source code for incidence of dead code? [on hold]

Recently I received JAVA application to write for my university classesThis is the task:

58