Last active
October 6, 2022 15:48
-
-
Save ryan-blunden/914867 to your computer and use it in GitHub Desktop.
XSLT Preview Tool
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
#!/usr/bin/env python | |
'''Basic XSLT previewer''' | |
__author__ = 'Ryan Blunden' | |
__copyright__ = 'Copyright 2010, Ryan Blunden' | |
__license__ = 'GPL' | |
__email__ = '[email protected]' | |
__status__ = 'Development' | |
from lxml import etree | |
import subprocess, sys | |
def xslt_preview(xml_file, xslt_file, output_file_path): | |
''' | |
Perform an XSLT using the supplied XML and XSL file paths, | |
saving it to the supplied output file path. | |
''' | |
xml_root = etree.XML(open(xml_file, 'r').read()) | |
xslt_root = etree.XML(open(xslt_file, 'r').read()) | |
transform = etree.XSLT(xslt_root) | |
output_file = open(output_file_path, 'w') | |
result = etree.tostring(transform(xml_root)) | |
output_file.write(result) | |
output_file.close() | |
if __name__ == '__main__': | |
if len(sys.argv) < 4: | |
print 'Usage: %s xml_file xslt_file output_file' % sys.argv[0] | |
print 'Example: python xslt.py test-store.xml test-store.xsl test.html' | |
sys.exit(1) | |
xml_file = sys.argv[1] | |
xslt_file = sys.argv[2] | |
output_file_path = sys.argv[3] | |
xslt_preview(xml_file, xslt_file, output_file_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment