10.3 Conditional elements

With STL it is possible to show or to hide an XML element based on a condition. For this purpose we use the stl:if attribute:

    <a href="edit_task" stl:if="can_edit">${title}</a>
    <span stl:if="not can_edit">${title}</span>

With the example above we will either have a link to a form to edit the task, or we will just have the title of the task. Depends on the value of the variable can_edit.

This is the syntax of the stl:if attribute:

    stl:if="[not] expression"

The value of the stl:if attribute is a boolean expression, the same boolean expressions we have seen in Section .

STL is an XML namespace

Something important to note from the previous template snippet is that the language STL uses XML namespaces, this means that the STL namespace must be declared:

    <?xml version="1.0" encoding="UTF-8"?>
    <html xmlns:stl="http://xml.itools.org/namespaces/stl"
      ...