Edouard@2627: #!/usr/bin/env python
Edouard@2627: # -*- coding: utf-8 -*-
Edouard@2627: # This file is part of Beremiz.
Edouard@2627: # See COPYING file for copyrights details.
Edouard@2627: 
kinsamanka@3750: 
Edouard@2627: from lxml import etree
Edouard@2627: 
Edouard@2627: class XSLTransform(object):
Edouard@2627:     """ a class to handle XSLT queries on project and libs """
Edouard@2627:     def __init__(self, xsltpath, xsltext):
Edouard@2627: 
Edouard@2627:         # parse and compile. "beremiz" arbitrary namespace for extensions
Edouard@2627:         self.xslt = etree.XSLT(
Edouard@2627:             etree.parse(
Edouard@2627:                 xsltpath,
Edouard@2627:                 etree.XMLParser()),
Edouard@2627:             extensions={("beremiz", name): call for name, call in xsltext})
Edouard@2627: 
edouard@3165:     def transform(self, root, profile_run=False, **kwargs):
kinsamanka@3750:         res = self.xslt(root, profile_run=profile_run, **{k: etree.XSLT.strparam(v) for k, v in kwargs.items()})
Edouard@2627:         # print(self.xslt.error_log)
Edouard@2627:         return res
Edouard@2627: 
Edouard@2707:     def get_error_log(self):
Edouard@2707:         return self.xslt.error_log
Edouard@2627: 
Edouard@2707: