This module is an XIST namespace. It provides a simple template language based on processing instructions embedded in XML or plain text.
The following example is a simple "Hello, World" type template:
from ll.xist.ns import detox template = """ <?def helloworld(n=10)?> <?for i in range(n)?> Hello, World! <?end for?> <?end def?> """ module = detox.xml2mod(template) print "".join(module.helloworld())
class expr
(ll.xist.xsc.ProcInst
):
Embed the value of the expression
class textexpr
(ll.xist.xsc.ProcInst
):
class attrexpr
(ll.xist.xsc.ProcInst
):
class code
(ll.xist.xsc.ProcInst
):
Embed the PI data literally in the generated code.
For example <?code foo = 42?>
will put the statement foo = 42
into
the generated Python source.
class if_
(ll.xist.xsc.ProcInst
):
Starts an if block. An if block can contain zero or more elif_
blocks, followed by zero or one else_
block and must be closed
with an endif
PI.
For example:
<?code import random?> <?code n = random.choice("123?")?> <?if n == "1"?> One <?elif n == "2"?> Two <?elif n == "3"?> Three <?else?> Something else <?end if?>
class elif_
(ll.xist.xsc.ProcInst
):
Starts an elif block.
class else_
(ll.xist.xsc.ProcInst
):
Starts an else block.
class def_
(ll.xist.xsc.ProcInst
):
Start a function (or method) definition. A function definition must be
closed with an end
PI.
Example:
<?def persontable(persons)?> <table> <tr> <th>first name</th> <th>last name</th> </tr> <?for person in persons?> <tr> <td><?textexpr person.firstname?></td> <td><?textexpr person.lastname?></td> </tr> <?end for?> </table> <?end def?>
If the generated function contains output (i.e. if there is text content
or expr
, textexpr
or attrexpr
PIs before the
matching end
) the generated function will be a generator function.
Output outside of a function definition will be ignored.
class class_
(ll.xist.xsc.ProcInst
):
Start a class definition. A class definition must be closed with an
end
PI.
Example:
<?class mylist(list)?> <?def output(self)?> <ul> <?for item in self?> <li><?textexpr item?></li> <?endfor?> </ul> <?end def?> <?end class?>
class for_
(ll.xist.xsc.ProcInst
):
Start a for
loop. A for loop must be closed with an end
PI.
For example:
<ul> <?for i in range(10)?> <li><?expr str(i)?></li> <?end for?> </ul>
class while_
(ll.xist.xsc.ProcInst
):
Start a while
loop. A while loop must be closed with an end
PI.
For example:
<?code i = 0?> <ul> <?while True?> <li><?expr str(i)?><?code i += 1?></li> <?code if i > 10: break?> <?end while?> </ul>
class end
(ll.xist.xsc.ProcInst
):
Ends a while_
or for
loop or a if_
, def_
or class_
block.