Julien Anguenot wrote:
> I got a problem with the standard macros use and the XML header.
> I've a view defined like the one below :
> <?xml version="1.0" encoding="UTF-8"?>
> <html
>     xmlns:tal="http://xml.zope.org/namespaces/tal";
>     xmlns:metal="http://xml.zope.org/namespaces/metal";
>   <body metal:use-macro="context/@@standard_macros/page">
>     <!-- content -->
>   </body>
> </html>
> And there, I got the following error when Zope's trying to render it :
> [snip]
>     (`macroName`, `mode`), self.position)
> METALError: macro u'context/@@standard_macros/page' has incompatible
> mode 'html', at line 6, column 3
> If I remove the xml header the error disappears.

It sucks, don't it?

> It's really a huge problem because it means Zope3 'as it' can't render
> valid XML pages with standard macros...
> Any idea how to fix thix problem without having to rewrite the standard
> macros ?
> My use case is the inclusion of XForms within the Page Template and the
> mozilla plugin requires the page to be XML valid and thus to have the
> xml header.
> Any hints welcome.

PageTemplates know two different modes, HTML4 mode and XML mode:

In this HTML4 mode, PageTemplates support unclosed singleton tags (e.g.
<br> instead of <br/>) and don't require namespace declarations. They
just assume that you use 'tal', 'metal' and 'i18n' as prefixes. They
also do a bit of HTML validity checking (e.g. no <li> inside <p>). This
mode is the default.

In XML mode, PageTemplates want strict XML syntax, which means you also
need to declare the TAL, METAL and I18N namespaces. The ZPT machinery
switches to XML mode when it finds the XML declarations (<?xml ... ?>)
on top of the file.

In the discussion of ZPT encodings, I have expressed that I consider
HTML4 mode a legacy that nearly all people can live without
(http://article.gmane.org/gmane.comp.web.zope.zope3/13354). Most use
cases involve XML, e.g. XHTML, XForms (as in this case), RSS, DocBook,
SVG, etc. In fact, the only person who was able to come up with a use
case for HTML4 mode was Dmitry Vasiliev who needs to generate i-mode
markup which is some restricted HTML

So, instead of proposing to radically get rid of HTML4 mode, I propose this:

- XML mode of ZPT becomes the standard mode.

- We keep HTML4 mode around as long people need it, but it's not the
standard mode. The switch whether to use XML or HTML4 mode is done via
ZCML and not some sniffing in the PageTemplate contents.

Yes, I realize that this will suddenly introduce the requirement that
all templates need to carry namespace declarations. I think that's a
good thing. They're not dead chickens. Namespace declarations are
meaningful and useful and they're what XML-capable people and tools are
used to. To sum it up: it's the spec. I've always found it much harder
to explain why Zope wouldn't support the spec in this or that particular
case than just sticking with the spec in such cases.

I would be willing to work this out as a full-blown proposal together
with Julien.

Zope3-dev mailing list
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to