Created
July 2, 2019 09:48
-
-
Save tkrisztian95/3952429c1b0c55b51ba61562ac450e9c to your computer and use it in GitHub Desktop.
Transform XML string by XSLT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class XmlUtils { | |
public static String XsltTransform(String xml, String xslt) throws TransformerException { | |
Source xsltSource = new StreamSource(new StringReader(xslt)); | |
Source xmlSource = new StreamSource(new StringReader(xml)); | |
TransformerFactory factory = TransformerFactory.newInstance(); | |
Transformer transformer = factory.newTransformer(xsltSource); | |
//create a StringWriter for the output | |
StringWriter outWriter = new StringWriter(); | |
StreamResult result = new StreamResult(outWriter); | |
transformer.transform(xmlSource, result); | |
StringBuffer sb = outWriter.getBuffer(); | |
String transformedXml = sb.toString(); | |
return transformedXml; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment