[Grok-dev] guidance for incorporating XSLT as alternative
jwashin at vt.edu
Wed Dec 19 15:34:42 EST 2007
cstrong at arielpartners.com wrote:
> I would love to get a few pointers on how to go about adding XSLT as an
> alternative templating mechanism.
> My plan is to always emit and consume XML via the Amara library.
> Sometimes the XML will be sent to the browser which will use
> Other times the XML will be transformed via XSLT on the server side.
> I am aware I am sacrificing efficiency for the sake of portability and
> I like the idea of adding xslt templates alongside zpt and genshi using
> another file extension (e.g. ".xsl")
> Perhaps the XSLT template mechanism knows it needs XML so it requests a
> suitable adapter?
I would use an IResult adapter. In
zope.publisher.http.HTTPResponse.setResult, Zope's publisher queries for
an IResult multiadapter and will use that instead of the default
publishing mechanism if available. Instead of a unicode string, your
application outputs a view-ish object that is adaptable to IResult, and
you write an IResult adapter to take care of it from there. The adapter
has to set the content-type and content-length headers into the response
and do any appropriate encoding, finally outputting a tuple of string
(output,). Inside the adapter, you may do any transforms you want on
I am working on some alpha code that's not quite ready for prime-time
that uses this hook for doing something similar with lxml. Let me know
if you want to see it.
More information about the Grok-dev