Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- '''Basic XSLT previewer'''
- __author__ = 'Ryan Blunden'
- __copyright__ = 'Copyright 2010, Ryan Blunden'
- __license__ = 'GPL'
- __email__ = 'ryan.blunden@gmail.com'
- __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)
Add Comment
Please, Sign In to add comment