[ZPT] Processing instructions in HTML with ZPT

Dieter Maurer dieter@handshake.de
Mon, 29 Oct 2001 22:47:54 +0100 (CET)


Brad Clements writes:
 > I'm trying to inject <?IMPORT tags in HTML output for some Page Templates. 
 > 
 > Those templates that use this have a property named import_Namespace, which is a 
 > tokens type.
 > 
 > In my Master macro, I have this:
 > 
 > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
 > <html xmlns:ps xmlns:ts metal:define-macro="master">
 > <tal:xyz tal:omit-tag=""
 >          tal:condition="template/import_Namespace | nothing"
 >          tal:repeat="namespace template/import_Namespace">
 > <?IMPORT  
 >    tal:attributes="namespace python:string.split(namespace,':')[0];
 >                    implementation python:string.split(namespace,':')[1]">
 > </tal:xyz>
 > 
 > There are two problems:
 > 
 > 1. I would like to be able to specify xmlns:ps and xmlns:ts in the HTML header based 
 > on some code that extracts these values from the import_Namespace property, 
 > however I couldn't figure out any way to do this with Page Templates. I thought of using 
 > a PythonScript to create a string "xmlns:ps xmlns:ts" but couldn't figure out any way to 
 > put that string in the <html> tag.
Side note: the "xmlns" attributes look funny, they do not have a value...

I would expect(hope) that a standard "tal:attributes" is able to
provide dynamic values for the namespace attributes.

Wait, I start to understand...

   You want a way to dynamically determine whether you
   want to include attribute A or rather attribute B.

Currently, TAL/METAL does not have means for this.
The "metal/tal" attributes and their values are static
and cannot be computed at runtime. You must build
the complete ZPT dynamically to obtain this effect.

I think to remember that there was an extension proposal
to allow a dynamically computed value to determine which
attributes are to be set. The use case was for easy
"img" tag generation.

 > 2. When tal:xyz repeat is processed, the <?IMPORT tag seems to be ignored, I get this 
 > output:
 > ...
 > <?IMPORT  
 >    tal:attributes="namespace python:string.split(namespace,':')[0];
 >                    implementation python:string.split(namespace,':')[1]">
 > 
 > 
 > <?IMPORT  
Processing instructions do not have attributes.

  Your "tal:attributes" is parsed as part of the
  processing instruction's value and (of course) not
  evaluated...
 > ...

 > What's the work around for this?
Do not want to use processing instructions with attributes...
No HTML/SGML/XML aware applications will recognize them...



Dieter