untitled

(ff) #1

10.2 Transforming XML 247




2000-1-15
18.66
normal
62
46.27


2000-1-15
26.93
overweight
63
68.95


2000-2-1
33.95
obese
65
92.53


2000-2-1
17.38
normal
67
50.35


To produce the XML document above use program 10.19.
It should be clear at this point that as the complexity of the XML file in-
creases, producing it starts becoming tedious, even with procedures. What
is especially bad is that it is very hard to see the structure of the XML file in
the program. Templates are a technique that remedies this to some degree.
Instead of burying the output text in strings scattered throughout the pro-
gram, templates bury the program inside the output text. To use an old term
for this, templates are closer to being WYSIWIG (“What You See Is What You
Get”). There are many examples of the template style in use today. Active
Server Pages (ASP) and Java Server Pages (JSP), are examples of this style. In
both cases, the programs are HTML pages in which program code has been
inserted in appropriate places.
When using the Perl Template Toolkit, one will need both a Perl program
and a template file. Consider the task of producing an XML file that has just

Free download pdf