Atom feeds with PHP 5 Dom and XSL January 13, 2008
Posted by idimmu in php.All blogs require silly amounts of feed generators, right? And this is a silly blog so requires a silly generator. The entire site is written using PHP5, and my automagic 'datahandler' activepage concept creates an XML document using DOM that then uses XSL as a templating engine, so I figured it wouldn't be too hard to knock up a stylesheet to turn the default datahandler for the blog in to a nice atom feed! Just make sure you set the content-type to application/atom+xml when generate the page!
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version = "1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" encoding="iso-8859-1" omit-xml-declaration="yes" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" doctype-public="-//W3C//DTD XHTML 1.1//EN" />
<xsl:template match="page">
<feed xmlns="http://www.w3.org/2005/Atom">
<link rel="alternate" type="text/html" href="http://www.idimmu.net/" />
<link rel="self" href="http://www.idimmu.net/blog/atom.php" />
<title>idimmu . net</title>
<link href="http://www.idimmu.net/"/>
<updated><xsl:value-of select="datahandler_blog/blog_list/blog/date/year"/>-<xsl:value-of select="datahandler_blog/blog_list/blog/date/month"/>-<xsl:value-of select="datahandler_blog/blog_list/blog/date/day"/>T<xsl:value-of select="datahandler_blog/blog_list/blog/date/hour"/>:<xsl:value-of select="datahandler_blog/blog_list/blog/date/minute"/>:<xsl:value-of select="datahandler_blog/blog_list/blog/date/second"/>Z</updated>
<author>
<name>idimmu</name>
</author>
<id>http://www.idimmu.net/</id>
<xsl:apply-templates select="datahandler_blog"/>
</feed>
</xsl:template>
<xsl:template match="datahandler_blog">
<xsl:apply-templates select="blog_list"/>
</xsl:template>
<xsl:template match="blog">
<entry>
<title><xsl:value-of select="title"/></title>
<link href="http://www.idimmu.net/{clonefakeurl}"/>
<id>http://www.idimmu.net/<xsl:value-of select="clonefakeurl"/></id>
<updated><xsl:value-of select="date/year"/>-<xsl:value-of select="date/month"/>-<xsl:value-of select="date/day"/>T<xsl:value-of select="date/hour"/>:<xsl:value-of select="date/minute"/>:<xsl:value-of select="date/second"/>Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<xsl:value-of select="bb_content" disable-output-escaping="yes"/>
</div>
</content>
</entry>
</xsl:template>
<xsl:template match="blog_list">
<xsl:apply-templates select="blog"/>
</xsl:template>
</xsl:stylesheet>



