<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:doc="http://www.w3.org/2000/10/swap/pim/doc#"
    xmlns:rec="http://www.w3.org/2001/02pd/rec54#"
    xmlns:contact="http://www.w3.org/2000/10/swap/pim/contact#"
    xmlns:skos="http://www.w3.org/2004/02/skos/core#"
    xmlns:glos="http://www.w3.org/2003/03/glossary-project/schema#"
    xmlns:str="http://www.w3.org/2001/10/str-util.xsl"
    exclude-result-prefixes="str"
    version="1.0">
  <xsl:import href="glossary-util.xsl"/>
  <xsl:import href="http://www.w3.org/2001/10/str-util.xsl"/>
  <xsl:output method="xml" media-type="text/xml" encoding="ISO-8859-1" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template name="createSchema">
    <xsl:param name="about"/>
    <rdf:RDF  xmlns="http://www.w3.org/1999/xhtml">
      <rdf:Description rdf:about="">
        <dc:rights xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:resource="http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231" />
      </rdf:Description>

      <rdf:Description rdf:about="{$about}">
        <xsl:call-template name="addDocumentData"/>
      </rdf:Description>
      <xsl:call-template name="addGlossaryData"/>
    </rdf:RDF>
  </xsl:template>

  <xsl:template name="addDocumentData"/>

  <xsl:template name="addGlossaryData"/>

  <xsl:template name="addDate">
    <xsl:param name="date"/>
    <dc:date><xsl:value-of select="concat(substring($date,1,4),'-',substring($date,5,2),'-',substring($date,7,2))"/></dc:date>
  </xsl:template>

  <xsl:template name="addTitle">
    <xsl:param name="title"/>
    <dc:title><xsl:value-of select="$title"/></dc:title>
  </xsl:template>

  <xsl:template name="addVersion">
    <xsl:param name="version"/>
    <doc:version><xsl:value-of select="$version"/></doc:version>
  </xsl:template>

  <xsl:template name="addEditor">
    <xsl:param name="full_name"/>
    <xsl:param name="mail"/>
    <xsl:variable name="given_name">
      <xsl:call-template name="str:keep-before-last">
        <xsl:with-param name="string" select="$full_name"/>
        <xsl:with-param name="delimiter" select="' '"/>
      </xsl:call-template>
    </xsl:variable>
    <rec:editor rdf:parseType="Resource">
      <xsl:if test="normalize-space($mail)">
        <contact:mailbox rdf:resource="{$mail}"/>
      </xsl:if>
      <contact:lastName><xsl:value-of select="normalize-space(substring-after($full_name,$given_name))"/></contact:lastName>
      <contact:firstName><xsl:value-of select="$given_name"/></contact:firstName>
    </rec:editor>
  </xsl:template>

  <xsl:template name="addTermEntry">
    <xsl:param name="term"/>
    <xsl:param name="definition"/>
    <xsl:param name="example"/>
    <xsl:param name="about"/>
    <xsl:param name="isDefinedBy"/>
    <xsl:variable name="tmp">
      <xsl:call-template name="removeForbiddenChars">
        <xsl:with-param name="str" select="$term"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="idref">
      <xsl:call-template name="computeTermID">
        <xsl:with-param name="str" select="normalize-space($tmp)"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="formatted_term">
      <xsl:call-template name="formatTerm">
        <xsl:with-param name="str" select="$term"/>
      </xsl:call-template>
    </xsl:variable>
    <skos:Concept rdf:about="{concat($about,$idref)}">
      <skos:prefLabel xml:lang="en"><xsl:value-of select="$formatted_term"/></skos:prefLabel>
      <skos:definition xml:lang="en" rdf:parseType='Literal'><xsl:copy-of select="$definition"/></skos:definition>
      <xsl:if test="normalize-space($example)">
        <skos:example xml:lang="en" rdf:parseType='Literal'><xsl:copy-of select="$example"/></skos:example>
      </xsl:if>
      <rdfs:isDefinedBy rdf:resource="{$isDefinedBy}"/>
    </skos:Concept>
  </xsl:template>

</xsl:stylesheet>