Skip to content

Instantly share code, notes, and snippets.

@viewpointsa
Created March 1, 2019 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viewpointsa/6fe31e4ef3235ca4b43b09a59bcfe04f to your computer and use it in GitHub Desktop.
Save viewpointsa/6fe31e4ef3235ca4b43b09a59bcfe04f to your computer and use it in GitHub Desktop.
python XSLT processing XML
import lxml.etree as ET
import argparse
parser = argparse.ArgumentParser(description='XSLT Transform XML file.')
parser.add_argument('xml', help='input xml file')
parser.add_argument('xsl', help='input xslt file')
parser.add_argument('-o', '--output', help='Output file')
args = parser.parse_args()
dom = ET.parse(args.xml)
xslt = ET.parse(args.xsl)
transform = ET.XSLT(xslt)
newdom = transform(dom)
content = ET.tostring(newdom, pretty_print=True)
if args.output :
with open(args.output,'wb') as f:
newdom.write_output(f)
else:
print newdom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment