Forum Moderators: phranque
So I'm looking for a small secure script that will pull the feed from my own directory, and embed the headlines into my own homepage.
I know that there are free proprietry *sites* that do this, but it seems daft to pull the feed from my directory to a server half a world a way, only to have it post the feed contents in a file back in my home directory.
I have MYSQL, but I'd prefer something that doesn't need it.
Anybody help?
Ta!
The best I could think was to use PHP5 but it's only just been released. The little I understand suggests this can pull xml + xslt and send the output to the user.
I'd look to write a simple XSLT stylesheet for the RSS and use PHP to do the work but this is not something I've tried before and may be dependant on your getting PHP5.. I've no idea whether PHP4 has XML handling.
Good luck.. I'd be interested to know of other approaches to this.
Is it really so complicated?
Anybody help?
Ta!
#!/usr/bin/perl
use XML::XSLT;
my $xmlfile = "example.xml";
my $xslfile = "example.xsl";
my $parser = XML::XSLT->new ($xslfile, "FILE");
$parser->transform_document ($xmlfile, "FILE");
$parser->print_result(); Maybe that's all you need?
for a stylesheet you might use something like..
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="item">
<h1><xsl:value-of select="title"/></h1>
<p><xsl:value-of select="description" disable-output-escaping="yes" /></p>
</xsl:template>
<xsl:template match="text()¦@*">
</xsl:template>
</xsl:stylesheet>
The perl script goes in the cgi-bin, where does the style sheet go?
And what code do I use on an html page to draw and embed the feed data?
Ta!
It goes wherever you want it and it's location is suggested by the my $xslfile = "example.xsl"; in the perl. So long as you get the relative location correct it should work.
The xml that the XSL stylesheet/transform works on is your RSS file.
If it does what we expect, the perl should call the XSL to transform the RSS file into HTML. ie. put your rss file location into my $xmlfile = "example.xml";
The transform I suggested is very simple but you can add other html elements to it. The XSL simply copies the HTML to output as it looks for "xsl:" elements.
<xsl:template match="item"> looks for all occurences of elements called 'item'
<xsl:template match="text()¦@*"> gives you control of the output by simply overwriting the default templates for text and attribute nodes. Otherwise you would get simple dump of the contents of nodes.
The only thing that might complicate this is if you are trying to add other <? scripting?> languages as the XSLT processor will try to understand the contents.. but then I believe there may be ways round that too.
Obviously you need to have the perl XML::XSLT module avaliable.
Hope that helps.
You can find more of an introduction to XML, XSL and others at w3schools [w3schools.com]
[edited by: davidpbrown at 9:10 am (utc) on July 16, 2004]
But my homepage is plain html, so I'm still scratchin' mi' bonce.
David, since you know more than I, why not try making a simple test rig to see if it works?
ie. Install the script and stylesheet, make a simple feed.xml file, and see if it displays in a .htm file on your site.
mydomain.com/index.htm
Appreciated ...