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

<!--
   Name:  01_idinfo.xsl
   Author:  Matthew J. McCready
   Date:  20070115
   Description:  XSLT stylesheet that transforms Section 1 of an
                 FGDC format file into a mif file
   Modification History:
      Initial   Date      Change Request ID   Description
      MMC       20070115   N/A                Initial Version
      MMC       20070415   N/A                Modified so that the Supplemental_Information 
                                               would have the correct XPath. Also made the
                                               element optional.
      MMC       20070500   N/A                Modified so that Edition, Series_Name and 
                                               Issue_Identification elements are all optional.
      MMC       20070500   N/A                Corrected the xpath for the Supplemental_Information element
      MMC       20070500   N/A                Modified so that  the  Other_Citation_Details element appears.
      MMC       20070800   N/A                Eliminated the hardcoding of ISO Keywords
      MMC       20071203   N/A                Modified so that blank keywords in the input FGDC come through 
                                               so that they can be flagged as invalid
      MMC       20110103   N/A                Modified so that all Theme_Keyword_Thesaurus with the value of
                                               'ISO 19115 Topic Categories' will be placed in the 'Theme_Keyword_Thesaurus_ISO'
                                               element. This was done so that the ISO theme Keywords could be checked. 
      MMC       20110103   N/A                Modified so that any keyword thesaurus can be included in the MIF file. This was 
                                               done through the use of a choice structure. 
-->

<xsl:stylesheet version = "1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>

<xsl:template name="idinfo" match="/">

<xsl:if test="//idinfo" >
   <!-- Entity_and_Attribute_Information PARENT ELEMENT -->
  
   <xsl:element name="Originator"> <!-- mif name -->
   <!-- section="citation" gid1="1" -->
   <xsl:attribute name ="section">citation</xsl:attribute>  <!-- mif attribute -->
   <xsl:attribute name ="gid1">1</xsl:attribute> <!-- mif attribute -->
   <xsl:apply-templates select="//idinfo/citation/citeinfo/origin"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Publication_Date">
   <xsl:attribute name="section">citation</xsl:attribute>
   <xsl:apply-templates select="//idinfo/citation/citeinfo/pubdate"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Title">
   <xsl:attribute name="section">citation</xsl:attribute>
   <xsl:apply-templates select="//idinfo/citation/citeinfo/title"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:if test="//idinfo/citation/citeinfo/edition">
   <xsl:element name="Edition">
   <xsl:attribute name="section">citation</xsl:attribute>
   <xsl:apply-templates select="//idinfo/citation/citeinfo/edition"/> <!-- FGDC path -->
   </xsl:element>
   </xsl:if>

    <xsl:element name="Geospatial_Data_Presentation_Form">
    <xsl:attribute name="section">citation</xsl:attribute>
    <xsl:apply-templates select="//idinfo/citation/citeinfo/geoform"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:if test="//idinfo/citation/citeinfo/serinfo/sername">
   <xsl:element name="Series_Name">
   <xsl:attribute name="section">citation</xsl:attribute>
    <xsl:apply-templates select="//idinfo/citation/citeinfo/serinfo/sername"/> <!-- FGDC path -->
   </xsl:element>
   </xsl:if>
   
    <xsl:if test="//idinfo/citation/citeinfo/serinfo/issue">
   <xsl:element name="Issue_Identification">
   <xsl:attribute name="section">citation</xsl:attribute>
    <xsl:apply-templates select="//idinfo/citation/citeinfo/serinfo/issue"/> <!-- FGDC path -->
   </xsl:element>
   </xsl:if>
  
    <xsl:if test="//idinfo/citation/citeinfo/othercit">	
    <xsl:element name="Other_Citation_Details">
   <xsl:attribute name="section">citation</xsl:attribute>
    <xsl:apply-templates select="//idinfo/citation/citeinfo/othercit"/> <!-- FGDC path -->
   </xsl:element>
   </xsl:if>
 
   <!--  <xsl:if test="//idinfo/citeinfo/onlink"> -->
   <xsl:element name="Online_Linkage">
   <xsl:attribute name ="section">citation</xsl:attribute>  <!-- mif attribute -->
   <xsl:attribute name ="gid1">1</xsl:attribute> <!-- mif attribute -->
   <xsl:apply-templates select="//idinfo/citation/citeinfo/onlink"/> <!-- FGDC path -->
   </xsl:element>
   <!-- </xsl:if> -->
   
   <xsl:element name="Abstract">
   <xsl:apply-templates select="//idinfo/descript/abstract"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Purpose">
   <xsl:apply-templates select="//idinfo/descript/purpose"/> <!-- FGDC path -->
   </xsl:element>
   
   <!-- these ones will need some thinking -->
   <xsl:element name="Subject_Entity">
  <!--  <xsl:value-of select ="substring(//idinfo/citation/citeinfo/title,39)"/> -->
  
   <xsl:choose>
   
    <xsl:when test="//idinfo/descript/Subject_Entity"> 
   <xsl:apply-templates select="//idinfo/descript/Subject_Entity"/>
   </xsl:when>
   
    <xsl:when test="//idinfo/descript/subject_entity">
    <xsl:apply-templates select="//idinfo/descript/subject_entity"/>
   </xsl:when>
   <xsl:otherwise></xsl:otherwise>
   </xsl:choose>

   </xsl:element>
   
  <!-- these ones will need some thinking -->
  <xsl:if test="//idinfo/descript/Survey_Instance_Name">
   <xsl:element name="Survey_Instance_Name">
 <!--  <xsl:value-of select ="substring(//idinfo/citation/citeinfo/title,1,36)"/> -->
    <xsl:apply-templates select="//idinfo/descript/Survey_Instance_Name"/>
   </xsl:element>
