當前位置: 首頁>>代碼示例>>Python>>正文


Python etree.XSLT屬性代碼示例

本文整理匯總了Python中lxml.etree.XSLT屬性的典型用法代碼示例。如果您正苦於以下問題:Python etree.XSLT屬性的具體用法?Python etree.XSLT怎麽用?Python etree.XSLT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在lxml.etree的用法示例。


在下文中一共展示了etree.XSLT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: execute

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def execute(path, cmd, uuid):
    filename  = "%s/%s" % (OUTPUT_PATH, uuid)
    nmap_cmd = '%s %s -oA %s' % (path, cmd, filename)
    ops = NmapOptions()
    ops.parse_string(nmap_cmd)
    proc = subprocess.Popen(ops.render(), shell=False)
    proc.wait()

    print('\n[%s] Finished execution of command "%s"' % (datetime.datetime.now(), cmd))

    dom = ET.parse("%s.xml" % filename)
    xsl_filename = dom.getroot().getprevious().getprevious().parseXSL() # need to add error checking
    transform = ET.XSLT(xsl_filename)
    html = transform(dom)
    html_file = open('%s.html' % filename, 'w')
    html.write(html_file)

    print('[%s] HTML report generated (%s.html)' % (datetime.datetime.now(), filename)) 
開發者ID:cldrn,項目名稱:rainmap-lite,代碼行數:20,代碼來源:nmaper-cronjob.py

示例2: _detect

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def _detect(env):
    """
    Detect all the command line tools that we might need for creating
    the requested output formats.
    """
    global prefer_xsltproc
    
    if env.get('DOCBOOK_PREFER_XSLTPROC',''):
        prefer_xsltproc = True
        
    if ((not has_libxml2 and not has_lxml) or (prefer_xsltproc)):
        # Try to find the XSLT processors
        __detect_cl_tool(env, 'DOCBOOK_XSLTPROC', xsltproc_com, xsltproc_com_priority)
        __detect_cl_tool(env, 'DOCBOOK_XMLLINT', xmllint_com)

    __detect_cl_tool(env, 'DOCBOOK_FOP', fop_com, ['fop','xep','jw'])

#
# Scanners
# 
開發者ID:Autodesk,項目名稱:arnold-usd,代碼行數:22,代碼來源:__init__.py

示例3: __build_libxml2

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def __build_libxml2(target, source, env):
    """
    General XSLT builder (HTML/FO), using the libxml2 module.
    """
    xsl_style = env.subst('$DOCBOOK_XSL')
    styledoc = libxml2.parseFile(xsl_style)
    style = libxslt.parseStylesheetDoc(styledoc)
    doc = libxml2.readFile(str(source[0]),None,libxml2.XML_PARSE_NOENT)
    # Support for additional parameters
    parampass = {}
    if parampass:
        result = style.applyStylesheet(doc, parampass)
    else:
        result = style.applyStylesheet(doc, None)
    style.saveResultToFilename(str(target[0]), result, 0)
    style.freeStylesheet()
    doc.freeDoc()
    result.freeDoc()

    return None 
開發者ID:Autodesk,項目名稱:arnold-usd,代碼行數:22,代碼來源:__init__.py

示例4: _detect

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def _detect(env):
    """
    Detect all the command line tools that we might need for creating
    the requested output formats.
    """
    global prefer_xsltproc
    
    if env.get('DOCBOOK_PREFER_XSLTPROC',''):
        prefer_xsltproc = True
        
    if ((not has_libxml2 and not has_lxml) or (prefer_xsltproc)):
        # Try to find the XSLT processors
        __detect_cl_tool(env, 'DOCBOOK_XSLTPROC', xsltproc_com)
        __detect_cl_tool(env, 'DOCBOOK_XMLLINT', xmllint_com)

    __detect_cl_tool(env, 'DOCBOOK_FOP', fop_com)

#
# Scanners
# 
開發者ID:bq,項目名稱:web2board,代碼行數:22,代碼來源:__init__.py

