Skip to content

Instantly share code, notes, and snippets.

@lawlesst
Created August 16, 2012 13:26
Show Gist options
  • Save lawlesst/3370069 to your computer and use it in GitHub Desktop.
Save lawlesst/3370069 to your computer and use it in GitHub Desktop.
XSLT with saxon in Jython
"""
Use saxon to do XSLT with Jython
See http://codingwithpassion.blogspot.com/2011/03/saxon-xslt-java-example.html
Pass in arguments
- 1 xslt
- 2 xml source
- 3 xml output
"""
from java.io import File;
from javax.xml.transform import Transformer;
from javax.xml.transform import TransformerFactory;
from javax.xml.transform.stream import StreamResult;
from javax.xml.transform.stream import StreamSource;
import os
import sys
xslt = File(sys.argv[1])
tFactory = TransformerFactory.newInstance()
transformer = tFactory.newTransformer(StreamSource(xslt))
out = transformer.transform(
StreamSource(File(
sys.argv[2]
)),
StreamResult(
File(sys.argv[3])
)
)
print out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment