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

I've got an XML file which I'm trying to transform via XSL using LibXML and LibXSL. It prints fine off the command line with the Doc Type and the correct formatting for html but Apache is throwing a 500 error saying that Bad Header = <html>. I know that in CGI you need to change the position of headers but I'm new to Perl and XSLT.
#!c:\perl\bin\perl.exe use strict; use warnings; use XML::LibXSLT; use XML::LibXML; my $parser = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); my $source = $parser->parse_file('xml'); my $style_doc = $parser->parse_file('xsl'); my $stylesheet = $xslt->parse_stylesheet($style_doc); my $results = $stylesheet->transform($source); print $stylesheet->output_string($results);
Is there any way of debugging what the script is sending to the server to see what is being added?

Replies are listed 'Best First'.
Re: Malformed headers from LibXSLT
by almut (Canon) on Apr 12, 2008 at 11:23 UTC

    You need to send the MIME-type before sending the actual content, i.e.

    ... print "Content-type: text/html\n\n"; print $stylesheet->output_string($results);

    (Note the two newlines — an empty line needs to separate the headers from the content.)

      D'oh! Hits head on PC table. Thanks.
Re: Malformed headers from LibXSLT
by oko1 (Deacon) on Apr 12, 2008 at 15:08 UTC

    This is not Perl-specific, but - as a general troubleshooting tool for headers and other "invisible" interaction stuff, I've always found "netcat" very useful. If I've got a CGI file (e.g., "info.cgi") that's not giving me any output, and it appears to run fine from the command line, I'll fire up my webserver and request that file via "nc":


    [ben@Tyr:~]$ nc localhost 80
    GET /info.cgi
    <HTML>
    <HEAD><TITLE>403 Forbidden</TITLE></HEAD>
    <BODY BGCOLOR="#cc9999" TEXT="#000000" LINK="#2020ff" VLINK="#4040cc">
    <H2>403 Forbidden</H2>
    The requested URL '/info.cgi' resolves to a file which is marked executable but is not a CGI file; retrieving it is forbidden.
    <HR>
    <ADDRESS><A HREF="http://www.acme.com/software/thttpd/">thttpd/2.23beta1 26may2002</A></ADDRESS>
    </BODY>
    </HTML>
    [ben@Tyr:~]$
    

    The above tells me that my webserver doesn't recognize this file as CGI - so now I know what to troubleshoot.

    
    -- 
    Human history becomes more and more a race between education and catastrophe. -- HG Wells