collect_app/src/main/java/org/odk/collect/android/activities/PrintFormInstanceActivity.java
public static String StaticTransform(String strXsl, String strXml) {
        String html = "";

        try {

            InputStream ds = null;
            ds = new ByteArrayInputStream(strXml.getBytes("UTF-8"));

            Source xmlSource = new StreamSource(ds);

            InputStream xs = new ByteArrayInputStream(strXsl.getBytes("UTF-8"));
            Source xsltSource = new StreamSource(xs);

            StringWriter writer = new StringWriter();
            Result result = new StreamResult(writer);
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer(xsltSource);
            transformer.transform(xmlSource, result);

            html = writer.toString();

            ds.close();
            xs.close();

            xmlSource = null;
            xsltSource = null;

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerFactoryConfigurationError e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return html;
    }
/**
     * Transform XML and XSLT to HTML string
     **/
Transform XML and XSLT to HTML string
Transform XML and XSLT to HTML string
public static String StaticTransform(String strXsl, String strXml) {
        String html = "";
        try {
            InputStream ds = null;
            ds = new ByteArrayInputStream(strXml.getBytes("UTF-8"));
            Source xmlSource = new StreamSource(ds);
            InputStream xs = new ByteArrayInputStream(strXsl.getBytes("UTF-8"));
            Source xsltSource = new StreamSource(xs);
            StringWriter writer = new StringWriter();
            Result result = new StreamResult(writer);
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer(xsltSource);
            transformer.transform(xmlSource, result);
            html = writer.toString();
            ds.close();
            xs.close();
            xmlSource = null;
            xsltSource = null;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerFactoryConfigurationError e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return html;
    }
public static String StaticTransform ( String strXsl , String strXml ) { String html = "" ; try { InputStream ds = null ; ds = new ByteArrayInputStream ( strXml . getBytes ( "UTF-8" ) ) ; Source xmlSource = new StreamSource ( ds ) ; InputStream xs = new ByteArrayInputStream ( strXsl . getBytes ( "UTF-8" ) ) ; Source xsltSource = new StreamSource ( xs ) ; StringWriter writer = new StringWriter ( ) ; Result result = new StreamResult ( writer ) ; TransformerFactory tFactory = TransformerFactory . newInstance ( ) ; Transformer transformer = tFactory . newTransformer ( xsltSource ) ; transformer . transform ( xmlSource , result ) ; html = writer . toString ( ) ; ds . close ( ) ; xs . close ( ) ; xmlSource = null ; xsltSource = null ; } catch ( UnsupportedEncodingException e ) { e . printStackTrace ( ) ; } catch ( TransformerConfigurationException e ) { e . printStackTrace ( ) ; } catch ( TransformerFactoryConfigurationError e ) { e . printStackTrace ( ) ; } catch ( TransformerException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return html ; }
Transform XML and XSLT to HTML string
Transform XML and XSLT to HTML string