set_uk has asked for the wisdom of the Perl Monks concerning the following question:

I have an HTML Table that I want to prepend a header to and append a footer to.

I would prefer to use XSLT to read the file in and convert it using XSLT but I am getting hung up because all the HTML is escaped when read in as XML.

Whats the easiest way to achieve this without storing all the headers and footers in cfg files and catting them to the start and the end of the table.

I looked at DBD::Anydata but its not clear from the doc whether an HTMLTable can be converted to XML. Thanks

Replies are listed 'Best First'.
(jeffa) Re: HTML Table Question
by jeffa (Bishop) on Apr 14, 2003 at 17:35 UTC

    "Whats the easiest way to achieve this ..."

    If the escaped HTML is your problem, then HTML::Entities is your answer:
    decode_entities($string) This routine replaces HTML entities found in the $string with the corresponding ISO-8859/1 (or with perl-5.7 or better Unicode) character. Unrecognized entities are left alone.
    If (pre|ap)pending headers and footers is the problem, then we really need more info.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: HTML Table Question
by Improv (Pilgrim) on Apr 14, 2003 at 18:38 UTC
    If all you're opposed to is the literal use of 'cat', you can achieve the same effect with something like the following:
    #!/usr/bin/perl -w
    
    use diagnostics;
    
    my $data = <<EHEAD;
    <HTML>
    <HEAD><TITLE>My Title</TITLE></HEAD>
    <BODY BGCOLOR="#AAACCC">
    <H1>Headers are fun</H1>
    EHEAD
    
    local $/;
    open(HTABLE, "my_html_table") || die "Could not open table: $!\n";
    $data .= <HTABLE>;
    close(HTABLE);
    
    $data .= <<EFOOT;
    <HR>
    That's all, folks!
    </BODY></HTML>
    
    EFOOT
    
    print $data;
    
    If you want something else, we'll need more info on what you want before we can help.