diff -r 0c20fc810d61 -r 5736d25bb393 plcopen/XSLTModelQuery.py --- a/plcopen/XSLTModelQuery.py Tue Feb 20 11:24:40 2018 +0100 +++ b/plcopen/XSLTModelQuery.py Tue Feb 20 14:16:51 2018 +0100 @@ -14,30 +14,33 @@ class XSLTModelQuery(object): """ a class to handle XSLT queries on project and libs """ - def __init__(self, controller, xsltpath, ext = []): + def __init__(self, controller, xsltpath, ext=None): # arbitrary set debug to false, updated later self.debug = False # merge xslt extensions for library access to query specific ones xsltext = [ - ("GetProject", lambda *_ignored: - [controller.GetProject(self.debug)]), - ("GetStdLibs", lambda *_ignored: - [lib for lib in StdBlckLibs.values()]), - ("GetExtensions", lambda *_ignored: - [ctn["types"] for ctn in controller.ConfNodeTypes]) - ] + ext + ("GetProject", lambda *_ignored: + [controller.GetProject(self.debug)]), + ("GetStdLibs", lambda *_ignored: + [lib for lib in StdBlckLibs.values()]), + ("GetExtensions", lambda *_ignored: + [ctn["types"] for ctn in controller.ConfNodeTypes]) + ] - # parse and compile. "beremiz" arbitrary namespace for extensions + if ext is not None: + xsltext.extend(ext) + + # parse and compile. "beremiz" arbitrary namespace for extensions self.xslt = etree.XSLT( etree.parse( os.path.join(ScriptDirectory, xsltpath), etree.XMLParser()), - extensions={ ("beremiz", name):call for name, call in xsltext}) + extensions={("beremiz", name): call for name, call in xsltext}) def _process_xslt(self, root, debug, **kwargs): self.debug = debug - res = self.xslt(root,**{k:etree.XSLT.strparam(v) for k,v in kwargs.iteritems()}) + res = self.xslt(root, **{k: etree.XSLT.strparam(v) for k, v in kwargs.iteritems()}) # print(self.xslt.error_log) return res @@ -60,4 +63,3 @@ return [translate(arg[0]) if len(arg) > 0 else None for translate, arg in zip(translations, args)] -