Created
March 1, 2019 09:45
-
-
Save viewpointsa/6fe31e4ef3235ca4b43b09a59bcfe04f to your computer and use it in GitHub Desktop.
python XSLT processing XML
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 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