[Zope] Re: XSL and DTML was: a funny thing happened today...

Martijn Faassen m.faassen@vet.uu.nl
Tue, 24 Aug 1999 11:33:21 +0200


Paul Prescod wrote:
> 
> I don't think it is fair to compare the complexity of the code used
> here:
> 
> http://www.zope.org:18200/Members/srichter
> 
> with the average XSLT transformation. XSLT is specifically designed to
> handle recursive, heterogenous document types. These document types are
> the norm in real-world Web publishing.

I don't think *recursive* documents are the norm? It may be that XSLT
transformations can be far more complex, but since Stephan is doing
'real-world web publishing' with XML now, I don't think it's fair to say
recursive documents are that incredibly common.

> I think that XSL is what DTML would become if it was evolved toward the
> problem of rendering real-world XML. The fundamental question is how do
> you extend a template structure so that it is recursive and polymorphic.
> Consider this model:
> 
> DOCUMENT -> TITLE, SECTION+
> SECTION -> TITLE, (P|LIST)+, SECTION+
> 
> So in the rule for section you need to process the title. And then the
> paragraphs and lists (in the order that they arrive) and then start the
> process over again for SECTION. TITLE must be handled differently in the
> DOCUMENT and SECTION contexts, and differently depending on how many
> levels of SECTION down it was.

I haven't experimented with recursive structures yet (Stephan has), but
the other things you mentioned I've done with DTML. So I've used your
rules, with the SECTION rule changed to this:

SECTION -> TITLE, (P|LIST)+
 
> This sort of thing is where XSLT excels. It would be useful if someone
> could outline a Zope/DTML solution to this problem.

A Zope XMLDocument represents an XML document as a DOM tree in Zope.
Each node in the tree automatically acquires the DTML methods that are
defined in the folder where the XMLDocument is (or a higher folder).

We have an DTML method called 'renderDocument' which renders the node
title (for instance with a H1 tag), and then for all the section nodes,
calls (with dtml-var) 'renderSection'. In renderSection, the title may
be rendered with H2, for instance. Then it can go through all the
contents, and see if it's encountering a P or a LIST node (for instance
in a renderContents DTML method). This in turn calls the renderP and
renderList DTML methods.

If you want to see an example of this I can send you a .zexp file (or
anyone else who asks :).

Having said all this, I'm sure XSLT may be suited better to this kind of
task, as it's specifically designed to do such. But DTML isn't bad at
all, and, if you know Zope, it's not hard to whip something up (or
change how the rendering works). Once you get to recursion (changing the
rendering depending on how many levels deep the recursion goes) things
may become more difficult to do.

Regards,

Martijn