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>

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' } ] } } ] } };

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}

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.


In reply to help me in template toolkit module. by veerubiji

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.