more useful options PerlMonks

help me in template toolkit module.

by veerubiji (Sexton)
 on Oct 27, 2011 at 09:24 UTC ( #934092=perlquestion: print w/ replies, xml ) Need Help??
veerubiji has asked for the wisdom of the Perl Monks concerning the following question:

Hi I have xml data like this

    <university>
<name>svu</name>
<location>ravru</location>
<branch>
<electronics>
<Section>
<student name="xxx" number="12">
<sem semister="1"subjects="7" rank="1"/
+>
<sem semister="2"subjects="4" rank="1"/
+>
<student>
<student name="xxx" number="15">
<sem semister="1"subjects="7" rank="10"
+/>
<sem semister="2"subjects="4" rank="1"/
+>
<student>
<student name="xxx" number="16">
<sem semister="1"subjects="7" rank="2"/
+>
<sem semister="2"subjects="4" rank="2"/
+>
<student>
</section>
</electronics>
</branch>
</university>
<university>
<name>sku</name>
<location>ANTP</location>
<branch>
<computers>
<Section>
<student name="xxx" number="12">
<sem semister="1"subjects="7" rank="no"
+/>
<sem semister="2"subjects="4" rank="no"
+/>
<student>
<student name="xxx" number="15">
<sem semister="1"subjects="7" rank="10"
+/>
<sem semister="2"subjects="4" rank="1"/
+>
<student>
<student name="xxx" number="16">
<sem semister="1"subjects="7" rank="20"
+/>
<sem semister="2"subjects="4" rank="21"
+/>
<student>
</section>
</electronics>
</branch>
</university>
[download]

I used XML::Simple and I generated hash structured data and stored in a variable. I used template::toolkit to generate pdffile(using pdflatex).my XML::simple output is like this

    $var1={ university=>{ 'name'=>'svu', 'location'=>'ravru', 'branch'=>{ 'electronics'=>{ 'section'=>[ { 'name'=>'xxx', 'number'=>'12', 'sem'=>[ { 'semister'=>'1', 'subjects'=>'7', 'rank'=>'1' }, { 'semister'=>'2', 'subjects'=>'4', 'rank'=>'1' } ] }, { 'name'=>'xxx', 'number'=>'15', 'sem'=>[ { 'semister'=>'1', 'subjects'=>'7', 'rank'=>'10' }, { 'semister'=>'1', 'subjects'=>'7', 'rank'=>'1' } ] }, { 'name'=>'xxx', 'number'=>'16', 'sem'=>[ { 'semister'=>'1', 'subjects'=>'7', 'rank'=>'2' }, { 'semister'=>'2', 'subjects'=>'4', 'rank'=>'2' } ] } } ] } }; [download] like this I have 15 universities and also some section having only two or three students some having 10 students, in students some body only one sem some having two semesters like that.I written template like this  my$template = Template->new();
my $filename = 'output.tex';$template->process(\*DATA, $data,$filename)
|| die "Template process failed: ", $template->error(), "\n"; system( "pdflatex$filename" );
__DATA__
\documentclass[a4paper,leqno,twoside]{article}
\begin{document}
[% FOREACH st IN university %]
[% st.name %]
[% st.location %]
branch student:[% st.branch.electronics.section.0.name %]
+
[%st.branch.electronics.section.0.number %]
[% st.branch.electronics.section.0.sem.semister %]
[% st.branch.electronics.section.0.sem.subjects %]
[% st.branch.electronics.section.0.sem.rank %]
branch student:[% st.branch.electronics.section.1.name %]
+
[%st.branch.electronics.section.1.number %]
[% st.branch.electronics.section.1.sem.semister %]
[% st.branch.electronics.section.1.sem.subjects %]
[% st.branch.electronics.section.1.sem.rank %]
[%END%]
/end{document}
[download]

like this it giving output but My problem is its too lengthy and also I said above some section have two students and some sections have more than two. for example first section contains 1 student and second section contains 10 students like that. but in pdf first section also printing 10 students only first student have information remaining all empty. how can I eliminate this problem. If you dont understand my problem just how can I get the data using shorter code than i written. is there any other way to get branch elements all with simpler using for loop for branch elements or any simple code.because if some section have 60 students so it printing 6o in every section.How can I use loop for getting section students data because i am using one for loop for getting all universitys data.

Comment on help me in template toolkit module.
Re: help me in template toolkit module.
by zwon (Monsignor) on Oct 27, 2011 at 13:52 UTC
it printing empty.

I'd be surprised if setting $template::Stash::PRIVATE even to true value would print anything. First of all it should be$Template::Stash::PRIVATE, but you don't need it anyway. You need process method, try it like this:

$tt->process(\*DATA) || die$tt->error(), "\n";
[download]
Note this \$tt->error(), it will tell you what's wrong.

yes ,your right I modified and I solved all problem but I am struggling with above problem can you help .

Re: help me in template toolkit module.
by Anonymous Monk on Oct 27, 2011 at 18:03 UTC

I am not able to get this type of complex data , Remaining everything I solved and I am getting output as I want but this problem suffers me.please help me.

Hi

You're supposed to mark your updates How do I change/delete my post?, so as not to make replies look out of context

Your question, in its current form, is unanswerable. How do I post a question effectively?

Create A New User
Node Status?
node history
Node Type: perlquestion [id://934092]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2013-05-26 09:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?