def find_xslt(self, document): """ Return the filename of an xslt template to use to render this document. The normal Django templating system is used to find a template. The first template found is used. """ candidates = filename_candidates(document, prefix='xsl/', suffix='.xsl') best = find_best_static(candidates) if not best: raise ValueError("Couldn't find XSLT file to use for %s, tried: %s" % (document, candidates)) return best
def html_to_text(self, html, doc): """ Transform HTML (a str) into Akoma-Ntoso friendly text (str). """ candidates = filename_candidates(doc, prefix='xsl/html_to_akn_text_', suffix='.xsl') xslt_filename = find_best_static(candidates) if not xslt_filename: raise ValueError("Couldn't find XSLT file to use for %s, tried: %s" % (doc, candidates)) html = ET.HTML(html) xslt = ET.XSLT(ET.parse(xslt_filename)) result = xslt(html) return str(result)