So, here we go:
import web
import libxml2
import libxslt
urls = (
'/','index'
)
XML="data.xml"
XSL="style.xsl"
class index(object):
def GET(self):
doc = libxml2.parseFile(XML)
styledoc = libxml2.parseFile(XSL)
style = libxslt.parseStylesheetDoc(styledoc)
result = style.applyStylesheet(doc, {})
data = style.saveResultToString(result)
style.freeStylesheet()
doc.freeDoc()
return data
app = web.application(urls, globals())
app.run()
I'm pretty sure that mixing XSLT and web.py templates is a bad (bad)
idea. So web.py serves file built using a XSL transformation, what do
you wanna do now? It's not that I *really* want to now, I'm sure that
more details can help us helping you ;-)
To talk about XSL, that mailing list is very (very) active:
http://www.mulberrytech.com/xsl/xsl-list/
Cheers,
-- Yoan
On Tue, Apr 8, 2008 at 3:18 PM, Joe <[EMAIL PROTECTED]> wrote:
>
> Well if you REALLY want to know... My original code.py extracted and
> listed all the XML results files within a given directory. The next
> step was to extract out certain pieces of information from each file
> and print them next to the first list. It seemed to me I could not do
> much with the template aside from looping through sets and printing
> out variables. My next thought was to create dictionaries within
> code.py and pass them to the template. Then I figured rather than
> passing a number of dicts to the template I could have all my stuff
> stored in an XML document in memory and pass it that way. Then the
> template would use XSLT to make the passed content look pretty.
>
> I'm sure you could tell at this point I'm pretty green with this
> stuff. Any ideas or best practices would help alot! Thx.
>
> - Joe
>
>
> On Apr 7, 4:02 pm, "Yoan Blanc" <[EMAIL PROTECTED]> wrote:
> > What's the point here? Do you really need to use files served by the
> > web server to do XSL Transformations?
> >
> > Best of luck.
> >
> > -- Yoan
> >
>
> > On Mon, Apr 7, 2008 at 9:55 PM, Joe Tseng <[EMAIL PROTECTED]> wrote:
> > > Thanks to the list for the help earlier... Now I'm trying to apply an
> XSLT
> > > document to the generated XML and nothing seems to show up. I suspect
> if it
> > > worked as it's supposed to you'd see two code 200 msgs in STDOUT - one
> for
> > > the XML itself and one for the XSLT document. So far I'm only getting
> one
> > > and I can see the contents of my XSLT doc only if I look directly at it
> with
> > > the browser. Is this something else that is blindingly obvious for
> others?
> >
> > > My code.py is as follows:
> >
> > > urls = (
> > > "/", "index",
> > > "/main.xsl", "xslmain"
> > > )
> > > ...
> > > xmlstr = "<?xml version=\"1.0\"
> > > encoding=\"UTF-8\"?>\n<?xml-stylesheet type=\"text/xsl\"
> > > href=\"./main.xsl\"?>\n"
> > > xmlstr = xmlstr + etree.tostring(runlist, pretty_print=True)
> > > ...class xslmain:
> > > def GET (self):
> > > web.header("Content-Type","text/xml; charset=utf-8")
> > > print open("templates/main.xsl").read()
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---