def transform(input, output_filename=None, is_file=True, \
parse_dublincore=True, stylesheet='legacy', options={}):
- """Transforms file input_filename in XML to output_filename in XHTML."""
+ """Transforms file input_filename in XML to output_filename in XHTML.
+
+ If output_filename is None, returns an XML,
+ otherwise returns True if file has been written,False if it hasn't.
+ File won't be written if it has no content.
+ """
# Parse XSLT
try:
style_filename = get_stylesheet(stylesheet)
result = document.transform(style, **options)
del document # no longer needed large object :)
- if etree.ETXPath('//p|//{%s}p' % str(XHTMLNS))(result) is not None:
+ if etree.ETXPath('//p|//{%s}p' % str(XHTMLNS))(result):
add_anchors(result.getroot())
add_table_of_contents(result.getroot())
return result
return True
else:
- return "<empty />"
+ if output_filename is not None:
+ return False
+ else:
+ return "<empty />"
except KeyError:
raise ValueError("'%s' is not a valid stylesheet.")
except (XMLSyntaxError, XSLTApplyError), e:
get_fixture('text', 'asnyk_miedzy_nami.html'),
parse_dublincore=False,
)
+
+def test_empty():
+ assert html.transform('<utwor />', is_file=False, parse_dublincore=False).find('empty')