<?xml version="1.0" encoding="ISO-8859-1"?><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>
        
        &lt;xsp:logic&gt;
          String world = "world";
          String color = "red";
        &lt;/xsp:logic&gt;
        
      </pre>

      

      <p>
        Just compare this:
      </p>
      
      <pre>
        &lt;center style="color:{#color}"&gt;Hello simple {#world}!&lt;/center&gt;
      </pre>
      <center style="color:red">Hello simple world!</center>

      <p>
        to that:
      </p>
      <pre>
        &lt;center&gt;&lt;xsp:attribute name="style"&gt;color:&lt;xsp:expr&gt;color&lt;/xsp:expr&gt;&lt;/xsp:attribute&gt;Hello complex &lt;xsp:expr&gt;world&lt;/xsp:expr&gt;!&lt;/center&gt;
      </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>