Hello,
I'm currently doing some RDF/RSS scripting. I've written this very simple script that takes an RSS file or URI, loads it in or gets it from the web server, converts all files to RSS 0.91 format (so the XSL-T is easier), then loads the file into Matts excellent LibXML, and the XSL-T file into LibXSLT, and finally dumps the output.
Called from the command line with local RSS and XSL files, it takes about 2 seconds on a low end NT box to run. The same script called via Apache/CGI on the same machine takes a LOT longer, about 4 minutes.
I put some print statments and an exit and it seems that the XML Parser is taking for ever to run when called via CGI, the rest is done in less than 1 second. I've done XSL-T using this module before on the same box via CGI and it ran fine before.
The RSS files are short, the XSL-T file is short and simple, and it runs fine from the command line, what am I doing that's so stupid as to screw it up under CGI?
Code Snip: uses strict, CGI, LibXML, LibXSLT etc etc
$rss->parse($xml);
$rss->{output} = '0.91';
$xml=$rss->as_string;
my $xslt = XML::LibXSLT->new();
my $xml_parser = XML::LibXML->new();
$xml_parser->keep_blanks(0);
$xml_parser->load_ext_dtd(0);
my $source_xml = $xml_parser->parse_string($xml);
my $style_xsl = $xml_parser->parse_file($style);
my $stylesheet = $xslt->parse_stylesheet($style_xsl);
my $result_xml = $stylesheet->transform($source_xml);
print $stylesheet->output_string($result_xml);
Here is an examle RSS file:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="C:\web\home\xml\xsl\rss-rdf.xsl
+"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns
+="http://my.netscape.com/rdf/simple/0.9/">
<channel>
<title>freshmeat.net</title>
<link>http://freshmeat.net</link>
<description>the one-stop-shop for all your Linux softwar need
+s</description>
</channel>
<image>
<title>freshmeat.net</title>
<url>http://freshmeat.net/images/fm.mini.jpg</url>
<link>http://freshmeat.net</link>
</image>
<item>
<title>Geheimnis 0.59</title>
<link>http://freshmeat.net/news/1999/06/21/930004162.html</lin
+k>
</item>
<item>
<title>Firewall Manager 1.3 PRO</title>
<link>http://freshmeat.net/news/1999/06/21/930004148.html</lin
+k>
</item>
<textinput>
<title>quick finder</title>
<description>Use the text input below to search the fresh
meat application database</description>
<name>query</name>
<link>http://core.freshmeat.net/search.php3</link>
</textinput>
</rdf:RDF>
Here is a simple XSL-T:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="xsl"
>
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<div>
<xsl:apply-templates select="rss"/>
</div>
</xsl:template>
<xsl:template match="rss">
<xsl:apply-templates select="channel"/>
</xsl:template>
<xsl:template match="channel">
<xsl:variable name="link" select="link"/>
<xsl:variable name="description" select="description"/>
<h1><a href="{$link}" title="{$description}"><xsl:value-of select=
+"title" /></a></h1>
<hr />
<ul><xsl:apply-templates select="item"/></ul>
</xsl:template>
<xsl:template match="item">
<xsl:variable name="item_link" select="link"/>
<xsl:variable name="item_title" select="description"/>
<li><a href="{$item_link}" title=""><xsl:value-of select="title"/>
+</a></li>
</xsl:template>
</xsl:stylesheet>