DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Atom To Html Conversion
This file is intended to transform an Atom feed into html code fragment to be included in a complete page.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:atom="http://purl.org/atom/ns#"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:apply-templates select="/atom:feed/atom:head"/>
<xsl:apply-templates select="/atom:feed"/>
</xsl:template>
<xsl:template match="atom:feed/atom:head">
<h3><xsl:value-of select="atom:title"/></h3>
<xsl:if test="atom:tagline"><p><xsl:value-of select="atom:tagline"/></p></xsl:if>
<xsl:if test="atom:subtitle"><p><xsl:value-of select="atom:subtitle"/></p></xsl:if>
</xsl:template>
<xsl:template match="/atom:feed">
<h3><xsl:value-of select="atom:title"/></h3>
<xsl:if test="atom:tagline"><p><xsl:value-of select="atom:tagline"/></p></xsl:if>
<xsl:if test="atom:subtitle"><p><xsl:value-of select="atom:subtitle"/></p></xsl:if>
<ul>
<xsl:apply-templates select="atom:entry"/>
</ul>
</xsl:template>
<xsl:template match="atom:entry">
<li>
<a href="{atom:link[@rel='related']/@href}" title="{substring(atom:published, 0, 11)}"><xsl:value-of select="atom:title"/></a>
<xsl:choose>
<xsl:when test="atom:content != ''">
<p><xsl:value-of select="atom:content" disable-output-escaping="yes" /></p>
</xsl:when>
<xsl:otherwise>
<p><xsl:value-of select="atom:summary" disable-output-escaping="yes" /></p>
</xsl:otherwise>
</xsl:choose>
</li>
</xsl:template>
</xsl:stylesheet>





Comments
Timothy Sumner replied on Tue, 2012/10/09 - 9:28am
Sorry for asking a painful question but how do I use this script to convert an Atom feed into an HTML site?
Thanks
Tim
Snippets Manager replied on Thu, 2012/01/19 - 2:06pm
xmlns:atom="http://www.w3.org/2005/Atom"in order to match elements in current Atom feeds.Snippets Manager replied on Tue, 2008/04/08 - 11:02am