本文整理汇总了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))
示例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
#
示例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
示例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
#
示例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)
示例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
示例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
示例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
示例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)
示例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
示例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
示例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})
示例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
示例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
示例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))