<?xml version="1.0" encoding="UTF-8" ?>
<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:element name="Edition">
   <xsl:attribute name="section">citation</xsl:attribute>
   <xsl:apply-templates select="//idinfo/citation/citeinfo/edition"/> <!-- FGDC path -->
   </xsl:element>
   
    <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: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: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: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/onlink"/> <!-- FGDC path -->
   </xsl:element>
   
   <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:element>
   
  <!-- these ones will need some thinking -->
   <xsl:element name="Survey_Instance_Name">
  <xsl:value-of select ="substring(//idinfo/citation/citeinfo/title,1,36)"/>
   </xsl:element>
   
   <!-- these ones will need some thinking -->
   <xsl:element name="Survey_Name">
   <xsl:value-of select ="substring(//idinfo/citation/citeinfo/title,1,16)"/>
   </xsl:element>
   
   <xsl:element name="Supplemental_Information">
   <xsl:apply-templates select="//idinfo/title"/> <!-- FGDC path -->
   </xsl:element>
   
  <!--  <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">
   <xsl:if test="themekt ='FGDC Framework Themes'">
   
   <xsl:element name="Theme_Keyword_Thesaurus">
   <xsl:attribute name="gid1">1</xsl:attribute>
   <!-- <xsl:apply-templates select="." /> -->
   <xsl:apply-templates select="themekt"/> 
   </xsl:element>
   
   <xsl:for-each select="themekey">
   <xsl:element name="Theme_Keywords">
   <xsl:attribute name="gid1">1</xsl:attribute>
   <xsl:value-of select="."/>
    <!-- <xsl:apply-templates select="//idinfo/keywords/theme/themekey"/> -->
   </xsl:element>
   </xsl:for-each>
   
   </xsl:if>
   
   
   <!-- ISO 19115 Topic Categories -->
   <xsl:if test="themekt ='ISO 19115 Topic Categories'">
   
   
   <xsl:element name="Theme_Keyword_Thesaurus">
   <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_Keywords">
   <xsl:attribute name="gid1">2</xsl:attribute>
   <xsl:value-of select="."/>
  <!-- <xsl:apply-templates select="themekey"/>  -->
   </xsl:element>
   </xsl:for-each>
   
   </xsl:if>
   
   <!-- None -->
   <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:apply-templates select="//idinfo/keywords/theme/themekey"/>  -->
   </xsl:element>
   </xsl:for-each>
   
   </xsl:if>
   </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">no</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>  
 
 
 
 
 
