Skip to content

Instantly share code, notes, and snippets.

@atomicules
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomicules/02b9291243a3f50738ec to your computer and use it in GitHub Desktop.
Save atomicules/02b9291243a3f50738ec to your computer and use it in GitHub Desktop.
My slight modification (as rev 2 of this gist) to the atom2rss.xsl file from here: https://kiza.eu/software/snownews/snowscripts/extensions/script/atom2rss/
<?xml version="1.0"?>
<!-- Atom to RSS 1.0 Transformation, written by Rene Puls (rpuls@kcore.de) -->
<!-- Snownews filter command for this extension: "xsltproc /path/to/atom2rss -" -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns="http://purl.org/rss/1.0/">
<xsl:output method="xml" indent="yes" cdata-section-elements="description" />
<xsl:template match="/">
<xsl:apply-templates select="atom:feed" />
</xsl:template>
<xsl:template match="atom:feed">
<rdf:RDF>
<channel>
<xsl:attribute name="rdf:about"><xsl:value-of select="atom:link[@rel='service.feed']/@href" /></xsl:attribute>
<title><xsl:value-of select="normalize-space(atom:title)" /></title>
<xsl:choose>
<xsl:when test="atom:link[@type='text/html']/@href">
<link><xsl:value-of select="atom:link[@type='text/html']/@href" /></link>
</xsl:when>
<xsl:otherwise>
<link><xsl:value-of select="atom:link[not(@rel='self')]/@href" /></link>
</xsl:otherwise>
</xsl:choose>
<description><xsl:value-of select="normalize-space(atom:info)" /></description>
<items>
<rdf:Seq>
<xsl:apply-templates select="atom:entry" mode="rdfitem"/>
</rdf:Seq>
</items>
</channel>
<xsl:apply-templates select="atom:entry" mode="rssitem" />
</rdf:RDF>
</xsl:template>
<xsl:template match="atom:entry" mode="rdfitem">
<rdf:li>
<xsl:attribute name="rdf:resource">
<xsl:value-of select="normalize-space(atom:id)" />
</xsl:attribute>
</rdf:li>
</xsl:template>
<xsl:template match="atom:entry" mode="rssitem">
<item>
<xsl:attribute name="rdf:about">
<xsl:value-of select="normalize-space(atom:id)" />
</xsl:attribute>
<title><xsl:value-of select="normalize-space(atom:title)" /></title>
<xsl:choose>
<xsl:when test="atom:link[@type='text/html']/@href">
<link><xsl:value-of select="atom:link[@type='text/html']/@href" /></link>
</xsl:when>
<xsl:otherwise>
<link><xsl:value-of select="atom:link[not(@rel='self')]/@href" /></link>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="atom:issued">
<dc:date><xsl:value-of select="normalize-space(atom:issued)" /></dc:date>
</xsl:if>
<xsl:if test="atom:author">
<dc:creator><xsl:value-of select="normalize-space(atom:author)" /></dc:creator>
</xsl:if>
<xsl:if test="atom:content">
<description><xsl:value-of select="normalize-space(atom:content)" /></description>
</xsl:if>
<xsl:if test="not(atom:content) and atom:summary">
<description><xsl:value-of select="normalize-space(atom:summary)" /></description>
</xsl:if>
</item>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment