<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:so="http://rdf.opiumfield.com/so/" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="text()" />
  <xsl:template match="opml">
    <rdf:RDF>
      <xsl:apply-templates />
    </rdf:RDF>
  </xsl:template>
  
  <xsl:template match="head">
    <rdf:Description rdf:about="">
      <xsl:if test="title">
        <so:title><xsl:value-of select="title" /></so:title>
      </xsl:if>
      <xsl:if test="dateCreated">
        <so:dateCreated><xsl:value-of select="dateCreated" /></so:dateCreated>
      </xsl:if>
    </rdf:Description>
  </xsl:template>
  
  <xsl:template match="body">
    <so:Document rdf:about="">
      <xsl:apply-templates select="outline" mode="childnode" />
    </so:Document>
    <xsl:apply-templates select="outline" mode="descriptor" />
  </xsl:template>

  <xsl:template match="outline" mode="descriptor">
    <xsl:param name="nodeid">
      <xsl:value-of select="generate-id(current())"/>
    </xsl:param>
    <so:Node rdf:about="#{$nodeid}">
      <xsl:if test="@title">
        <so:title>
          <xsl:value-of select="@title"/>
        </so:title>
      </xsl:if>
      <xsl:if test="@text">
        <so:text>
          <xsl:value-of select="@text"/>
        </so:text>
      </xsl:if>
      <xsl:if test="@isComment">
        <so:isComment>
          <xsl:value-of select="@isComment"/>
        </so:isComment>
      </xsl:if>
      <xsl:if test="@isBreakpoint">
        <so:isBreakpoint>
          <xsl:value-of select="@isBreakpoint"/>
        </so:isBreakpoint>
      </xsl:if>
      <xsl:if test="@type">
        <so:type><xsl:value-of select="@type" /></so:type>
      </xsl:if>
      <xsl:if test="@type = 'include'">
        <xsl:if test="@url">
          <rdfs:seeAlso rdf:resource="http://rdf.opiumfield.com/so/{@url}" />
        </xsl:if>
      </xsl:if>
      <xsl:if test="@htmlUrl">
        <so:htmlUrl rdf:resource="{@htmlUrl}" />
      </xsl:if>
      <xsl:if test="@xmlUrl">
        <so:xmlUrl rdf:resource="{@xmlUrl}" />
      </xsl:if>
      <xsl:if test="@category">
        <so:category><xsl:value-of select="@category" /></so:category>
      </xsl:if>
      <xsl:if test="@version">
        <so:version><xsl:value-of select="@version" /></so:version>
      </xsl:if>
      <xsl:if test="@url">
        <so:url rdf:resource="{@url}" />
      </xsl:if>
      <xsl:apply-templates select="outline" mode="childnode" />
    </so:Node>
    <xsl:apply-templates select="outline" mode="descriptor" />
  </xsl:template>
  <xsl:template match="outline" mode="childnode">
    <so:hasChild rdf:resource="#{generate-id(current())}" />
  </xsl:template>
</xsl:stylesheet>