Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

XML2HTML

by holygrail (Scribe)
on Jul 05, 2001 at 17:46 UTC ( [id://94100]=perlcraft: print w/replies, xml ) Need Help??

   1: <!-- 
   2: 
   3: XML2HTML
   4: 
   5: Author : HolyGrail
   6: Version: 0.1
   7: 
   8: This TemplateToolkit template  takes the same inputformat as XML2PDF
   9: (look there for the DTD...) and outputs HTML that looks just like the
  10: PDFfile.
  11: 
  12: I know, it's not spectacular, but now we have a media-independent
  13: DTD, with a conversiontool to HTML and to PDF :)
  14: 
  15: Use the following one-liner to process this HTML-Template
  16: (and save this file as template.html)
  17: 
  18: perl -MTemplate -e'$t=Template->new({EVAL_PERL => 1});$t->process("template.html") ||die $t->error'
  19: 
  20: -->
  21: <html>
  22: <body>
  23: [% USE xpath = XML.XPath(file => "./filename.xml") %]
  24: [% FOREACH section1 = xpath.findnodes('document/section1') %]
  25: <h1>[% section1.getAttribute('title') %]</h1>
  26: [% FOREACH node = section1.findnodes('*') %]
  27: [% IF node.getName() == 'section2' %]
  28: <h2>[% node.getAttribute('title') %]</h2>
  29: [% FOREACH p = node.findnodes('p') %]
  30: [% pvalue = p.string_value %]
  31: <p>[% PERL %] <!-- use Perl to convert the \n into <br> -->
  32: my $p = $stash->get('pvalue');
  33: $p=~s/\n/<br \/>\n/gs;
  34: print $p;
  35: [% END %]</p>
  36: [% END %]
  37: [% ELSE %]
  38: [% pvalue = node.string_value %]
  39: <p>[% PERL %] <!-- use Perl to convert the \n into <br> -->
  40: my $p = $stash->get('pvalue');
  41: $p=~s/\n/<br \/>\n/gs;
  42: print $p;
  43: [% END %]</p>
  44: [% END %]
  45: [% END %]
  46: [% END %]
  47: </body>
  48: </html>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-29 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found