Modularize code;
Add packaging instructions; Add modules to handle Gemini file type (no Gemini server yet); Improve handling of configuration.
This commit is contained in:
parent
84e54085b5
commit
766e51af4c
46 changed files with 2359 additions and 663 deletions
22
xml/xslt.py
Normal file
22
xml/xslt.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
class XmlXslt:
|
||||
|
||||
"""This is a patch function to append XSLT reference to XML."""
|
||||
"""Why is there no built-in function of ElementTree or LXML?"""
|
||||
def append_stylesheet(xml_data, type):
|
||||
# Register namespace in order to avoide ns0:
|
||||
if type == 'atom': ET.register_namespace('', 'http://www.w3.org/2005/Atom')
|
||||
# Load XML from string
|
||||
tree = ET.fromstring(xml_data)
|
||||
# The following direction removes the XML declaration
|
||||
xml_data_without_a_declaration = ET.tostring(tree, encoding='unicode')
|
||||
# Add XML declaration and stylesheet
|
||||
xml_data_declaration = (
|
||||
'<?xml version="1.0" encoding="utf-8"?>'
|
||||
'<?xml-stylesheet type="text/xsl" href="xsl/{}.xsl"?>'.format(type) +
|
||||
xml_data_without_a_declaration)
|
||||
return xml_data_declaration
|
Loading…
Add table
Add a link
Reference in a new issue