#!/usr/bin/env perl
use strict;
use warnings;
####
use XML::Fast;
use Template;
use Data::Dumper;
my $xml = <<'XML';
24
bachelors
computers
128
xxxx
23
ph.d.
physics
12
yyyy
XML
my $xml_hash = xml2hash $xml;
print Dumper($xml_hash),$/;
my $template = Template->new();
my $filename = 'output.tex';
$template->process(\*DATA, $xml_hash, $filename)
|| die "Template process failed: ", $template->error(), "\n";
system( "pdflatex $filename" );
__DATA__
\documentclass{article}
\title{Roster}
\author{pavani}
\begin{document}
\maketitle
[% FOREACH st IN student %]
Student [% st.number %] is a [% st.specialization %] [% st.education %] student and his address is [% st.address.house_number +%] [% st.address.street_name %].
[% END %]
\end{document}
####
t.xml =
####
24
bachelors
computers
128
xxxx
23
ph.d.
physics
12
yyyy
22
BS
Biology
123
zzzz
21
MS
Agronomy
321
aaaa
20
Ph.D
sociology
333
bbbb
-- end t.xml
#!/usr/bin/env perl
use strict;
use warnings;
use XML::Fast;
use Template;
use Data::Dumper;
my $xmlfile = 't.xml';
my $xml;
{
open my $xml_fh, '<', $xmlfile or die "cannot open $xmlfile: $!\n";
$/ = '';
$xml = <$xml_fh>;
close $xml_fh;
}
print Dumper($xml),$/;
my $xml_hash = xml2hash $xml;
print Dumper($xml_hash),$/;
my $template = Template->new();
my $filename = 'output.tex';
$template->process(\*DATA, $xml_hash, $filename)
|| die "Template process failed: ", $template->error(), "\n";
system( "pdflatex $filename" );
__DATA__
\documentclass{article}
\title{Roster}
\author{pavani}
\begin{document}
\maketitle
[% FOREACH st IN student %]
Student [% st.number %] is a [% st.specialization %] [% st.education %] student and his address is [% st.address.house_number +%] [% st.address.street_name %].
[% END %]
\end{document}