<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:atom="http://purl.org/atom/ns#"
		xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
		xmlns:rss="http://purl.org/rss/1.0/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:dcterms="http://purl.org/dc/terms/"
		exclude-result-prefixes="atom"
                version="1.0">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
  <rdf:RDF>
    <xsl:apply-templates/>
  </rdf:RDF>
</xsl:template>

<xsl:template match="atom:feed">
  <xsl:if test="not(@version) or @version != '0.3'">
    <!-- Danger, Will Robinson! -->
  </xsl:if>
  <xsl:if test="not(atom:link[@rel='alternate'][1]/@href)">
    <!-- Error, Will Robinson! -->
  </xsl:if>

  <rss:channel>
    <xsl:attribute name="rdf:about">
      <xsl:value-of select="atom:link[@rel='alternate'][1]/@href"/>
    </xsl:attribute>
    <rss:title>
      <xsl:value-of select="atom:title"/>
    </rss:title>
    <rss:link>
      <xsl:value-of select="atom:link[@rel='alternate'][1]/@href"/>
    </rss:link>
    <xsl:if test="atom:tagline">
      <rss:description>
	<xsl:value-of select="atom:tagline"/>
      </rss:description>
    </xsl:if>
    <xsl:copy-of select="dc:*"/>
    <rss:items>
      <rdf:Seq>
	<xsl:for-each select="atom:entry">
	  <rdf:li rdf:resource="{atom:id}"/>
	</xsl:for-each>
      </rdf:Seq>
    </rss:items>
  </rss:channel>
  <xsl:apply-templates select="atom:entry"/>
</xsl:template>

<xsl:template match="atom:entry">
  <rss:item rdf:about="{atom:id}">
    <rss:title><xsl:value-of select="atom:title"/></rss:title>
    <xsl:if test="atom:link[@rel='alternate'][1]/@href">
      <rss:link><xsl:value-of select="atom:link[@rel='alternate'][1]/@href"/></rss:link>
    </xsl:if>
    <xsl:if test="atom:issued and not(dc:date)">
      <dc:date><xsl:value-of select="atom:issued"/></dc:date>
    </xsl:if>
    <xsl:if test="atom:modified and not (dcterms:modified)">
      <dcterms:modified><xsl:value-of select="atom:modified"/></dcterms:modified>
    </xsl:if>
    <xsl:copy-of select="dc:*|dcterms:*"/>
    <rss:description>
      <xsl:value-of select="atom:summary"/>
    </rss:description>
  </rss:item>
</xsl:template>

</xsl:stylesheet>