</xsl:if>
   
   <!-- these ones will need some thinking -->
 <xsl:if test="//idinfo/descript/Survey_Name">
   <xsl:element name="Survey_Name">
 <xsl:apply-templates select="//idinfo/descript/Survey_Name"/>
   <!-- <xsl:value-of select ="substring(//idinfo/citation/citeinfo/title,1,16)"/> -->
   </xsl:element>
   </xsl:if>

  <xsl:if test="//idinfo/descript/supplinf">
   <xsl:element name="Supplemental_Information">
   <xsl:apply-templates select="//idinfo/descript/supplinf"/> <!-- FGDC path -->
   </xsl:element>
  </xsl:if> 
  <!--  <timeperd>
<timeinfo> -->
   
    <xsl:element name="Beginning_Date">
   <xsl:attribute name="section">time period of content</xsl:attribute>
    <xsl:apply-templates select="//idinfo/timeperd/timeinfo/rngdates/begdate"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Ending_Date">
   <xsl:attribute name="section">time period of content</xsl:attribute>
    <xsl:apply-templates select="//idinfo/timeperd/timeinfo/rngdates/enddate"/> <!-- FGDC path -->
   </xsl:element>
   
    <xsl:element name="Currentness_Reference">
   <xsl:apply-templates select="//idinfo/timeperd/current"/> <!-- FGDC path -->
   </xsl:element>
   
  <xsl:element name="Progress">
   <xsl:apply-templates select="//idinfo/status/progress"/> <!-- FGDC path -->
   </xsl:element> 
   
   <xsl:element name="Maintenance_and_Update_Frequency">
   <xsl:apply-templates select="//idinfo/status/update"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="West_Bounding_Coordinate">
   <xsl:apply-templates select="//idinfo/spdom/bounding/westbc"/> <!-- FGDC path -->
   </xsl:element>
   
  <xsl:element name="East_Bounding_Coordinate">
   <xsl:apply-templates select="//idinfo/spdom/bounding/eastbc"/> <!-- FGDC path -->
   </xsl:element> 
   
   <xsl:element name="North_Bounding_Coordinate">
   <xsl:apply-templates select="//idinfo/spdom/bounding/northbc"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="South_Bounding_Coordinate">
   <xsl:apply-templates select="//idinfo/spdom/bounding/southbc"/> <!-- FGDC path -->
   </xsl:element>
   
   <!-- FGDC Frameworks condition area stares here -->
   
   <!-- /themekt -->
   <xsl:for-each select="//idinfo/keywords/theme">
   
   
   <!-- ISO 19115 Topic Categories -->
<!-- 
   <xsl:if test="themekt ='ISO 19115 Topic Categories'">
   
  
 
   <xsl:element name="Theme_Keyword_Thesaurus_ISO">
   <xsl:attribute name="gid1">2</xsl:attribute>
    <xsl:apply-templates select="themekt"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:for-each select="themekey">
   <xsl:element name="Theme_Keyword">
   <xsl:attribute name="gid1">2</xsl:attribute>
   <xsl:value-of select="."/>
  
   </xsl:element>
   </xsl:for-each>
   
   </xsl:if>
   
   <xsl:if test="themekt ='None'">
   
   <xsl:element name="Theme_Keyword_Thesaurus">
   <xsl:attribute name="gid1">3</xsl:attribute>
    <xsl:apply-templates select="themekt"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:for-each select="themekey">
   <xsl:element name="Theme_Keyword">
   <xsl:attribute name="gid1">3</xsl:attribute>
   <xsl:value-of select="."/>
   </xsl:element>
   </xsl:for-each>
   
   </xsl:if>

    <xsl:if test="themekt =''">

   <xsl:element name="Theme_Keyword_Thesaurus">
   <xsl:attribute name="gid1">3</xsl:attribute>
    <xsl:apply-templates select="themekt"/> <!-- FGDC path -->
   </xsl:element>

   <xsl:for-each select="themekey">
   <xsl:element name="Theme_Keyword">
   <xsl:attribute name="gid1">3</xsl:attribute>
   <xsl:value-of select="."/>
   </xsl:element>
   </xsl:for-each>

   </xsl:if>
