equal
deleted
inserted
replaced
6 from __future__ import absolute_import |
6 from __future__ import absolute_import |
7 import os |
7 import os |
8 from lxml import etree |
8 from lxml import etree |
9 import util.paths as paths |
9 import util.paths as paths |
10 from plcopen.structures import StdBlckLibs |
10 from plcopen.structures import StdBlckLibs |
|
11 from XSLTransform import XSLTransform |
11 |
12 |
12 ScriptDirectory = paths.AbsDir(__file__) |
13 ScriptDirectory = paths.AbsDir(__file__) |
13 |
14 |
14 |
15 class XSLTModelQuery(XSLTransform): |
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=None): |
17 def __init__(self, controller, xsltpath, ext=None): |
|
18 |
18 # arbitrary set debug to false, updated later |
19 # arbitrary set debug to false, updated later |
19 self.debug = False |
20 self.debug = False |
20 |
21 |
21 # merge xslt extensions for library access to query specific ones |
22 # merge xslt extensions for library access to query specific ones |
22 xsltext = [ |
23 xsltext = [ |
29 ] |
30 ] |
30 |
31 |
31 if ext is not None: |
32 if ext is not None: |
32 xsltext.extend(ext) |
33 xsltext.extend(ext) |
33 |
34 |
34 # parse and compile. "beremiz" arbitrary namespace for extensions |
35 XSLTransform.__init__(self, |
35 self.xslt = etree.XSLT( |
36 os.path.join(ScriptDirectory, xsltpath), |
36 etree.parse( |
37 xsltext) |
37 os.path.join(ScriptDirectory, xsltpath), |
|
38 etree.XMLParser()), |
|
39 extensions={("beremiz", name): call for name, call in xsltext}) |
|
40 |
|
41 def _process_xslt(self, root, debug, **kwargs): |
38 def _process_xslt(self, root, debug, **kwargs): |
42 self.debug = debug |
39 self.debug = debug |
43 res = self.xslt(root, **{k: etree.XSLT.strparam(v) for k, v in kwargs.iteritems()}) |
40 return self.transform(root, **kwargs) |
44 # print(self.xslt.error_log) |
|
45 return res |
|
46 |
|
47 |
41 |
48 # ------------------------------------------------------------------------------- |
42 # ------------------------------------------------------------------------------- |
49 # Helpers functions for translating list of arguments |
43 # Helpers functions for translating list of arguments |
50 # from xslt to valid arguments |
44 # from xslt to valid arguments |
51 # ------------------------------------------------------------------------------- |
45 # ------------------------------------------------------------------------------- |