示例5: schematron

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def schematron(cls, schema):
        transforms = [
            "xml/schematron/iso_dsdl_include.xsl",
            "xml/schematron/iso_abstract_expand.xsl",
            "xml/schematron/iso_svrl_for_xslt1.xsl",
            ]
        if isinstance(schema, file):
            compiled = etree.parse(schema)
        else:
            compiled = schema
        for filename in transforms:
            with resource_stream(
                    __name__, filename) as stream:
                xform_xml = etree.parse(stream)
                xform = etree.XSLT(xform_xml)
                compiled = xform(compiled)
        return etree.XSLT(compiled) 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:19,代碼來源:validation.py

示例6: _transform_to_html

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def _transform_to_html(self, content, xslt_package=None, xslt_path=None):

        xslt_package = xslt_package or __name__
        xslt_path = xslt_path or \
            '../templates/ckanext/spatial/gemini2-html-stylesheet.xsl'

        # optimise -- read transform only once and compile rather
        # than at each request
        with resource_stream(xslt_package, xslt_path) as style:
            style_xml = etree.parse(style)
            transformer = etree.XSLT(style_xml)

        xml = etree.parse(StringIO(content.encode('utf-8')))
        html = transformer(xml)

        response.headers['Content-Type'] = 'text/html; charset=utf-8'
        response.headers['Content-Length'] = len(content)

        result = etree.tostring(html, pretty_print=True)

        return result 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:23,代碼來源:api.py

示例7: _get_xslt

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def _get_xslt(self, original=False):

        if original:
            config_option = \
                'ckanext.spatial.harvest.xslt_html_content_original'
        else:
            config_option = 'ckanext.spatial.harvest.xslt_html_content'

        xslt_package = None
        xslt_path = None
        xslt = config.get(config_option, None)
        if xslt:
            if ':' in xslt:
                xslt = xslt.split(':')
                xslt_package = xslt[0]
                xslt_path = xslt[1]
            else:
                log.error(
                    'XSLT should be defined in the form <package>:<path>' +
                    ', eg ckanext.myext:templates/my.xslt')

        return xslt_package, xslt_path 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:24,代碼來源:api.py

示例8: transform_with_xsl

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def transform_with_xsl(xml_path, xsl_path, recover=False):
    try:
        xml_dom = etree.parse(xml_path)
    except etree.XMLSyntaxError as e:
        if recover:
            logger.error(e)
            parser = etree.XMLParser(recover=True)
            xml_dom = etree.parse(xml_path, parser=parser)
        else:
            raise
    xsl_transform = etree.XSLT(etree.parse(xsl_path))
    try:
        transformed_dom = xsl_transform(xml_dom)
    except Exception as err:
        logger.error(err)
        for xsl_error in xsl_transform.error_log:
            logger.error(xsl_error)
        if not recover:
            raise

    return transformed_dom 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:23,代碼來源:files.py

示例9: ingest

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def ingest(self, file_path):
        """Ingestor implementation."""
        file_size = self.result.size or os.path.getsize(file_path)
        if file_size > self.MAX_SIZE:
            raise ProcessingException("XML file is too large.")

        try:
            doc = etree.parse(file_path)
        except (ParserError, ParseError):
            raise ProcessingException("XML could not be parsed.")

        text = self.extract_html_text(doc.getroot())
        transform = etree.XSLT(self.XSLT)
        html_doc = transform(doc)
        html_body = html.tostring(html_doc, encoding=str, pretty_print=True)
        self.result.flag(self.result.FLAG_HTML)
        self.result.emit_html_body(html_body, text) 
開發者ID:occrp-attic,項目名稱:ingestors,代碼行數:19,代碼來源:xml.py

示例10: apply_xslt_stylesheets

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def apply_xslt_stylesheets(self, description):
        """
        Apply XSLT style sheet rules to an xml file

        The result of the XSLT processing is stored in a named
        temporary file and returned to the caller

        :param string description: path to an XML description file
        """
        xslt_transform = etree.XSLT(
            etree.parse(Defaults.get_xsl_stylesheet_file())
        )
        self.description_xslt_processed = NamedTemporaryFile(prefix='xslt-')
        with open(self.description_xslt_processed.name, "wb") as xsltout:
            xsltout.write(
                etree.tostring(xslt_transform(etree.parse(description)))
            )
        return self.description_xslt_processed.name 
