XMLUtils { public static String transformXML(final InputStream xml, final InputStream xslt) throws TransformerConfigurationException, TransformerException { TransformerFactory tFact = TransformerFactory.newInstance(); Transformer transformer = tFact.newTransformer(new StreamSource(xslt)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); transformer.transform( new StreamSource(xml), new StreamResult(bos) ); String transformedXML = bos.toString(); return transformedXML; } private  XMLUtils(); static String transformXML(final InputStream xml, final InputStream xslt); static String createPrettyXML(Document document); static XPathExpression createXPathExpression(final String expression); static Boolean createBooleanUsingXPathExpression(String expression, String xml); static NodeList createNodeListUsingXPathExpression(String expression, String xml); static Node createNodeUsingXPathExpression(String expression, String xml);  }
@Test public void transformXMLTest() throws FileNotFoundException, TransformerConfigurationException, TransformerException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); String fileSeparator = System.getProperty("file.separator"); URL xmlFileLocation = cl.getResource("Sample_Files"+fileSeparator+"XSLT"+fileSeparator+"sample.xml"); URL xsltFileLocation = cl.getResource("Sample_Files"+fileSeparator+"XSLT"+fileSeparator+"sample.xsl"); File sampleXMLFile = null; File xsltFile = null; try { sampleXMLFile = new File(xmlFileLocation.toURI()); xsltFile = new File(xsltFileLocation.toURI()); } catch (URISyntaxException e) { assertTrue("Exception encountered: " + e.getMessage(), false); } assertTrue(sampleXMLFile.exists()); assertTrue(xsltFile.exists()); FileInputStream xmlFis = new FileInputStream(sampleXMLFile); FileInputStream xslFis = new FileInputStream(xsltFile); String result = XMLUtils.transformXML(xmlFis, xslFis); assertTrue(result != null); assertTrue(result.contains("Input: FEATURE_ATTRIBUTE_NAME")); assertTrue(result.contains("Data: 1999-12-30T00:00:00.000Z")); assertTrue(result.contains("Input: FEATURE_COLLECTION")); assertTrue(result.contains("< Complex Value Reference (not shown) >")); assertTrue(result.contains("Mime Type: text/csv")); }