untitled

(ff) #1

252 10 Transforming with Traditional Programming Languages



  1. Selection of a part of a data structure is specified in Perl using brackets
    for array indices (e.g.,$x[1]) and braces for hash keys (e.g.,$h{name}.
    The Template Toolkit uses the dot notation for both of these (e.g.,x.1and
    h.name, respectively).

  2. Keywords such asFOREACHare written using all capital letters in the Tem-
    plate Toolkit, but using lower-case letters in Perl.
    The Template Toolkit can simplify its notation because it supports a very
    limited range of features compared with Perl.
    Next consider a more difficult transformation such as transforming the
    output produced by BioProspector as in subsection 10.1.4. The Perl program
    for extracting the motifs must be modified so that the information is kept in a
    Perl data structure which is given to the template in the usual way, as shown
    in program 10.23. The corresponding template is shown in template 10.3.
    Running this program on the BioProspector file produces output that begins
    like this:


<MotifData>

<Motif id=’1’>

<DNA>
<A>0.00</A>
<C>0.21</C>
<T>0.59</T>
<G>0.21</G>
</DNA>

...

The extra blank lines come from theFOREACHandENDdirectives. These do
not produce any text by themselves, so they show up as blank lines in the
output. To get rid of the unnecessary blank lines and other spaces, just add
dashes at the end of each directive, as shown in template 10.4.

Summary


  • To convert non-XML data to the XML format, one can use the same tech-
    niques that apply to any kind of processing of text data. The XML docu-
    ment is just another kind of output format.

Free download pdf