untitled

(ff) #1
10.2 Transforming XML 253

use Template;

while (<>) {
chomp;
if (/Motif #([0-9]+):/) {
$label = $1;
$i = 0;
} elsif ($label && /^[0-9]+/) {
split;
$motifs{$label}[$i]{A} = $_[1];
$motifs{$label}[$i]{G} = $_[2];
$motifs{$label}[$i]{C} = $_[3];
$motifs{$label}[$i]{T} = $_[4];
$i++;
}
}
$tt = Template->new();
$vars = {
MotifData => {%motifs},
};
$tt->process("motif.tt", $vars);

Program 10.23 Using pattern matching to extract data and then formatting it with
Perl templates


  • The Perl Template Toolkit simplifies the production of XML documents
    by using a WYSIWIG style.

  • The Perl Template Toolkit has its own language for iteration and selecting
    an item of a hash or array. The Template Toolkit language is much simpler
    than Perl because it has fewer features.


10.2.5 Transforming XML to XML


The last type of transformation task is transforming from XML to XML. In
theory, this kind of transformation is just a special case of transforming from
XML to text. However, there are new issues that arise in this case, and there
are some new tools that are designed for this case.
Free download pdf