-<page xmlns:xsp="http://apache.org/xsp" xmlns:xsp-interpolation="http://apache.org/xsp/interpolation/1.0">
<title>Attribute and Text Interpolation</title>
-<content>
-<p>
Apache Cocoon 2.1.9 allows to use
<tt>{#expr}</tt>
to replace the value of the Java expression
<tt>expr</tt>
within attribute values and text nodes.
</p>
<p> For expression interpolation in text nodes the difference is to the usual xsp:expr syntax is minor. For dynamic attribute values, however, interpolation keeps it much more concise and readable. </p>
<pre> <xsp:logic> String world = "world"; String color = "red"; </xsp:logic> </pre>
<p> Just compare this: </p>
<pre> <center style="color:{#color}">Hello simple {#world}!</center> </pre>
<center style="color:red">Hello simple world!</center>
<p> to that: </p>
<pre> <center><xsp:attribute name="style">color:<xsp:expr>color</xsp:expr></xsp:attribute>Hello complex <xsp:expr>world</xsp:expr>!</center> </pre>
<center style="color:red">Hello complex world!</center>
<p> Interpolation can also be used in logicsheets: </p>
<center style="color:red">Hello logicsheet world!</center>
<p> The XSP expression parser understands nested braces, single and double quoted strings, and backslash-escaped quotes and apostrophes. </p>
-<table border="1">
-<tr>
<th>Expression</th>
<th>Result</th>
<th>Expected</th>
</tr>
-<tr>
<td> {#new String[]{}.length} </td>
<td> 0 </td>
<td> 0 </td>
</tr>
-<tr>
<td> {#new String[]{"}"}.length} </td>
<td> 1 </td>
<td> 1 </td>
</tr>
-<tr>
<td> {#"'\"}".indexOf('}')} </td>
<td> 2 </td>
<td> 2 </td>
</tr>
</table>
</content>
</page>