<?xml version="1.0"?>
<xsl:transform
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:admin="http://webns.net/mvcb/"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:dcterms="http://purl.org/dc/terms/"
  xmlns:atom="http://purl.org/atom/ns#"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:foaf="http://xmlns.com/foaf/0.1/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  version="1.0">
  <xsl:output method="XML" indent="yes"/>

  <xsl:template match="atom:feed">
    <rdf:RDF>
      <atom:Feed>
        <xsl:apply-templates select="@*[not(name()='version')]" />

        <xsl:if test="atom:id">
          <xsl:attribute name="rdf:about">
            <xsl:value-of select="atom:id"/>
          </xsl:attribute>
        </xsl:if>

        <xsl:apply-templates select="*[not(self::atom:id) and
                                       not(self::atom:entry) and
                                       not(self::atom:contributor)]" />

        <xsl:if test="atom:contributor">
          <atom:contributors rdf:parseType="Collection">
            <xsl:apply-templates select="atom:contributor"/>
          </atom:contributors>
        </xsl:if>

        <xsl:if test="atom:entry">
          <atom:entries rdf:parseType="Collection">
            <xsl:apply-templates select="atom:entry"/>
          </atom:entries>
        </xsl:if>
      </atom:Feed>
    </rdf:RDF>
  </xsl:template>

  <xsl:template match="atom:entry">
    <atom:Entry>
      <xsl:apply-templates select="@*" />
      <xsl:if test="atom:id">
        <xsl:attribute name="rdf:about">
          <xsl:value-of select="atom:id"/>
        </xsl:attribute>
      </xsl:if>

      <xsl:apply-templates select="*[not(self::atom:contributor) and
                                     not(self::atom:id)]" />

      <xsl:if test="atom:contributor">
        <atom:contributors rdf:parseType="Collection">
          <xsl:apply-templates select="atom:contributor"/>
        </atom:contributors>
      </xsl:if>
    </atom:Entry>
  </xsl:template>

  <xsl:template match="atom:link">
    <atom:link>
      <xsl:attribute name="rdf:resource">
        <xsl:value-of select="."/>
      </xsl:attribute>
    </atom:link>
  </xsl:template>

  <xsl:template match="atom:title">
    <dc:title>
      <xsl:apply-templates select="*|@*|text()"/>
    </dc:title>
  </xsl:template>

  <xsl:template match="atom:summary">
    <dc:description>
      <xsl:apply-templates select="*|@*|text()"/>
    </dc:description>
  </xsl:template>

  <xsl:template match="atom:copyright">
    <dc:rights>
      <xsl:apply-templates select="*|@*|text()"/>
    </dc:rights>
  </xsl:template>

  <xsl:template match="atom:created">
    <dcterms:created>
      <xsl:apply-templates select="*|@*|text()"/>
    </dcterms:created>
  </xsl:template>

  <xsl:template match="atom:issued">
    <dcterms:issued>
      <xsl:apply-templates select="*|@*|text()"/>
    </dcterms:issued>
  </xsl:template>

  <xsl:template match="atom:modified">
    <dcterms:modified>
      <xsl:apply-templates select="*|@*|text()"/>
    </dcterms:modified>
  </xsl:template>

  <xsl:template match="atom:author/atom:name">
    <dc:creator>
      <xsl:apply-templates select="*|@*|text()"/>
    </dc:creator>
  </xsl:template>

  <xsl:template match="atom:feed/atom:tagline">
    <dc:description>
      <xsl:apply-templates select="*|@*|text()"/>
    </dc:description>
  </xsl:template>

  <xsl:template match="atom:generator">
    <admin:generatorAgent>
      <rdf:Description>
        <xsl:attribute name="rdf:about">
          <xsl:value-of select="."/>
        </xsl:attribute>
        <dc:title>
          <xsl:value-of select="@name"/>
        </dc:title>
        <xsl:apply-templates select="*"/>
      </rdf:Description>
    </admin:generatorAgent>
  </xsl:template>

  <xsl:template match="atom:author">
    <foaf:maker>
      <foaf:Person>
        <xsl:if test="atom:name">
          <foaf:name>
            <xsl:value-of select="atom:name"/>
          </foaf:name>
        </xsl:if>

        <xsl:if test="atom:url">
          <foaf:weblog>
            <xsl:attribute name="rdf:resource">
              <xsl:value-of select="atom:url"/>
            </xsl:attribute>
          </foaf:weblog>
        </xsl:if>

        <xsl:if test="atom:email">
          <foaf:mbox>
            <xsl:attribute name="rdf:resource">
              <xsl:text>mailto:</xsl:text>
              <xsl:value-of select="atom:email"/>
            </xsl:attribute>
          </foaf:mbox>
        </xsl:if>

      </foaf:Person>
    </foaf:maker>
  </xsl:template>

  <xsl:template match="atom:contributor">
    <foaf:Person>
      <xsl:if test="atom:name">
        <foaf:name>
          <xsl:value-of select="atom:name"/>
        </foaf:name>
      </xsl:if>

      <xsl:if test="atom:url">
        <foaf:weblog>
          <xsl:attribute name="rdf:resource">
            <xsl:value-of select="atom:url"/>
          </xsl:attribute>
        </foaf:weblog>
      </xsl:if>

      <xsl:if test="atom:email">
        <foaf:mbox>
          <xsl:attribute name="rdf:resource">
            <xsl:text>mailto:</xsl:text>
            <xsl:value-of select="atom:email"/>
          </xsl:attribute>
        </foaf:mbox>
      </xsl:if>

    </foaf:Person>
  </xsl:template>
	
  <xsl:template match="atom:content">
    <atom:content>
      <xsl:attribute name="rdf:parseType">Resource</xsl:attribute>
      <xsl:apply-templates select="@xml:*"/>

      <atom:type>
        <xsl:value-of select="@type"/>
      </atom:type>

      <xsl:if test="atom:mode">
        <atom:encoding>
          <xsl:attribute name="rdf:resource">
            <xsl:text>http://purl.org/atom/ns#</xsl:text>
            <xsl:value-of select="atom:mode"/>
          </xsl:attribute>
        </atom:encoding>
      </xsl:if>

      <xsl:if test="not(atom:mode)">
        <atom:encoding rdf:resource="http://purl.org/atom/ns#xml"/>
      </xsl:if>

      <rdf:value rdf:parseType="Literal">
        <xsl:apply-templates select="*"/>
      </rdf:value>
    </atom:content>
  </xsl:template>

  <xsl:template match="*|@*|text()">
    <xsl:copy>
      <xsl:apply-templates select="*|@*|text()"/>
    </xsl:copy>
  </xsl:template>

</xsl:transform>
