The best way is to use lxml, but it only supports XSLT 1
import os import lxml.etree as ET inputpath = "D:\\temp\\" xsltfile = "D:\\temp\\test.xsl" outpath = "D:\\output" for dirpath, dirnames, filenames in os.walk(inputpath): for filename in filenames: if filename.endswith(('.xml', '.txt')): dom = ET.parse(inputpath + filename) xslt = ET.parse(xsltfile) transform = ET.XSLT(xslt) newdom = transform(dom) infile = unicode((ET.tostring(newdom, pretty_print=True))) outfile = open(outpath + "\\" + filename, 'a') outfile.write(infile)
to use XSLT 2 you can check the parameters Use saxon with python
Maliqf Oct 17 '17 at 10:27 2017-10-17 10:27
source share