Skip to content

Instantly share code, notes, and snippets.

@jdkane3
Created January 28, 2016 13:50
Show Gist options
  • Save jdkane3/46683446e104ee0feac9 to your computer and use it in GitHub Desktop.
Save jdkane3/46683446e104ee0feac9 to your computer and use it in GitHub Desktop.
Simple groovy XSLT code
import javax.xml.transform.TransformerFactory
import javax.xml.transform.stream.StreamResult
import javax.xml.transform.stream.StreamSource
// Load xslt
def xslt= new File("MyTrasform.xsl").getText()
// Create transformer
def transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(new StringReader(xslt)))
// Load xml
def xml= new File("MyXml.xml").getText()
// Set output file
def html = new FileOutputStream("output.html")
// Perform transformation
transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(html))
@jrobens
Copy link

jrobens commented Oct 17, 2023

Do you need this line?

def html = new FileOutputStream("output.html")

This works better

transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult("output.html"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment