javascript - Using Tornado to serve xml formatted with xsl -


i trying have tornado serve xml file , transform using xsl.

i'm using:

xmlhttp.open("get",url,true); , xmlhttp.send(); in javascript/html

self.render("cd_catalog.xml") in python

document.getelementbyid("mydiv").innerhtml=xmlhttp.responsetext; in javascript/html.

the results non-formatted xml file.

why doesn't xsl transform xml? missing?

python:

import os import tornado.httpserver import tornado.ioloop import tornado.web  class mainhandler(tornado.web.requesthandler):     def get(self):             self.render("index.html") class test(tornado.web.requesthandler):     def get(self):             self.render("cd_catalog.xml")  def main():     application = tornado.web.application([     (r"/", mainhandler),     (r"/test", test),     ])     http_server = tornado.httpserver.httpserver(application)     port = int(os.environ.get("port", 5003))     http_server.listen(port)     tornado.ioloop.ioloop.instance().start()  if __name__ == "__main__":  main() 

js/html:

    <!doctype html>     <html>     <head>     <script>     function loadxmldoc(url)     {     var xmlhttp;     if (window.xmlhttprequest)       {// code ie7+, firefox, chrome, opera, safari       xmlhttp=new xmlhttprequest();       }     else       {// code ie6, ie5       xmlhttp=new activexobject("microsoft.xmlhttp");       }     xmlhttp.onreadystatechange=function()       {       if (xmlhttp.readystate==4 && xmlhttp.status==200)         {         document.getelementbyid("mydiv").innerhtml=xmlhttp.responsetext;         }       }     xmlhttp.open("get",url,true);     xmlhttp.send();     }     </script>     </head>     <body>      <div id="mydiv"><h2>get list of presidents</h2></div>     <button type="button" onclick="loadxmldoc('/test')">ok</button>      </body>     </html> 

xml:

    <?xml version="1.0" encoding="utf-8"?>     <?xml-stylesheet type="text/xsl" href="cd_catalog.xsl"?>     <catalog>       <cd>         <title>empire burlesque</title>         <artist>bob dylan</artist>         <country>usa</country>         <company>columbia</company>         <price>10.90</price>         <year>1985</year>       </cd>     .     .     </catalog> 

xsl:

    <?xml version="1.0" encoding="utf-8"?>      <xsl:stylesheet version="1.0"     xmlns:xsl="http://www.w3.org/1999/xsl/transform">      <xsl:template match="/">       <html>       <body>       <h2>my cd collection</h2>       <table border="1">         <tr bgcolor="#9acd32">           <th>title</th>           <th>artist</th>         </tr>         <xsl:for-each select="catalog/cd">         <tr>           <td><xsl:value-of select="title"/></td>           <td><xsl:value-of select="artist"/></td>         </tr>         </xsl:for-each>       </table>       </body>       </html>     </xsl:template>      </xsl:stylesheet> 

tornado didn't apply xsl because didn't ask to. instead, using requesthandler.render(), asked tornado render file tornado template , send result browser. instead, should explicitly run file through xsl processor of choice, , use requesthandler.write() send result browser.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -