PXTL is an XML document type allowing embedded Python code to control the generation of transformed document content.
It can be used for web page templating, in a style similar to existing templating languages such as PHP, JSP and ASP. Unlike these languages it is purely XML-based, and can be used for processing any kind of XML document.
The example templates in this tutorial are all XHTML, because this is the most common use of PXTL, and XHTML is a vocabulary well-known to most XML authors.
If you are currently writing ‘old-style’ HTML, you’ll need to learn XHTML before you can use PXTL. PXTL can be used to output plain HTML instead of XHTML, but you still have to write the original document in XHTML.
This is actually pretty simple. The Web Standards Project offers a useful guide to making the transition, but the quick summary for the impatient goes like this:
<p>...</p>
to surround each
paragraph instead of <p>
between paragraphs.
<br />
or <img src="..." alt="..." />
.
checked="checked"
.
Most importantly, though, XHTML documents have to be ‘well-formed’ XML. Whilst many web browsers will let you get away with mistakes like forgetting an end-tag or quotation mark in old-style HTML, XML tools will produce an error if they come across faulty markup.
Here is a simple PXTL template:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:px="http://www.doxdesk.com/pxtl">
<?px
n= 3
?>
<head>
<title>Hello,
<?_
n
?>times
</title>
</head>
<body>
<px:for range="
n
">
<p>Hello!
</p>
</px:for>
</body>
</html>
Blah write stuff.