It works fine on my local machine... It produces nothing after removing 
<GlobalConfiguration> tags

On Fri, 29 Jul 2005 15:51:28 +0300
Ghais Issa <[EMAIL PROTECTED]> wrote:

> Hello everyone,
> I am writing a little program to generate configuration files out of
> templates and xml data files,
> this is a sample template
> 
> [% FOREACH g= GlobalConfiguration -%]
> [% g.TC %] qdisc del dev [% g.DEV %] root
> [% END %]
> 
> 
> and this is a sample xml data file
> 
> <TC>
> <GlobalConfiguration>
>       <TC>`tc1`</TC>
>       <DEV>eth1</DEV>
>       <Group>
>               <Name>MasterGroup</Name>
>               <ID>3</ID>
>               <Prio>1</Prio>
>               <Uplink>32</Uplink>
>               <Downlink>128</Downlink>
>       </Group>
>       <Group>
>               <Name>MinorGroup</Name>
>               <ID>2</ID>
>               <Prio>2</Prio>
>               <Uplink>16</Uplink>
>               <Downlink>64</Downlink>
>       </Group>
> </GlobalConfiguration>
> <GlobalConfiguration>
>       <TC>`tc2`</TC>
>       <DEV>eth2</DEV>
>       <Group>
>               <Name>MasterGroup</Name>
>               <ID>3</ID>
>               <Prio>1</Prio>
>               <Uplink>32</Uplink>
>               <Downlink>128</Downlink>
>       </Group>
>       <Group>
>               <Name>MinorGroup</Name>
>               <ID>2</ID>
>               <Prio>2</Prio>
>               <Uplink>16</Uplink>
>               <Downlink>64</Downlink>
>       </Group>
> </GlobalConfiguration>
> </TC>
> 
> the code, is 
> #!/usr/bin/perl -w
> use warnings;
> use strict;
> use XML::Simple;
> use Template;
> 
> 
> my $file = 'faysal.xml';
> my $xs = XML::Simple->new();
> 
> my $doc = $xs->XMLin($file);
> my $i = 0;
> #foreach my $key1 (keys(%$doc)){
> #    $i++;
> #    print "$key1\n$i\n";
> #}
> my $tt = Template->new;
> $tt->process('faysal.tmplt', $doc) or die $tt->error;
> 
> 
> Now, this works just fine with the following output:
> `tc1` qdisc del dev eth1 root
> `tc2` qdisc del dev eth2 root
> 
> however if i remove the second
> <GlobalConfiguration>........</GlobalConfiguration> tags, the program
> doesn't work correctly, it produces the following output:
>  qdisc del dev  root
>  qdisc del dev  root
>  qdisc del dev  root
> 
> without any of the variables,
> i tried adding this line to the template file to see the size of the loop
> [% loop.size %] and it says, 3 while it should be one
> 
> can anyone please tell me what the problem is here, and shouldn't the
> loop be processed only once, with the correct variable replacements
> 
> Best Rgds,
> 
> _______________________________________________
> templates mailing list
> [email protected]
> http://lists.template-toolkit.org/mailman/listinfo/templates


-- 
WBR dyker
Agava Software

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to