XSLTransform.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Wed, 12 Apr 2023 21:05:00 +0200
branchpython3
changeset 3793 9958cf865da0
parent 3750 f62625418bff
permissions -rw-r--r--
IDE: fixed/remove checks wxPython versions
2627
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
     3
# This file is part of Beremiz.
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
     4
# See COPYING file for copyrights details.
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
     5
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3165
diff changeset
     6
2627
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
     7
from lxml import etree
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
     8
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
     9
class XSLTransform(object):
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    10
    """ a class to handle XSLT queries on project and libs """
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    11
    def __init__(self, xsltpath, xsltext):
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    12
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    13
        # parse and compile. "beremiz" arbitrary namespace for extensions
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    14
        self.xslt = etree.XSLT(
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    15
            etree.parse(
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    16
                xsltpath,
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    17
                etree.XMLParser()),
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    18
            extensions={("beremiz", name): call for name, call in xsltext})
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    19
3165
2db69e2c5673 SVGHMI: Optimized overlapping geometry (widget ot page belonging) computation. Added human readable messages for progress. Includes updated XSLT.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2707
diff changeset
    20
    def transform(self, root, profile_run=False, **kwargs):
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3165
diff changeset
    21
        res = self.xslt(root, profile_run=profile_run, **{k: etree.XSLT.strparam(v) for k, v in kwargs.items()})
2627
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    22
        # print(self.xslt.error_log)
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    23
        return res
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    24
2707
c26195654ae9 XSLTransform.py: added get_error_log()
Edouard Tisserant
parents: 2627
diff changeset
    25
    def get_error_log(self):
c26195654ae9 XSLTransform.py: added get_error_log()
Edouard Tisserant
parents: 2627
diff changeset
    26
        return self.xslt.error_log
2627
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
    27
2707
c26195654ae9 XSLTransform.py: added get_error_log()
Edouard Tisserant
parents: 2627
diff changeset
    28