Skip to content

Instantly share code, notes, and snippets.

@jitanghu
Last active June 7, 2017 01:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jitanghu/9386625 to your computer and use it in GitHub Desktop.
Save jitanghu/9386625 to your computer and use it in GitHub Desktop.
Simple script to transform xml doc with specified xslt
#!/usr/bin/python
import lxml.etree as et
import sys
USAGE = sys.argv[0] + " <template> <doc>"
if len(sys.argv) < 3:
print USAGE
sys.exit(-1)
template_path = sys.argv[1]
doc_path = sys.argv[2]
template_dom = et.parse(template_path)
doc_dom = et.parse(doc_path)
transform = et.XSLT(template_dom)
transfomed_dom = transform(doc_dom)
print(et.tostring(transfomed_dom, pretty_print=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment