<?xml version="1.0" encoding="UTF-8" ?>

<!--
   Name:NonISOKeywords.xsl   
   Author:  Matthew J. McCready
   Date:  20110611
   Description:  XSLT stylesheet that transforms the value in the keywords/theme and keywords/place
  to the gmd:descriptiveKeywords element.
   Modification History:
      Initial   Date      Change Request ID   Description

-->

<xsl:stylesheet version = "1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:gmd="http://www.isotc211.org/2005/gmd"
   xmlns:gco="http://www.isotc211.org/2005/gco" 
>
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>
<xsl:variable name ="MetDate"   select= "//metadata/metainfo/metd"/>
<!-- <xsl:variable name="SDTSPntVot" select="//metadata/spdoinfo/ptvctinf/sdtsterm/sdtstype"/> -->

<xsl:template name="NonISOKeywords">
	<xsl:call-template name="NonThemeISOKeywords"/>
        <xsl:call-template name="PlaceKeywords"/>
</xsl:template>

<xsl:template name="NonThemeISOKeywords">
<xsl:variable name="CodeListLoc">http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_KeywordTypeCode</xsl:variable>
<xsl:variable name="NonISOKeywordsTheme" select="//metadata/idinfo/keywords/theme/themekt"/>

<xsl:for-each select="//metadata/idinfo/keywords/theme">
<xsl:variable name="NonISOKeywordsThemeA" select="./themekt"/>

<!--
<xsl:comment> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx </xsl:comment>
<xsl:value-of select=" $NonISOKeywordsThemeA"/>
<xsl:comment> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx </xsl:comment>
-->

<xsl:if test="$NonISOKeywordsThemeA !='ISO 19115 Topic Categories'">
<xsl:element name="gmd:descriptiveKeywords">
<xsl:element name="gmd:MD_Keywords">
<!-- <xsl:for-each select="//metadata/idinfo/keywords/theme"> -->
<xsl:for-each select="//metadata/idinfo/keywords/theme/themekey"> 
<!-- <xsl:element name="gmd:keyword"> -->
<xsl:variable name="ThemeKey" select="."/> <!-- else try the full path  -->

 
<xsl:if test="$ThemeKey !='farming'">
<xsl:if test="$ThemeKey !='biota'">
<xsl:if test="$ThemeKey !='boundaries'"> 
<xsl:if test="$ThemeKey !='transportation' "> 
<xsl:if test="$ThemeKey !='climatologyMeteorologyAtmosphere' ">
<xsl:if test="$ThemeKey !='economy' ">
<xsl:if test="$ThemeKey !='elevation'">
<xsl:if test="$ThemeKey !='environment'">
<xsl:if test="$ThemeKey !='geoscientificInformation'">
<xsl:if test="$ThemeKey !='health'">
<xsl:if test="$ThemeKey !='imageryBaseMapsEarthCover'">
<xsl:if test="$ThemeKey !='intelligenceMilitary'">
<xsl:if test="$ThemeKey !='inlandWaters'">
<xsl:if test="$ThemeKey !='location'">
<xsl:if test="$ThemeKey !='oceans'">
<xsl:if test="$ThemeKey !='planningCadastre'">
<xsl:if test="$ThemeKey !='society'">
<xsl:if test="$ThemeKey !='structure'">
<!-- <xsl:if test="$ThemeKey !='boundaries' or $ThemeKey !='transportation' "> -->
<xsl:element name="gmd:keyword">
<xsl:element name="gco:CharacterString"><xsl:value-of select="."/>   </xsl:element> <!-- gco:CharacterString   ($ThemeKey !='utilitiesCommunication')-->
</xsl:element> <!-- gmd:keyword -->
</xsl:if><!-- structure -->
</xsl:if><!-- society -->
</xsl:if><!-- planningCadastre -->
</xsl:if><!-- oceans -->
</xsl:if><!-- location -->
</xsl:if><!-- inlandWaters -->
</xsl:if><!-- intelligenceMilitary --> 
</xsl:if><!-- imageryBaseMapsEarthCover -->
</xsl:if><!-- health -->
</xsl:if><!-- geoscientificInformation -->
</xsl:if><!-- environment -->
</xsl:if><!-- elevation -->
</xsl:if><!-- economy -->
</xsl:if><!-- climatologyMeteorologyAtmosphere -->
</xsl:if><!-- transportation -->
</xsl:if><!-- boundaries -->
</xsl:if><!-- biota --> 
</xsl:if><!-- farming -->

<!-- 
($ThemeKey !='structure)' ">
<xsl:element name="gco:CharacterString
-->
<!-- </xsl:element> --> <!-- gmd:keyword -->
</xsl:for-each>

<xsl:element name="gmd:type">
<xsl:element name="gmd:MD_KeywordTypeCode">
<xsl:attribute name="codeList">http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_KeywordTypeCode</xsl:attribute>
<xsl:attribute name="codeListValue">theme</xsl:attribute>
<xsl:attribute name="codeSpace">005</xsl:attribute>
theme
</xsl:element><!-- gmd:MD_KeywordTypeCod -->
</xsl:element><!-- gmd:type -->

<xsl:element name="gmd:thesaurusName">
<xsl:element name="gmd:CI_Citation">
<xsl:element name="gmd:title">
<xsl:element name="gco:CharacterString"><xsl:value-of select="$NonISOKeywordsThemeA"/></xsl:element><!-- gco:CharacterString -->
</xsl:element><!-- gmd:title -->
</xsl:element><!-- gmd:CI_Citation -->
</xsl:element><!-- gmd:thesaurusName -->

</xsl:element><!-- gmd:MD_Keywords -->
</xsl:element><!-- gmd:descriptiveKeywords -->
</xsl:if> 
</xsl:for-each> 
</xsl:template>

<xsl:template name="PlaceKeywords">
<xsl:for-each select="//metadata/idinfo/keywords/place">
<xsl:variable name="PlaceThes" select="./placekt"/> 
<xsl:element name="gmd:descriptiveKeywords">
<xsl:element name="gmd:MD_Keywords">
<xsl:for-each select="//metadata/idinfo/keywords/place/placekey">

<xsl:element name="gmd:keyword">
<xsl:element name="gco:CharacterString"><xsl:value-of select="."/>   </xsl:element> <!-- gco:CharacterString   ($ThemeKey !='utilitiesCommunication')-->
</xsl:element> <!-- gmd:keyword -->

</xsl:for-each>
</xsl:element><!-- gmd:MD_Keywords -->
</xsl:element><!-- gmd:descriptiveKeywords -->

<xsl:element name="gmd:type">
<xsl:element name="gmd:MD_KeywordTypeCode">
<xsl:attribute name="codeList">http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_KeywordTypeCode</xsl:attribute>
<xsl:attribute name="codeListValue">place</xsl:attribute>
<xsl:attribute name="codeSpace">002</xsl:attribute>
place
</xsl:element><!-- gmd:MD_KeywordTypeCod -->
</xsl:element><!-- gmd:type -->

<xsl:element name="gmd:thesaurusName">
<xsl:element name="gmd:CI_Citation">
<xsl:element name="gmd:title">
<xsl:element name="gco:CharacterString"><xsl:value-of select="$PlaceThes"/></xsl:element><!-- gco:CharacterString -->
</xsl:element><!-- gmd:title -->
</xsl:element><!-- gmd:CI_Citation -->
</xsl:element><!-- gmd:thesaurusName -->
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
