You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xsp-dev@xml.apache.org by Matt Sergeant <ma...@sergeant.org> on 2003/07/10 00:16:59 UTC

Proposal: Attribute value interpolation

Hi core XSP developers...

This is a proposal to support attribute value interpolation (called 
"attribute value templates" in XSLT) in XSP. We have an implementation 
of this in AxKit now, and it really makes a huge difference in code 
size in place of using <xsp:attribute> all over the place in order to 
get dynamic attribute values.

Basically it works like this:

<xsp:page>
   <page>
     <xsp:logic>
       my $tomorrow = localtime(time + 86400);
     </xsp:logic>
     <foo bar="{$tomorrow}"/>
   </page>
</xsp:page>

Here the output is something like:

   <page>
     <foo bar="Thu Jul 10 23:11:35 2003"/>
   </page>

If you need a curly bracket inside you have to escape it. This is a bit 
of a pain for Java and Perl - being curly bracket based languages, but 
it's that way to be similar to XSLT:

   <foo bar="{$a->{{dir}}}/{$a->{{file}}}"/>

Which is equivalent to the regular XSP:

   <foo>
     <xsp:attribute name="bar">
     <xsp:expr>$a->{dir}</xsp:expr>/<xsp:expr>$a->{file}</xsp:expr>
     </xsp:attribute>
   </foo>

(there you can really see the verbosity in play!)

Finally, this is so useful we're going to make this the default 
behaviour in the next release of AxKit, but you can turn it off on a 
page-by-page basis with the top level <xsp:page> attribute:

   <xsp:page attribute-value-interpolation="no">

We'd like to consider making this a part of the spec, as if not, it'll 
be an AxKit-only extension.

Matt.