9.1 Usage

The FigureĀ 9.1 shows how STL works. Basically stl is a function that receives two parameters, an XML template and a Python namespace, and returns an XML string as the output.

\includegraphics[width=\textwidth ]{figures/stl}
Figure 9.1: The Simple Template Language (STL)

This is the way we use STL:

    # Import from itools
    from itools.handlers import get_handler
    from itools.stl import stl

    # Build the namespace
    namespace = {}
    namespace['title'] = 'Hello World'
    namespace['description'] = 'XXX'

    # Load the template
    template = get_handler('template.xml')

    # Call STL
    output = stl(template, namespace)

One thing should be clear now is that all the logic required to build the namespace is done in Python. STL enforces strict separation of concerns. We use the best language for each purpose, Python for the logic, XML for the presentation.