def __xslt_error__(self, errorlist): """Format an errorlist. Override this if you want your errors looking different. """ errors = [E.li(str(error)) for error in errorlist] errordoc = E.html( E.h1("an error occurred"), E.ol(*errors) ) return errordoc
def parse(self, ctx_value, *args): try: ## Not sure if it's better to return EMPTYDOC from here if nothing is passed in if ctx_value: xmldoc = etree.fromstring(unicode(ctx_value)) doc= [xmldoc] return doc else: return EMPTYDOC except etree.XMLSyntaxError, e: self.logger.debug(ctx_value) for i in e.error_log: self.logger.error("couldn't transform %s via %s %s" % (i, ctx_value, args)) self.logger.debug(traceback.format_exc()) if settings.DEBUG: errors = [E.li(str(error)) for error in e.error_log] return [E.ol(*errors)] return ""
def parsehtml(self, ctx_value, *args): try: # First make it HTML htmldoc = etree.HTML(ctx_value) xmldoc = etree.XML(re.sub( "<html>", """<html xmlns="%s">""" % XHTML_NAMESPACE, etree.tostring(htmldoc) )) self.logger.debug(etree.tostring(xmldoc)) doc= [xmldoc] return doc except etree.XMLSyntaxError, e: self.logger.debug(ctx_value) for i in e.error_log: self.logger.error("couldn't transform %s" % i) self.logger.debug(traceback.format_exc()) if settings.DEBUG: errors = [E.li(str(error)) for error in e.error_log] return [E.ol(*errors)] return ""