Prerequisite: Install LIBXML2 Libxstl
Official website: http://xmlsoft.org/XSLT/index.html
installation package Download: http://xmlsoft.org/sources/
The following is the EXE installation file download for the Windows platform:
http://xmlsoft.org/sources/win32/python/
This is a reprint of the test code:
The code is as follows:
#-*-Coding:mbcs-*-
#!/usr/bin/python
Import LIBXML2, Libxslt
Class Compoundxml:
def __init__ (self):
Self._result = None
self._xsl = None
Self._xml = None
def do (self, xml_file_name, xsl_file_name):
Self._xml = Libxml2.parsefile (xml_file_name)
if Self._xml = = None:
return 0
Styledoc = Libxml2.parsefile (xsl_file_name)
if Styledoc = = None:
return 0
self._xsl = Libxslt.parsestylesheetdoc (Styledoc)
if self._xsl = = None:
return 0
Self._result = Self._xsl.applystylesheet (Self._xml, None)
def get_xml_doc (self):
Return Self._result
def get_translated (self):
Return self._result.serialize (' UTF-8 ')
def save_translated (self, file_name):
Self._xsl.saveresulttofilename (file_name, Self._result, 0)
def release (self):
'''
This function must is called in the end.
'''
Self._xsl.freestylesheet ()
Self._xml.freedoc ()
Self._result.freedoc ()
self._xsl = None
Self._xml = None
Self._result = None
if __name__ = = ' __main__ ':
Test = Compoundxml ()
Test.do (' Test/testxmlutil.xml ', ' test/testxmlutil.xsl ')
Print test.get_translated ()
test.save_translated (' test/testxmlutil.htm ')
Test.release ()