開發者ID:OSInside,項目名稱:kiwi,代碼行數:20,代碼來源:base.py

示例11: GetEntriesList

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def GetEntriesList(self, limits=None):
        entries = {}

        factory = EntryListFactory(entries)

        entries_list_xslt_tree = etree.XSLT(
            entries_list_xslt, extensions={
                ("entries_list_ns", "AddEntry"): factory.AddEntry,
                ("entries_list_ns", "HexDecValue"): HexDecValue,
                ("entries_list_ns", "EntryName"): EntryName})
        entries_list_xslt_tree(self, **dict(zip(
            ["min_index", "max_index"],
            map(lambda x: etree.XSLT.strparam(str(x)),
                limits if limits is not None else [0x0000, 0xFFFF])
            )))

        return entries 
開發者ID:thiagoralves,項目名稱:OpenPLC_Editor,代碼行數:19,代碼來源:etherlab.py

示例12: __init__

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
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])
        ]

        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}) 
開發者ID:thiagoralves,項目名稱:OpenPLC_Editor,代碼行數:25,代碼來源:XSLTModelQuery.py

示例13: __build_lxml

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def __build_lxml(target, source, env):
    """
    General XSLT builder (HTML/FO), using the lxml module.
    """
    from lxml import etree
    
    xslt_ac = etree.XSLTAccessControl(read_file=True, 
                                      write_file=True, 
                                      create_dir=True, 
                                      read_network=False, 
                                      write_network=False)
    xsl_style = env.subst('$DOCBOOK_XSL')
    xsl_tree = etree.parse(xsl_style)
    transform = etree.XSLT(xsl_tree, access_control=xslt_ac)
    doc = etree.parse(str(source[0]))
    # Support for additional parameters
    parampass = {}
    if parampass:
        result = transform(doc, **parampass)
    else:
        result = transform(doc)
        
    try:
        of = open(str(target[0]), "wb")
        of.write(of.write(etree.tostring(result, pretty_print=True)))
        of.close()
    except:
        pass

    return None 
開發者ID:Autodesk,項目名稱:arnold-usd,代碼行數:32,代碼來源:__init__.py

示例14: __build_lxml

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def __build_lxml(target, source, env):
    """
    General XSLT builder (HTML/FO), using the lxml module.
    """
    from lxml import etree
    
    xslt_ac = etree.XSLTAccessControl(read_file=True, 
                                      write_file=True, 
                                      create_dir=True, 
                                      read_network=False, 
                                      write_network=False)
    xsl_style = env.subst('$DOCBOOK_XSL')
    xsl_tree = etree.parse(xsl_style)
    transform = etree.XSLT(xsl_tree, access_control=xslt_ac)
    doc = etree.parse(str(source[0]))
    # Support for additional parameters
    parampass = {}
    if parampass:
        result = transform(doc, **parampass)
    else:
        result = transform(doc)
        
    try:
        of = open(str(target[0]), "w")
        of.write(of.write(etree.tostring(result, pretty_print=True)))
        of.close()
    except:
        pass

    return None 
開發者ID:bq,項目名稱:web2board,代碼行數:32,代碼來源:__init__.py

示例15: apply_stylesheet

# 需要導入模塊: from lxml import etree [as 別名]
# 或者: from lxml.etree import XSLT [as 別名]
def apply_stylesheet(self, stylesheet: 'XML') -> 'XML':
        transform = etree.XSLT(xslt_input=stylesheet.lxml)
        result = transform(self.lxml)
        return XML(xml=str(result)) 
開發者ID:erinxocon,項目名稱:requests-xml,代碼行數:6,代碼來源:requests_xml.py


注:本文中的lxml.etree.XSLT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。