-->
<xsl:choose>

<xsl:when test="themekt ='ISO 19115 Topic Categories'">
  
   <xsl:element name="Theme_Keyword_Thesaurus_ISO">
   <xsl:attribute name="gid1">2</xsl:attribute>
    <xsl:apply-templates select="themekt"/> <!-- FGDC path -->
   </xsl:element>
    
   <xsl:for-each select="themekey">
   <xsl:element name="Theme_Keyword">
   <xsl:attribute name="gid1">2</xsl:attribute>
   <xsl:value-of select="."/>
   
   </xsl:element>
   </xsl:for-each>
</xsl:when>

<xsl:when test="themekt ='None'">
    
   <xsl:element name="Theme_Keyword_Thesaurus">
   <xsl:attribute name="gid1">3</xsl:attribute>
    <xsl:apply-templates select="themekt"/> <!-- FGDC path -->
   </xsl:element>
    
   <xsl:for-each select="themekey">
   <xsl:element name="Theme_Keyword">
   <xsl:attribute name="gid1">3</xsl:attribute>
   <xsl:value-of select="."/>
   </xsl:element>
   </xsl:for-each>
</xsl:when>

<xsl:when testtest="themekt =''">

   <xsl:element name="Theme_Keyword_Thesaurus">
   <xsl:attribute name="gid1">4</xsl:attribute>
    <xsl:apply-templates select="themekt"/> <!-- FGDC path -->
   </xsl:element>

   <xsl:for-each select="themekey">
   <xsl:element name="Theme_Keyword">
   <xsl:attribute name="gid1">4</xsl:attribute>
   <xsl:value-of select="."/>
   </xsl:element>
   </xsl:for-each>
</xsl:when>

<xsl:otherwise>
 <xsl:element name="Theme_Keyword_Thesaurus">
   <xsl:attribute name="gid1">5</xsl:attribute>
    <xsl:apply-templates select="themekt"/> <!-- FGDC path -->
   </xsl:element>

   <xsl:for-each select="themekey">
   <xsl:element name="Theme_Keyword">
   <xsl:attribute name="gid1">5</xsl:attribute>
   <xsl:value-of select="."/>
   </xsl:element>
   </xsl:for-each


</xsl:otherwise>



</xsl:choose>

   </xsl:for-each>
   
   <xsl:element name="Place_Keyword_Thesaurus">
   <xsl:attribute name="gid1">1</xsl:attribute>
    <xsl:apply-templates select="//idinfo/keywords/place/placekt"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:for-each select="//idinfo/keywords/place/placekey">
   <xsl:element name="Place_Keyword">
   <xsl:attribute name="gid1">1</xsl:attribute>
   <xsl:attribute name="gid2">1</xsl:attribute>
   <xsl:value-of select="."/>
 <!--  <xsl:apply-templates select="//idinfo/keywords/place/placekey"/>  -->
   </xsl:element>
   </xsl:for-each>
   
   <xsl:element name="Access_Constraints">
   <xsl:apply-templates select="//idinfo/accconst"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Use_Constraints">
   <xsl:apply-templates select="//idinfo/useconst"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Title_13_Restrictions">
   <xsl:apply-templates select="//idinfo/Title_13_Restrictions"/>
   </xsl:element>
   
   <xsl:element name="Contact_Organization">
   <xsl:attribute name="section">point of contact</xsl:attribute>
    <xsl:apply-templates select="//idinfo/ptcontac/cntinfo/cntorgp/cntorg"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Address_Type">
   <xsl:attribute name="section">point of contact</xsl:attribute>mailing</xsl:element>
   
    <xsl:element name="Address">
   <xsl:attribute name="section">point of contact</xsl:attribute>
    <xsl:apply-templates select="//idinfo/ptcontac/cntinfo/cntaddr/address"/> <!-- FGDC path -->
   </xsl:element>
   
  <xsl:element name="City">
   <xsl:attribute name="section">point of contact</xsl:attribute>
    <xsl:apply-templates select="//idinfo/ptcontac/cntinfo/cntaddr/city"/> <!-- FGDC path -->
   </xsl:element> 
   
