llarochelle has asked for the wisdom of the Perl Monks concerning the following question:
Using the Template Toolkit, I'm creating templates in an XML format to create XLS files. Of course, I'm using the TT instructions such as "[% FOREACH ... %], [% END %], [% IF %]". My objective is to create a user friendly HTML view of a template so users can consult it. I want to retrieve sheet names, cell contents and TT instructions.
I'm looking for advice on two different topics. First I was thinking about XML::LibXML for the XML parsing part. Is it a good choice for this task ? Second, since TT instructions won't be recognized as XML content, how should I parse the mixed content to obtain a result respecting the template logic ? (line order)
Post edit : After my reply to Marto, I thought I should add some info to my post.
The source data is XML with TT instructions in the file. The XML is intended to create and XLS file.Below is an extract
So what I want to do, is extract both "cell text" and TT instructions to recreate the content in HTML format. Problem is, how should I parse the file so that I can retrieve XML with XML::LibXML & TT instruction lines at the same time ? Like I said, my objective is to display the template to the users. Creating the XLS file is not a problem. I want to show network engineers how the template is built without giving access to the .tt file.<?xml version="1.0" encoding="ISO-8859-1"?> <workbook> <worksheet name="[% config.template %]"><format color="black"> [% FOREACH host IN hosts %] <row><bold><format color="white" size="14" bg_color="blue"><cell w +idth="60" text="Configuring de : [% host.name %]" /></format></bold>< +/row> <row /> [% FOREACH int IN host.interfaces %] <row><cell text="interface ip-bundle [% int.bundle %].[% int.subBu +ndle %]" /></row> [% FOREACH ip IN int.secondaries %] <row><cell text=" ip address [% ip.ipAddress %] [% ip.subnetMask % +] [% bits(ip.ipAddress,ip.subnetMask) %] secondary" /></row> [% END %] <row><cell text="!"/></row> [% END %] <row /> <row><bold><format color="white" size="14" bg_color="blue"><cell t +ext="END OF : [% host.name %]" /></format></bold></row> <row /><row /><row /> [% END %] </format> </worksheet> </workbook>
Cheers ! Luc
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML Parsing in a "mixed content" file
by marto (Cardinal) on Jan 11, 2019 at 16:05 UTC | |
by llarochelle (Beadle) on Jan 11, 2019 at 16:47 UTC | |
by marto (Cardinal) on Jan 11, 2019 at 16:53 UTC | |
by llarochelle (Beadle) on Jan 11, 2019 at 17:48 UTC | |
|
Re: XML Parsing in a "mixed content" file
by poj (Abbot) on Jan 11, 2019 at 18:21 UTC | |
by llarochelle (Beadle) on Jan 11, 2019 at 18:51 UTC | |
|
Re: XML Parsing in a "mixed content" file
by haukex (Archbishop) on Jan 11, 2019 at 16:47 UTC | |
by llarochelle (Beadle) on Jan 14, 2019 at 14:58 UTC | |
|
Re: XML Parsing in a "mixed content" file
by Veltro (Hermit) on Jan 11, 2019 at 22:06 UTC |