def send_xsl(self,xml,xsl): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() sheetfile = open(xsl,"r") sheet = sheetfile.read() proc = Processor() proc.appendStylesheetString(sheet) self.wfile.write(proc.runString(xml))
def send_xsl(self, xml, xsl): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() sheetfile = open(xsl, "r") sheet = sheetfile.read() proc = Processor() proc.appendStylesheetString(sheet) self.wfile.write(proc.runString(xml))
navigation = '<a href="%s">Index</a>' % pagename pathlen = modname.count('.') if pathlen: navigation = navigation + ' | ' modparts = modname.split('.') for pathidx in range(pathlen): path = '.'.join(modparts[:pathidx + 1]) navigation = navigation + '<a href="%s?module=%s">%s</a>' % ( pagename, path, modparts[pathidx]) if pathidx < pathlen: navigation = navigation + '.' navigation = navigation + '<hr size="1">' else: # generate index xmlstr = xmldoc.xml.document(None, encoding=config.charset) navigation = '' processor = Processor() processor.appendStylesheetFile(xslfile) try: result = processor.runString(xmlstr, topLevelParams={ 'uri-prefix': pagename + "?module=", 'uri-suffix': "", }) except: print wikiutil.escape(xmlstr) raise return navigation + result
if pathlen: navigation = navigation + ' | ' modparts = modname.split('.') for pathidx in range(pathlen): path = '.'.join(modparts[:pathidx+1]) navigation = navigation + '<a href="%s?module=%s">%s</a>' % ( pagename, path, modparts[pathidx]) if pathidx < pathlen: navigation = navigation + '.' navigation = navigation + '<hr size="1">' else: # generate index xmlstr = xmldoc.xml.document(None, encoding=config.charset) navigation = '' processor = Processor() processor.appendStylesheetFile(xslfile) try: result = processor.runString(xmlstr, topLevelParams={ 'uri-prefix': pagename + "?module=", 'uri-suffix': "", } ) except: print wikiutil.escape(xmlstr) raise return navigation + result
return StylesheetReader.fromUri(self, uri, baseUri, ownerDoc, stripElements) if __name__ == "__main__": # the sample stylesheet repository internal_stylesheets = { 'second-author.xsl': """ <person xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"> <xsl:value-of select="books/book/author[2]"/> </person> """ } # the sample document, referring to an "internal" stylesheet xmldoc = """ <?xml-stylesheet href="internal:second-author.xsl" type="text/xml"?> <books> <book title="Python Essential Reference"> <author>David M. Beazley</author> <author>Guido van Rossum</author> </book> </books> """ # create XSLT processor and run it processor = Processor() processor.setStylesheetReader(StylesheetFromDict(internal_stylesheets)) print processor.runString(xmldoc)