Forum OpenACS Development: Re: new templating model: ideas, questions

Collapse
Posted by Andrei Popov on

I am not suggesting using XSL as such -- only following the approach, as this creates a valid XML file. I guess that a sample template could be something like this (using original example):

<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>@title@</title> <!-- keep @var@'s -->
</head>

<body>
  <p>Got a list @list@</p>
  <p>Looping over list:</p>
  <ul>
    <tcl:foreach l="@list@">
      <li>@l@</li>
    </tcl:foreach>
  </ul>

  <p>Got an array @array@</p>
  <p>Looping over Array:</p>
  <table>
    <tr>
      <th>Name</th>
      <th>Age</th>
      <th>City</th>
    </tr>
    <tcl:foreach a="@array@">
      <tr>
        <td>@a(name)@</td>
        <td>@a(age)@</td>
        <td>@a(city)@</td>
      </tr>
    </tcl:foreach>
  </table>

</body>
</html>

When <tcl:...> tag is parsed in this case, XML quoting (single or double quotes) should simply be stripped before evaluating quoted expression. Then an expression should be evaluated using Tcl evaluation rules. Using namespace prefix (tcl:) should actually help parser a lot, since it would no that only these tags need to be expanded, others can remain as they are.

I am sure that this is *very* simplistic, but it may just work... Just don't think of it as "implement templating system in XSL", but rahter "borrow XSL syntax for template definition language".