<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:foaf="http://xmlns.com/foaf/0.1/"
  xmlns:bm="http://www.w3.org/2002/01/bookmark#"
  xmlns:a="http://www.w3.org/2001/10/annotea-ns#">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
    <rdf:RDF
      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:dc="http://purl.org/dc/elements/1.1/"
      xmlns:foaf="http://xmlns.com/foaf/0.1/"
      xmlns:bm="http://www.w3.org/2002/01/bookmark#"
      xmlns:a="http://www.w3.org/2001/10/annotea-ns#">
      <xsl:apply-templates match="/posts/post" />
    </rdf:RDF>
  </xsl:template>

  <xsl:template match="post">
    <bm:Bookmark rdf:about="http://del.icio.us/url/{@hash}">
      <bm:recalls rdf:resource="{@href}" />
      <dc:title><xsl:value-of select="@description" /></dc:title>
      <dc:description><xsl:value-of select="@extended" /></dc:description>
      <a:created><xsl:value-of select="@time" /></a:created>
      <xsl:call-template name="tags">
        <xsl:with-param name="tags" select="@tag" />
      </xsl:call-template>
    </bm:Bookmark>
  </xsl:template>

  <xsl:template name="tags">
    <xsl:param name="tags" />
    <xsl:if test="string-length(substring-before($tags, ' ')) &gt; 1">
      <bm:hasTopic rdf:resource="http://del.icio.us/tag/{substring-before($tags, ' ')}" />
      <xsl:call-template name="tags">
        <xsl:with-param name="tags" select="substring-after($tags, ' ')" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
