The Python implementation converts XML or XSL into HTML format _python

Source: Internet
Author: User
Tags xsl

A small program that used python to process XML transformations a few days ago to convert xml,xsl into HTML.

With the LIBXML2, so you have to install the LIBXML2 module before you can use it.

#-*-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 SEL f._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) d 
    EF 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__ = ' __ma 
  In__ ': test = Compoundxml () test.do (' Test/testxmlutil.xml ', ' test/testxmlutil.xsl ') print test.get_translated ()
 test.save_translated (' test/testxmlutil.htm ') test.release ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.