XMLTransform interface alternatives

Craeg Strong <[email protected]> Fri, 30 Aug 2002 16:45:50 -0700
Newsgroups gmane.comp.web.zope.parsed-xml
Organization Ariel Partners LLC
Message-ID <[email protected]>
See below:

Karl Anderson wrote:

>Craeg K Strong <[email protected]> writes:
>
>>So if your docbook format XML document was contained in
>>a ParsedXML object called foo, you would create a DTMLDocument
>>called, for example, bar with the contents:
>>
>><dtml-var expr="foo.index_html()">
>>
>>And then list "bar" as the sourceID of the XMLTransform.
>>
>>A bit clunky, but it works!   I am hoping the authors of
>>ParsedXML add a __call__() method in their next release
>>that does the same thing as index_html()
>>which would obviate the extra DTMLDocument step.
>>    
>>
>Well, to be Zopish, XSLTransform should try index_html if __call__
>isn't there (actually, before __call__).  And to be flexible,
>XSLTransform should let you specify the method used to get XML from the
>source and sheet object(s), so you can feed it objects for which XML
>isn't their main reason for living (ZDOM, StructuredText, whatever).
>
>Anyway, unless you're caching, you don't want to render the top
>ParsedXML object if you're using it in plumbing, because that's
>expensive.  You want to get the proxied DOM object with getDOMObj()
>and render that.
>
After a good nights' sleep, I am thinking more clearly.  

There is a very good reason I want/need to use __call__()

Here is the reason.  I am assuming that the Zope object does its own 
evaluation, and that the
RESULTS of this evaluation is what I actually want.  

For example, if the Zope object is some kind of ZSQL object 
(hypothetical example, not sure if
such a product exists)   then the text of the object might be some kind 
of SQL query.
I *don't* want the SQL query, rather the *results* of running the SQL 
query (expressed
as XML, of course).   By calling __call__() I am more clearly 
communicating this semantic IMHO.

Same thing with DTML.  Imagine the following document:

<?xml version="1.0"?>
<Document>
  <Author>
    <dtml-var author>
  </Author>
  <Content>
    Hello, world
   </Content>
</Document>

Calling __call__() makes the dtml-var get evaluated correctly *before* 
XMLTransform sees it.

IMHO, Neither __str__ nor index_html() implies this semantic the way 
__call__ does
(obviously, since its Python code, you can code these methods however 
you want)

For example, I could see where __str__ could return a string 
representation of an object "as is" without processing.
I could see index_html() calling __call__() and then wrapping the 
results in <html> to make a w3c compliant HTML 4.0 document.

I am aware that such conventions don't really exist (or aren't 
enforced), but in my opinion the above seems intuitively correct to me.

Anyway, perhaps the thing to do is to leave__call__ as the default, but 
allow folks to specify alternative method names if they want.
That way they can use __str__ or index_html if the situation calls for 
it....

--Craeg