<xsl:element name="State_or_Province">
   <xsl:attribute name="section">point of contact</xsl:attribute>
    <xsl:apply-templates select="//idinfo/ptcontac/cntinfo/cntaddr/state"/> <!-- FGDC path -->
   </xsl:element>   
   
  <xsl:element name="Postal_Code">
   <xsl:attribute name="section">point of contact</xsl:attribute>
    <xsl:apply-templates select="//idinfo/ptcontac/cntinfo/cntaddr/postal"/> <!-- FGDC path -->
   </xsl:element>  
   
   <xsl:element name="Country">
   <xsl:attribute name="section">point of contact</xsl:attribute>
    <xsl:apply-templates select="//idinfo/ptcontac/cntinfo/cntaddr/country"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Contact_Voice_Telephone">
   <xsl:attribute name="section">point of contact</xsl:attribute>
    <xsl:apply-templates select="//idinfo/ptcontac/cntinfo/cntvoice"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Contact_Facsimile_Telephone">
   <xsl:attribute name="section">point of contact</xsl:attribute>
    <xsl:apply-templates select="//idinfo/ptcontac/cntinfo/cntfax"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Contact_Electronic_Mail_Address">
   <xsl:attribute name="section">point of contact</xsl:attribute>
    <xsl:apply-templates select="//idinfo/ptcontac/cntinfo/cntemail"/> <!-- FGDC path -->
   </xsl:element>
   
   
    <xsl:if test="//idinfo/browse/browsen">
   <xsl:element name="Browse_Graphic_File_Name">
    <xsl:attribute name="gid1">1</xsl:attribute>
    <xsl:apply-templates select="//idinfo/browse/browsen"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Browse_Graphic_File_Description">
   <xsl:attribute name="gid1">1</xsl:attribute>
    <xsl:apply-templates select="//idinfo/browse/browsed"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Browse_Graphic_File_Type">
   <xsl:attribute name="gid1">1</xsl:attribute>
    <xsl:apply-templates select="//idinfo/browse/browset"/> <!-- FGDC path -->
   </xsl:element>
   
   </xsl:if>
   
   <xsl:element name="Data_Set_Character_Set">8859part1</xsl:element>
   
  <xsl:element name="Data_Set_Language">eng</xsl:element>  
   
   <xsl:if test="//idinfo/native">
   <xsl:element name="Native_Data_Set_Enviornment">
    <xsl:apply-templates select="//idinfo/browse/browsen"/> <!-- FGDC path -->
   </xsl:element>
   </xsl:if>
   
   <xsl:if test="//idinfo/crossref">
   <xsl:element name="Originator">
   <xsl:attribute name="section">cross reference</xsl:attribute>
   <xsl:attribute name="gid1">1</xsl:attribute>
   <xsl:attribute name="gid2">1</xsl:attribute>
    <xsl:apply-templates select="//idinfo/crossref/citeinfo/origin"/> <!-- FGDC path -->
   </xsl:element>
   
   <xsl:element name="Publication_Date">
   <xsl:attribute name="section">cross reference</xsl:attribute>
   <xsl:attribute name="gid1">1</xsl:attribute>
   <xsl:attribute name="gid2">1</xsl:attribute>
    <xsl:apply-templates select="//idinfo/crossref/citeinfo/pubdate"/> <!-- FGDC path -->
   </xsl:element>  
   
   <xsl:element name="Title">
   <xsl:attribute name="section">cross reference</xsl:attribute>
   <xsl:attribute name="gid1">1</xsl:attribute>
   <xsl:attribute name="gid2">1</xsl:attribute>
    <xsl:apply-templates select="//idinfo/crossref/citeinfo/title"/> <!-- FGDC path -->
   </xsl:element>   
   
   <xsl:if test="//idinfo/crossref/citeinfo/onlink">
   
   <xsl:element name="Online_Linkage">
   <xsl:attribute name="section">cross reference</xsl:attribute>
   <xsl:attribute name="gid1">1</xsl:attribute>
   <xsl:attribute name="gid2">1</xsl:attribute>
    <xsl:apply-templates select="//idinfo/crossref/citeinfo/onlink"/> <!-- FGDC path -->
   </xsl:element>
   
   </xsl:if>
   </xsl:if>
   </xsl:if>
   
 </xsl:template>
 </xsl:stylesheet>  
 
 
 
 
 
<!-- Stylus Studio meta-information - (c) 2004-2005. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios/><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition></MapperMetaTag>
</metaInformation>
-->
