On Wed, 9 Jul 2003, Matt Sergeant wrote:

> I think we should take a leaf out of XSLT's book and allow
> interpolation in attributes, so that this would work:
>
>      if (my $n = $page->previous_page) {
>          <pagenav previous="1" page="{$n}">&lt;&lt;</pagenav>
>      }

Patch to implement this attached. Shall I apply it?

-- 
<!-- Matt -->
<:->get a SMart net</:->
Spam trap - do not mail: [EMAIL PROTECTED]
Index: lib/Apache/AxKit/Language/XSP.pm
===================================================================
RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Language/XSP.pm,v
retrieving revision 1.41
diff -b -u -r1.41 XSP.pm
--- lib/Apache/AxKit/Language/XSP.pm    18 Jun 2003 14:11:56 -0000      1.41
+++ lib/Apache/AxKit/Language/XSP.pm    9 Jul 2003 14:48:28 -0000
@@ -681,6 +681,17 @@
         if (exists $attribs{'base-class'}) {
             $e->{XSP_Base_Class} = $attribs{'base-class'};
         }
+        if (my $i = lc $attribs{'attribute-value-interpolate'}) {
+            if ($i eq 'no') {
+                $e->{XSP_No_Attr_Interpolate} = 1;
+            }
+            elsif ($i eq 'yes') {
+                $e->{XSP_No_Attr_Interpolate} = 0;
+            }
+            else {
+                die "Unknown value for attribute-value-interpolate: $i";
+            }
+        }
     }
     elsif ($tag eq 'structure') {
     }
@@ -832,6 +843,32 @@
 
 *makeSingleQuoted = \&Apache::AxKit::Language::XSP::makeSingleQuoted;
 
+sub _undouble_curlies {
+    my $value = shift;
+    $value =~ s/\{\{/\{/g;
+    $value =~ s/\}\}/\}/g;
+    return $value;
+}
+
+sub _attr_value_template {
+    my ($e, $value) = @_;
+    if ($e->{XSP_No_Attr_Interpolate}) {
+        return makeSingleQuoted($value);
+    }
+    # return makeSingleQuoted($value);
+    warn("Transforming: $value\n");
+    my $output = "''";
+    while ($value =~ s/\G(.*?)\{(?!\{)(.*?)\}(?!\})//gcs) {
+        my $pre = $1;
+        my $code = $2;
+        $output .= ".";
+        $output .= makeSingleQuoted(_undouble_curlies($pre));
+        $output .= ".do{" . _undouble_curlies($code) . "}";
+    }
+    $output .= "." . makeSingleQuoted(_undouble_curlies($value));
+    return $output;
+}
+
 sub start_element {
     my ($e, $node) = @_;
 
@@ -888,8 +925,9 @@
     }
 
     for my $attr (@{$node->{Attributes}}) {
+        my $value = _attr_value_template($e, $attr->{Value});
         $code .= '$parent->setAttribute('.makeSingleQuoted($attr->{Name}).
-                ','.makeSingleQuoted($attr->{Value}).");\n";
+                ",$value);\n";
     }
 
     for my $ns (keys %{$e->{Current_NS}}) {
@@ -1254,7 +1292,7 @@
 
 =head1 Tag Reference
 
-=head2 C<<xsp:page>>
+=head2 C<< <xsp:page> >>
 
 This is the top level element, although it does not have to be. AxKit's
 XSP implementation can process XSP pages even if the top level element
@@ -1269,7 +1307,15 @@
 this feature, or it creates invalid output, then you can add the
 attribute: C<indent-result="yes">
 
-=head2 C<<xsp:structure>>
+By default all non-XSP and non-taglib attributes are interpolated in
+a similar way to XSLT attributes - by checking for C<{ code }> in the
+attributes. The C<code> can be any perl code, and is treated exactly
+the same as having an C<< <xsp:expr>code</xsp:expr> >> in the
+attribute value. In order to turn this I<off>, simply specify the
+attribute C<attribute-value-interpolate="no">. The default is C<yes>
+which enables the interpolation.
+
+=head2 C<< <xsp:structure> >>
 
   parent: <xsp:page>
 
@@ -1277,7 +1323,7 @@
 tags. It defines page-global "things" in the C<<xsp:logic>> and
 C<<xsp:import>> tags.
 
-=head2 C<<xsp:import>>
+=head2 C<< <xsp:import> >>
 
   parent: <xsp:structure>
 
@@ -1287,7 +1333,7 @@
     <xsp:import>DBI</xsp:import>
   </xsp:structure>
 
-=head2 C<<xsp:logic>>
+=head2 C<< <xsp:logic> >>
 
   parent: <xsp:structure>, any
 
@@ -1330,7 +1376,7 @@
 
 The reason is that XSP intrinsically knows about XML!
 
-=head2 C<<xsp:content>>
+=head2 C<< <xsp:content> >>
 
   parent: <xsp:logic>
 
@@ -1347,32 +1393,32 @@
     }
   </xsp:logic>
 
-=head2 C<<xsp:element>>
+=head2 C<< <xsp:element> >>
 
 This tag generates an element of name equal to the value in the attribute
 C<name>. Alternatively you can use a child element C<<xsp:name>> to specify
 the name of the element. Text contents of the C<<xsp:element>> are created
 as text node children of the new element.
 
-=head2 C<<xsp:attribute>>
+=head2 C<< <xsp:attribute> >>
 
 Generates an attribute. The name of the attribute can either be specified
 in the C<name="..."> attribute, or via a child element C<<xsp:name>>. The
 value of the attribute is the text contents of the tag.
 
-=head2 C<<xsp:comment>>
+=head2 C<< <xsp:comment> >>
 
 Normally XML comments are stripped from the output. So to add one back in
 you can use the C<<xsp:comment>> tag. The contents of the tag are the
 value of the comment.
 
-=head2 C<<xsp:text>>
+=head2 C<< <xsp:text> >>
 
 Create a plain text node. The contents of the tag are the text node to be
 generated. This is useful when you wish to just generate a text node while
 in an C<<xsp:logic>> section.
 
-=head2 C<<xsp:expr>>
+=head2 C<< <xsp:expr> >>
 
 This is probably the most useful, and most important (and also the most
 complex) tag. An expression is some perl code that executes, and the results

Reply via email to