12 ScriptDirectory = paths.AbsDir(__file__) |
12 ScriptDirectory = paths.AbsDir(__file__) |
13 |
13 |
14 |
14 |
15 class XSLTModelQuery(object): |
15 class XSLTModelQuery(object): |
16 """ a class to handle XSLT queries on project and libs """ |
16 """ a class to handle XSLT queries on project and libs """ |
17 def __init__(self, controller, xsltpath, ext = []): |
17 def __init__(self, controller, xsltpath, ext=None): |
18 # arbitrary set debug to false, updated later |
18 # arbitrary set debug to false, updated later |
19 self.debug = False |
19 self.debug = False |
20 |
20 |
21 # merge xslt extensions for library access to query specific ones |
21 # merge xslt extensions for library access to query specific ones |
22 xsltext = [ |
22 xsltext = [ |
23 ("GetProject", lambda *_ignored: |
23 ("GetProject", lambda *_ignored: |
24 [controller.GetProject(self.debug)]), |
24 [controller.GetProject(self.debug)]), |
25 ("GetStdLibs", lambda *_ignored: |
25 ("GetStdLibs", lambda *_ignored: |
26 [lib for lib in StdBlckLibs.values()]), |
26 [lib for lib in StdBlckLibs.values()]), |
27 ("GetExtensions", lambda *_ignored: |
27 ("GetExtensions", lambda *_ignored: |
28 [ctn["types"] for ctn in controller.ConfNodeTypes]) |
28 [ctn["types"] for ctn in controller.ConfNodeTypes]) |
29 ] + ext |
29 ] |
30 |
30 |
31 # parse and compile. "beremiz" arbitrary namespace for extensions |
31 if ext is not None: |
|
32 xsltext.extend(ext) |
|
33 |
|
34 # parse and compile. "beremiz" arbitrary namespace for extensions |
32 self.xslt = etree.XSLT( |
35 self.xslt = etree.XSLT( |
33 etree.parse( |
36 etree.parse( |
34 os.path.join(ScriptDirectory, xsltpath), |
37 os.path.join(ScriptDirectory, xsltpath), |
35 etree.XMLParser()), |
38 etree.XMLParser()), |
36 extensions={ ("beremiz", name):call for name, call in xsltext}) |
39 extensions={("beremiz", name): call for name, call in xsltext}) |
37 |
40 |
38 def _process_xslt(self, root, debug, **kwargs): |
41 def _process_xslt(self, root, debug, **kwargs): |
39 self.debug = debug |
42 self.debug = debug |
40 res = self.xslt(root,**{k:etree.XSLT.strparam(v) for k,v in kwargs.iteritems()}) |
43 res = self.xslt(root, **{k: etree.XSLT.strparam(v) for k, v in kwargs.iteritems()}) |
41 # print(self.xslt.error_log) |
44 # print(self.xslt.error_log) |
42 return res |
45 return res |
43 |
46 |
44 |
47 |
45 # ------------------------------------------------------------------------------- |
48 # ------------------------------------------------------------------------------- |