Hi every one,

I have several xml files and I processed through XML::Simple and i used
template toolkit process to genarate pdf by running pdflatex. I have
problem getting some data using template tool kit.
After processing xml data using XML::Simple I have hash data like this
$var1={

  'Service' => [
                       {
                         'Suppliers' => [
                                               {
                                                 'SW' => [
                                                         {

                                                           'ID' => 'CANMSG'
                                                         },
                                                         {
                                                           ' ID ' => 'ISAP'
                                                         }
                                                       ],
                                                 'HW' => [
                                                         {
                                                           'Type' =>
'CANCONV',
                                                           'Nr' => '1',
                                                           'Service' => '1'
                                                         }
                                                       ]
                                               }
                                             ],
                         'Id' => 'ASSI',
                         'Customers' => [
                                               {
                                                 'SW' => [
                                                         {

                                                           'ID' => 'AMBPRE'
                                                         }
                                                       ]
                                               }
                                             ],
                         'Description' => 'Provide signal with identifier',
                         'Name' => 'Ambient sensor Signal Identifier'
                       },
                       {
                         'Suppliers' => [
                                               {
                                                 'SW' => [
                                                         {

                                                           'ID' => 'CANMSG'
                                                         },
                                                         {

                                                           'ID' => 'ISNMM'
                                                         }
                                                       ],
                                                 'HW' => [
                                                         {
                                                           'Type' =>
'CANCONV',
                                                           'Nr' => '1',
                                                           'Service' => '1'
                                                         }
                                                       ]
                                               }
                                             ],
                         'Id' => 'ISAP',
                         'Customers' => [
                                               {
                                                 'SW' => [
                                                         {

                                                           'ID' => 'ASSI'
                                                         }
                                                       ]
                                               }
                                             ],
                         'Description' => 'Provide signal with identifier',
                         'Name' => 'Sensor Signal Identifier'

 },...........................................................

.....................................................

                    ]
       };

In the above data I have service information, each service have the Id,
name, description, suppliers and customers. In the suppliers we have either
SW , HW tags.
I written script like this to genarate pdf

#!/usr/bin/perl
use warnings;
use strict;
use XML::Simple;
use Data::Dumper;
use Template;

 my $xml = new XML::Simple;
  my $data = $xml->XMLin("$all", ForceArray => [
'Service','SW','HW','Customers','Suppliers'],);

print Dumper($data);
my $template = Template->new();
my $filename = 'Service.tex';
$template->process(\*DATA, $data, $filename)
    || die "Template process failed: ", $template->error(), "\n";
system( "pdflatex $filename" );
__DATA__
\documentclass[a4paper,leqno,twoside]{article}

\usepackage[latin1]{inputenc}

\usepackage[english]{babel}
\usepackage{multirow}

\begin{document}


[% FOREACH st IN Service %]
Name,Id:
[% st.Id %], [% st.Name %]

des:
[% st.Description %]

Customers:
[% FOREACH softservice IN st.Customers %][% FOREACH swid IN softservice.SW
%][% swid.ID %] [% FOREACH st IN Service %][% IF swid.ID == st.Id %]([%
st.Name %])

[% END %] [% END %][% END %][% END %]

Suppliers:

[% FOREACH shservice IN st.Suppliers %]

 [% FOREACH sw IN shservice.SW %][% sw.ID %] [% FOREACH st IN Service %][%
IF sw.ID == st.Id %]([% st.Name %])

[% END %] [% END %][% END %]

[% FOREACH hw IN shservice.HW %][% hw.Type %][% hw.Nr %][% END %]

[% END %]
\newpage
[% END %]
\end{document}

from above script I am able to print Service Id, name and deecription
perfectly. for service customers I written like IF customers.SW.ID is equal
to Service.Id then print customer ID and its name.
its working also but when i apply same procedure for suppliers (If
supplier.sw.ID is equal to Service.Id print both supplier ID and its name.)
but i don't know why its not working. Its not printing,
its printing last service suppliers ID's to all suppliers and also not
printing names. I am not able to understand what is the problem.

I need to print service customer name and if customer ID equal to any
service Id the then get its name. I need to print same for suppliers. my
output like this

customers:
ASSI( ambient pressure sensor identifier)
.......
......
suppliers:
ISAP(sensor signal identifier)

Can any one help me with this problem. what mistake i am doing and how to
overcom this.

Thanks in advance.
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to