Here you can find the source of transformToHTML(StreamSource xmlStreamSource)
private static String transformToHTML(StreamSource xmlStreamSource) throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException
//package com.java2s; import java.io.StringReader; import java.io.StringWriter; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactoryConfigurationError; import javax.xml.transform.stream.StreamSource; public class Main { private static final String XSLT_TO_HTML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n" + "\n" + "<xsl:output method=\"xml\" version=\"1.0\" encoding=\"UTF-8\" indent=\"yes\" omit-xml-declaration=\"no\"/>\n" + "\n" + "<!-- identity template -->\n" + "<xsl:template match=\"@*|node()\">\n" + " <xsl:copy>\n" + " <xsl:apply-templates select=\"@*|node()\"/>\n" + " </xsl:copy>\n" + "</xsl:template>\n" + "</xsl:stylesheet>"; private static String transformToHTML(StreamSource xmlStreamSource) throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException { String htmlResult = null; try {/* w w w.ja va 2 s. co m*/ StringWriter writer = new StringWriter(); StringReader xsltReader = new StringReader(XSLT_TO_HTML); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory .newTransformer(new javax.xml.transform.stream.StreamSource(xsltReader)); transformer.transform(xmlStreamSource, new javax.xml.transform.stream.StreamResult(writer)); htmlResult = writer.toString(); } catch (Exception e) { } return htmlResult; } }