logo       

Re: FOREACH loop help: msg#00147

Subject: Re: FOREACH loop help
Greets Pronichev Alexander and all

if you replace the previous xml file with this one:

<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>
</TC>

not if you remove all the <GlobalConfiguration> tags,
PS thanks for the quick reply

On 7/29/05, Pronichev Alexander <dyker-IKmu+C6G6q4AvxtiuMwx3w@xxxxxxxxxxxxxxxx> 
wrote:
> 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 <ghais.issa-Re5JQEeQqe8AvxtiuMwx3w@xxxxxxxxxxxxxxxx> 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
> > templates-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@xxxxxxxxxxxxxxxx
> > http://lists.template-toolkit.org/mailman/listinfo/templates
> 
> 
> --
> WBR dyker
> Agava Software
> 


-- 
Wherever a story ends, a new story might begin.


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe