Last active
May 13, 2016 13:35
-
-
Save bowmanb/21845a3667c8b1078616fe84cae83bec to your computer and use it in GitHub Desktop.
Java XSL transform w/ parameters only
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
<?xml version="1.0" encoding="UTF-8"?><test>hello world</test> | |
Process finished with exit code 0 |
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
import javax.xml.transform.Transformer; | |
import javax.xml.transform.TransformerFactory; | |
import javax.xml.transform.dom.DOMSource; | |
import javax.xml.transform.stream.StreamResult; | |
import javax.xml.transform.stream.StreamSource; | |
import java.io.File; | |
public class Params { | |
public static void main(String[] args) { | |
try { | |
// I/O | |
DOMSource input = new DOMSource(); | |
StreamSource xsl = new StreamSource(new File("params.xsl")); | |
StreamResult result = new StreamResult(System.out); | |
// Transformation | |
TransformerFactory factory = TransformerFactory.newInstance(); | |
Transformer transformer = factory.newTransformer(xsl); | |
transformer.setParameter("test", "hello world"); | |
transformer.transform(input, result); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
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
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:param name="test"/> | |
<xsl:template match="/"> | |
<test> | |
<xsl:value-of select="$test"/> | |
</test> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment