Re: populating template from a dom object

Tim Arnold <[email protected]> Tue, 12 Jan 2010 15:30:32 -0500
Newsgroups gmane.comp.python.cheetah
Message-ID <[email protected]>
> -----Original Message-----
> From: R. Tyler Ballance [mailto:[email protected]]
> Sent: Tuesday, January 12, 2010 1:59 PM
> To: Tim Arnold
> Cc: [email protected]
> Subject: Re: [Cheetahtemplate-discuss] populating template from a dom object
> 
> 
> On Tue, 12 Jan 2010, Tim Arnold wrote:
> 
> > Hi,
> > I'm new to Cheetah. I was wondering if it's possible to populate a set of
> Cheetah templates from a document object model.
> > For example, I have a DocBook XML file that I can read and parse into a
> tree using lxml; is there a way I can apply a set of Cheetah templates to
> render that object into HTML?
> >
> > I know about the DocBook XSLT stylesheets, I was just wondering if the
> Cheetah template method is feasible.
> 
> There's no built-in "magic" for handling this kind of scenario; that said if
> you're using lxml and you've already got a handful of Element objects you
> can likely write some template logic (that phrase sounds wrong ;)) to do
> your translation.
> 
> 
> 
> Cheers,
> -R. Tyler Ballance
> --------------------------------------
>  Jabber: [email protected]
>  GitHub: http://github.com/rtyler
> Twitter: http://twitter.com/agentdero
>    Blog: http://unethicalblogger.com

Yes, thanks. I wasn't expecting too much magic, but it would be nice!
To take a specific example, say I've got this as an lxml tree:
<chapter>
  <info>
    <title>My first chapter</title>
  </info>
  <para role="intro">my first paragraph</para>
</chapter>

I wondered if I had Cheetah templates for chapter, info, title, and para, whether I could use the lxml tree as the namespace to feed in?  I'm guessing the templates would belong to a class somehow so they could be referenced as one thing....

If not, would you mind a snippet of the template logic you mentioned?

thanks very much,
--Tim

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev