[Petal] Petal 0.84 released

Kurt Stephens kstep at pepsdesign.com
Mon Feb 10 06:40:34 GMT 2003


----- Original Message -----
From: "Daniel Fisher" <dan at webslingerz.com>
To: <petal at lists.webarch.co.uk>
Sent: Sunday, February 09, 2003 8:21 PM
Subject: Re: [Petal] Petal 0.84 released


> I was wondering if folks have tried using Petal 0.84 to generate Petal
> templates from other Petal templates.

I am currently working on a program to generate Petal templates from
a MySQL database schema, which I will post shortly.  In doing so, I
have found several tricks, including the namespace trick from Jean.

> I'm using a technique (which might have been a syntactical violation)
> under 0.83 which doesn't work under 0.84.
>
> <input type='hidden'
> TAL:attributes="name configuration/get_identity_field_name;"
> petal:attributes="value entry/${configuration/get_identity_field_name};"
> />

What URI have you assigned to the TAL and petal: namespaces?
I am assuming that you have assigned the TAL namespace to Petal's
namespace URI.  In this case, Petal no longer associates the petal:
namespace with itself!

I generally set petal:attribute attributes to some dummy value, assign
the Petal namespace URI to something like 'xmlns:meta' and use the
aliased 'meta:attribute' to replace both 'xmlns:petal' and 'petal:attribute'
using a string: construct.

For example:

<test xmlns:meta="http://purl.org/petal/1.0/"
xmlns:petal="http://purl.org/petal/1.0/willBeReplaced"
meta:attributes="xmlns:petal string:http://purl.org/petal/1.0/">

<input type='hidden'
petal:attributes="value willBeReplaced"
meta:attributes="name configuration/get_identity_field_name;
  petal:attributes string:value
entry/${configuration/get_identity_field_name}"
 />
</test>

In this case, Petal processes the meta-template using the 'meta:' namespace,
replacing the 'xmlns:petal' attribute in the 'test' element, and both the
'name' and 'petal:attributes' attributes in the 'input' element.  When
processing
the resulting template, Petal uses the usual petal: namespace.

> Under 0.83 output:
> <input petal:attributes="value entry/id;" type="hidden" name="id" />
>
> Under 0.84 this doesn't work and complains ...
> 'Cannot find value for name="configuration/get_identity_field_name"?>:
> get_identity_field_name"?> cannot be retrieved
>
> Maybe I'm missing something (and its also possible that I'm leaving out
> important information to help me debug), but the behavior of resolving
> variables 'in place' for the 'attributes' attribute is fairly powerful
> (and valuable for making Petal templates from Petal templates). Was this
> behavior removed on purpose, or is this a side effect of the
>
>  > - Fixed entities not being encoded in static attributes.
>  >   Kurt's analysis seemed to be the right one so it was very easy

I think that there may be a problem with the bugfix that I submitted.
It appears that Petal has already replaced the inline syntax in the
attribute value with the PI syntax used internally before the attribute
is XML encoded and written to the output.  After processing your
meta-template I get the following for the 'input' element:

<input petal:attributes="value entry/&lt;?var
name=&quot;configuration/get_identity_field_name&quot;?&gt;;" type="hidden"
name="id" />

I need to track this down further.  I thought that the logic around
the code that I added had already assured that the attribute was
truly static, without interpolation operators, however I seem to
have been mistaken ;-)

By the way, there is another problem that comes up when you
use petal:attribute to fill in meta-template petal:attribute commands
with multiple placeholders.  Because the semicolon acts as a delimiter
for petal:attribute, it must be backslash-escaped when using the 'string:'
modifier in the meta-template.  But, since the semicolon is escaped,
it will not act as a delimiter in the resulting template!  I first kluged my
way around this by creating a hash value SC => ';' and replacing the
semicolons with ${SC} in the meta-template.  Since then, I have
written a 'qq:' modifier which calls 'string:'.  Petales expressions are
interpolated, and backslash-escape sequences are expanded much
like with Perl's qq{} operator.  More on this in a later post.

HTH,

Kurt Stephens
kstep at pepsdesign.com




More information about the Petal mailing list