XSLTransform.py
author Edouard Tisserant
Wed, 12 Oct 2022 11:56:04 +0200
changeset 3645 82882a9f91ce
parent 3165 2db69e2c5673
child 3750 f62625418bff
permissions -rw-r--r--
SVGHMI: cosmetic fixes
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
3ba6a2d26507 Moved XSLT model query python code so that XSLT part can be reused for other transformations
Edouard Tisserant
parents:
diff changeset
     6
from __future__ import absolute_import
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):
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
    21
        res = self.xslt(root, profile_run=profile_run, **{k: etree.XSLT.strparam(v) for k, v in kwargs.iteritems()})
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