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

<!--
   Name: 01_Identification_Information.xsl 
   Author:  Matthew J. McCready
   Date:  20070115
   Description:  XSLT stylesheet that transforms Section 1 of an
                 MRF format file into a FGDC posting file
   Modification History:
      Initial   Date      Change Request ID   Description
      MMC       20110103        N/A           Modified the keywords section so that the Theme_Keyword_Thesaurus_ISO
                                               and Theme_ISO elements in the MRF file will transform into the 
                                               Theme_Keyword_Thesaurus and Theme elements respectively. This was done
                                               so that the ISO theme keywords could be verified  
      MMC       20110302        N/A           Modifed the keywords section so that the Place_INCITS and Place_INCITSB 
                                               elements in the MRF file will transform into the Place element. This was
                                               done so that more than 1 place element could exist with the all option in
                                               the schema
-->
<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="Identification_Information" match="/">

      <!-- Identification_Information PARENT ELEMENT -->
      <xsl:element name="idinfo">

         <!-- Citation PARENT ELEMENT -->
         <xsl:element name="citation">

            <!-- FGDC PARENT ELEMENT -->
            <xsl:element name="citeinfo">

               <!-- Originator:R REPEATING DATA -->
               <xsl:for-each select="//Identification_Information/Citation/Originator">
                  <xsl:element name="origin">
                     <xsl:value-of select="." />
                  </xsl:element>
               </xsl:for-each>

               <!-- Publication_Date: DATA -->
               <xsl:element name="pubdate">
                  <xsl:apply-templates select="//Identification_Information/Citation/Publication_Date" />
               </xsl:element>

               <!-- Title: DATA -->
               <xsl:element name="title">
                  <xsl:apply-templates select="//Identification_Information/Citation/Title" />
               </xsl:element>


               <!-- Edition: DATA -->
               <xsl:if test="//Identification_Information/Citation/Edition">
                  <xsl:element name="edition">
                     <xsl:apply-templates select="//Identification_Information/Citation/Edition" />
                  </xsl:element>
               </xsl:if>

               <!-- Geospatial_Data_Presentation_Form: DATA -->
               <xsl:if test="//Identification_Information/Citation/Geospatial_Data_Presentation_Form" >
                  <xsl:element name="geoform">
                     <xsl:apply-templates select="//Identification_Information/Citation/Geospatial_Data_Presentation_Form" />
                  </xsl:element>
               </xsl:if>


               <!-- Series_Information PARENT ELEMENT -->
               <xsl:if test="//Identification_Information/Citation/Series_Information/Series_Name" >
                  <xsl:element name="serinfo">
                     <!-- Series_name: DATA -->
                     <xsl:element name="sername">
                        <xsl:apply-templates select="//Identification_Information/Citation/Series_Information/Series_Name" />
                     </xsl:element>
                     <!-- Issue_Identification: DATA -->
                     <xsl:element name="issue">
                        <xsl:apply-templates select="//Identification_Information/Citation/Series_Information/Issue_Identification" />
                     </xsl:element>
                  </xsl:element>
               </xsl:if>

               <!-- Other_Citation_Details: DATA -->
               <xsl:if test="//Identification_Information/Citation/Other_Citation_Details">
                  <xsl:element name="othercit">
                     <xsl:apply-templates select="//Identification_Information/Citation/Other_Citation_Details" />
                  </xsl:element>
               </xsl:if>

               <!-- Online_Linkage:R REPEATING DATA -->
               <xsl:for-each select="//Identification_Information/Citation/Online_Linkage">
                  <xsl:element name="onlink">
                     <xsl:value-of select="."/>
                  </xsl:element>
               </xsl:for-each>

            <!-- CLOSE CITE INFO -->
            </xsl:element>
         <!-- CLOSE CITATION -->
         </xsl:element>

         <!-- Description PARENT ELEMENT -->
         <xsl:element name="descript">
            <!-- Abstract: DATA -->
            <xsl:element name="abstract">
               <xsl:apply-templates select="//Identification_Information/Description/Abstract" />
            </xsl:element>
            <!-- Purpose: DATA -->
            <xsl:element name="purpose">
               <xsl:apply-templates select="//Identification_Information/Description/Purpose" />
            </xsl:element>

            <!-- Subject_Entity IS MRF ONLY -->
            <!-- Survey_Instance_Name IS MRF ONLY -->
            <!-- Survey_Name IS MRF ONLY -->

            <!-- Supplemental_Information: DATA -->
            <xsl:if test="//Identification_Information/Description/Supplemental_Information" >
               <xsl:element name="supplinf">
                  <xsl:apply-templates select="//Identification_Information/Description/Supplemental_Information" />
               </xsl:element>
            </xsl:if>

         </xsl:element>

         <!-- Time_Period_of_Content PARENT ELEMENT -->
         <xsl:element name="timeperd">
            <!-- FGDC PARENT ELEMENT -->
            <xsl:element name="timeinfo">
               <!-- FGDC PARENT ELEMENT -->
               <xsl:element name="rngdates">
                  <!-- Beginning_Date: DATA -->
                  <xsl:element name="begdate">
                     <xsl:apply-templates select="//Identification_Information/Time_Period_of_Content/Beginning_Date" />
                  </xsl:element>
                  <!-- Ending_Date: DATA -->
                  <xsl:element name="enddate">
                     <xsl:apply-templates select="//Identification_Information/Time_Period_of_Content/Ending_Date" />
                  </xsl:element>
               </xsl:element>
            </xsl:element>

            <!-- Currentness_Reference: DATA -->
            <xsl:element name="current">
               <xsl:apply-templates select="//Identification_Information/Time_Period_of_Content/Currentness_Reference" />
            </xsl:element>
         </xsl:element>

         <!-- Status PARENT ELEMENT -->
         <xsl:element name="status">
            <!-- Progress: DATA -->
            <xsl:element name="progress">
               <xsl:apply-templates select="//Identification_Information/Status/Progress" />
            </xsl:element>
            <!-- Maintenance_and_Update_Frequency: DATA -->
            <xsl:element name="update">
               <xsl:apply-templates select="//Identification_Information/Status/Maintenance_and_Update_Frequency" />
            </xsl:element>
         </xsl:element>
         <!-- Spatial_Domain PARENT ELEMENT -->
         <xsl:element name="spdom">
            <!-- FGDC PARENT ELEMENT -->
            <xsl:element name="bounding">
               <!-- West_Bounding_Coordinate: DATA -->
               <xsl:element name="westbc">
                  <xsl:apply-templates select="//Identification_Information/Spatial_Domain/West_Bounding_Coordinate" />
               </xsl:element>
               <!-- East_Bounding_Coordinate: DATA -->
               <xsl:element name="eastbc">
                  <xsl:apply-templates select="//Identification_Information/Spatial_Domain/East_Bounding_Coordinate" />
               </xsl:element>
               <!-- North_Bounding_Coordinate: DATA -->
               <xsl:element name="northbc">
                  <xsl:apply-templates select="//Identification_Information/Spatial_Domain/North_Bounding_Coordinate" />
               </xsl:element>
               <!-- South_Bounding_Coordinate: DATA -->
               <xsl:element name="southbc">
                  <xsl:apply-templates select="//Identification_Information/Spatial_Domain/South_Bounding_Coordinate" />
               </xsl:element>
            </xsl:element>

            <!-- Data_Set_G-Polygon*R REPEATING CONTAINER -->
            <xsl:for-each select="//Identification_Information/Spatial_Domain/Data_Set_G-Polygon">
               <xsl:element name="dsgpoly">

                  <xsl:if test="Outer_G-Ring">
                     <!-- FGDC PARENT ELEMENT -->
                     <xsl:element name="dsgpolyo">
                        <!-- Outer_G-Ring: DATA -->
                        <xsl:element name="gring">
                           <xsl:apply-templates select="Outer_G-Ring" />
                        </xsl:element>
                     </xsl:element>
                  </xsl:if>

                  <!-- Exclusion_G-Ring:R REPEATING DATA -->
                  <xsl:for-each select="Exclusion_G-Ring">
                     <!-- FGDC PARENT ELEMENT -->
                     <xsl:element name="dsgpolyx">
                        <xsl:element name="gring">
                           <xsl:value-of select="."/>
                        </xsl:element>
                     </xsl:element>
                  </xsl:for-each>

               </xsl:element>
            </xsl:for-each>
         </xsl:element>

         <xsl:if test="('//Identification_Information/Keywords/Theme') or ('//Identification_Information/Keywords/Place')">
            <!-- Keywords PARENT ELEMENT -->
            <xsl:element name="keywords">

               <!-- Theme*R REPEATING CONTAINER -->
               <xsl:for-each select="//Identification_Information/Keywords/Theme">
                  <xsl:element name="theme">
                     <!-- Theme_Keyword_Thesaurus: DATA -->
                     <xsl:element name="themekt">
                        <xsl:apply-templates select="Theme_Keyword_Thesaurus" />
                     </xsl:element>
                     <!-- Theme_Keyword:R REPEATING DATA -->
                     <xsl:for-each select="Theme_Keyword">
                        <xsl:element name="themekey">
                           <xsl:value-of select="."/>
                        </xsl:element>
                     </xsl:for-each>
                  </xsl:element>
               </xsl:for-each>


 <!-- Theme*R REPEATING CONTAINER -->
               <xsl:for-each select="//Identification_Information/Keywords/Theme_ISO">
                  <xsl:element name="theme">
                     <!-- Theme_Keyword_Thesaurus: DATA -->
                     <xsl:element name="themekt">
                        <xsl:apply-templates select="Theme_Keyword_Thesaurus_ISO" />
                     </xsl:element>
                     <!-- Theme_Keyword:R REPEATING DATA -->
                     <xsl:for-each select="Theme_Keyword">
                        <xsl:element name="themekey">
                           <xsl:value-of select="."/>
                        </xsl:element>
                     </xsl:for-each>
                  </xsl:element>
               </xsl:for-each>
                               
               <!-- Place*R REPEATING CONTAINER -->
               <xsl:for-each select="//Identification_Information/Keywords/Place">
                  <xsl:element name="place">
                     <!-- Place_Keyword_Thesaurus: DATA -->
                     <xsl:element name="placekt">
                        <xsl:apply-templates select="Place_Keyword_Thesaurus" />
                     </xsl:element>
                     <!-- Place_Keyword:R REPEATING DATA -->
                     <xsl:for-each select="Place_Keyword">
                        <xsl:element name="placekey">
                           <xsl:value-of select="."/>
                        </xsl:element>
                     </xsl:for-each>
                  </xsl:element>
               </xsl:for-each>

               <xsl:for-each select="//Identification_Information/Keywords/Place_INCITS">
                  <xsl:element name="place">
                     <!-- Place_Keyword_Thesaurus: DATA -->
                     <xsl:element name="placekt">
                        <xsl:apply-templates select="Place_Keyword_Thesaurus" />
                     </xsl:element>
                     <!-- Place_Keyword:R REPEATING DATA -->
                     <xsl:for-each select="Place_Keyword">
                        <xsl:element name="placekey">
                           <xsl:value-of select="."/>
                        </xsl:element>
                     </xsl:for-each>
                  </xsl:element>
               </xsl:for-each>



               <xsl:for-each select="//Identification_Information/Keywords/Place_INCITSB">
                  <xsl:element name="place">
                     <!-- Place_Keyword_Thesaurus: DATA -->
                     <xsl:element name="placekt">
                           <xsl:variable name="placektNor" select="normalize-space(Place_Keyword_Thesaurus)"/>
                            <xsl:value-of select="$placektNor"/>
                        <!-- <xsl:apply-templates select="Place_Keyword_Thesaurus" /> -->
                     </xsl:element>
                     <!-- Place_Keyword:R REPEATING DATA -->
                     <xsl:for-each select="Place_Keyword">
                        <xsl:element name="placekey">
                          <!--  <xsl:value-of select="."/> -->
                           <xsl:variable name="placekeyNor" select="normalize-space(.)"/>
                             <xsl:value-of select="$placekeyNor"/>
                        </xsl:element>
                     </xsl:for-each>
                  </xsl:element>
               </xsl:for-each>

<xsl:for-each select="//Identification_Information/Keywords/Place_INCITSC">
                  <xsl:element name="place">
                     <!-- Place_Keyword_Thesaurus: DATA -->
                     <xsl:element name="placekt">
                           <xsl:variable name="placektNor" select="normalize-space(Place_Keyword_Thesaurus)"/> 
                        <!-- <xsl:apply-templates select="Place_Keyword_Thesaurus" /> -->
                               <xsl:value-of select="$placektNor"/>
                     </xsl:element>
                     <!-- Place_Keyword:R REPEATING DATA -->
                     <xsl:for-each select="Place_Keyword">
                        <xsl:element name="placekey">
                            <xsl:variable name="placekeyNor" select="normalize-space(.)"/>   
                           <!-- <xsl:value-of select="."/> -->
                                 <xsl:value-of select="$placekeyNor"/>    
                        </xsl:element>
                     </xsl:for-each>
                  </xsl:element>
               </xsl:for-each>


             </xsl:element>
         </xsl:if>




         <!-- Access_Constraints: DATA -->
         <xsl:element name="accconst">
            <xsl:apply-templates select="//Identification_Information/Access_Constraints" />
         </xsl:element>
         <!-- Use_Constraints: DATA -->
         <xsl:element name="useconst">
            <xsl:apply-templates select="//Identification_Information/Use_Constraints" />
         </xsl:element>


         <!-- TEST FOR: Point_of_Contact PARENT ELEMENT -->
         <xsl:if test="//Identification_Information/Point_of_Contact">
            <!-- Point_of_Contact PARENT ELEMENT -->
            <xsl:element name="ptcontac">
               <!-- FGDC PARENT ELEMENT -->
               <xsl:element name="cntinfo">

                  <!-- FGDC PARENT ELEMENT -->
                  <xsl:element name="cntorgp">
                     <!-- Contact_Organization: DATA -->
                     <xsl:element name="cntorg">
                        <xsl:apply-templates select="//Identification_Information/Point_of_Contact/Contact_Organization" />
                     </xsl:element>
                  </xsl:element>

                  <!-- Contact_Address PARENT ELEMENT -->
                  <xsl:element name="cntaddr">
                     <!-- Address_Type: DATA -->
                     <xsl:element name="addrtype">
                        <xsl:apply-templates select="//Identification_Information/Point_of_Contact/Contact_Address/Address_Type" />
                     </xsl:element>

					                   
                  <!-- Address:R -->
                  
                      <xsl:for-each select="//Identification_Information/Point_of_Contact/Contact_Address/Address">
                        <xsl:call-template name="Address"/>
                      </xsl:for-each>
                  
                     
					 <!-- LL This is not working no address tag or address is written
					 replace this with address code above and see end of file for address template 
					 Address:R REPEATING DATA
                     <xsl:for-each select="Address">
                        <xsl:element name="address">
                           <xsl:value-of select="."/>
                        </xsl:element>
                     </xsl:for-each> -->
                     
					 
					 <!-- City: DATA -->
                     <xsl:element name="city">
                        <xsl:apply-templates select="//Identification_Information/Point_of_Contact/Contact_Address/City" />
                     </xsl:element>
                     <!-- State_or_Province: DATA -->
                     <xsl:element name="state">
                        <xsl:apply-templates select="//Identification_Information/Point_of_Contact/Contact_Address/State_or_Province" />
                     </xsl:element>
                     <!-- Postal_Code: DATA -->
                     <xsl:element name="postal">
                        <xsl:apply-templates select="//Identification_Information/Point_of_Contact/Contact_Address/Postal_Code" />
                     </xsl:element>
                     <!-- Country: DATA -->
                     <xsl:element name="country">
                        <xsl:apply-templates select="//Identification_Information/Point_of_Contact/Contact_Address/Country" />
                     </xsl:element>
                  </xsl:element>

                  <!-- Contact_Voice_Telephone:R REPEATING DATA -->
                  <xsl:for-each select="//Identification_Information/Point_of_Contact/Contact_Voice_Telephone">
                     <xsl:element name="cntvoice">
                        <xsl:value-of select="."/>
                     </xsl:element>
                  </xsl:for-each>
                  <!-- Contact_Facsimile_Telephone: DATA -->
                  <xsl:element name="cntfax">
                     <xsl:apply-templates select="//Identification_Information/Point_of_Contact/Contact_Facsimile_Telephone" />
                  </xsl:element>
                  <!-- Contact_Electronic_Mail_Address: DATA -->
                  <xsl:element name="cntemail">
                     <xsl:apply-templates select="//Identification_Information/Point_of_Contact/Contact_Electronic_Mail_Address" />
                  </xsl:element>

               </xsl:element>
            </xsl:element>

         </xsl:if>
         <!-- END TEST FOR: Point_of_Contact PARENT ELEMENT -->


      <xsl:if test="//Identification_Information/Browse_Graphic/Browse_Graphic_File_Name" >
         <!-- Browse_Graphic PARENT ELEMENT -->
         <xsl:element name="browse">

            <!-- Browse_Graphic_File_Name: DATA -->
            <xsl:element name="browsen">
               <xsl:apply-templates select="//Identification_Information/Browse_Graphic/Browse_Graphic_File_Name" />
            </xsl:element>
            <!-- Browse_Graphic_File_Description: DATA -->
            <xsl:element name="browsed">
               <xsl:apply-templates select="//Identification_Information/Browse_Graphic/Browse_Graphic_File_Description" />
            </xsl:element>
            <!-- Browse_Graphic_File_Type: DATA -->
            <xsl:element name="browset">
               <xsl:apply-templates select="//Identification_Information/Browse_Graphic/Browse_Graphic_File_Type" />
            </xsl:element>

         </xsl:element>
      </xsl:if>

      <xsl:if test="//Identification_Information/Native_Data_Set_Environment">
         <!-- Native_Data_Set_Environment: DATA -->
         <xsl:element name="native">
            <xsl:apply-templates select="//Identification_Information/Native_Data_Set_Environment" />
         </xsl:element>
      </xsl:if>

      <!-- Cross_Reference*R REPEATING CONTAINER -->
      <xsl:for-each select="//Identification_Information/Cross_Reference">
         <xsl:element name="crossref">
            <!-- FGDC PARENT ELEMENT -->
            <xsl:element name="citeinfo">

               <!-- Originator:R REPEATING DATA -->
               <xsl:for-each select="Originator">
                  <xsl:element name="origin">
                     <xsl:value-of select="."/>
                  </xsl:element>
               </xsl:for-each>

               <!-- Publication_Date: DATA -->
               <xsl:element name="pubdate">
                  <xsl:apply-templates select="//Identification_Information/Cross_Reference/Publication_Date" />
               </xsl:element>

               <!-- Title: DATA -->
               <xsl:element name="title">
                  <xsl:apply-templates select="//Identification_Information/Cross_Reference/Title" />
               </xsl:element>

               <!-- Online_Linkage:R REPEATING DATA -->
               <xsl:for-each select="Online_Linkage">
                  <xsl:element name="onlink">
                     <xsl:value-of select="."/>
                  </xsl:element>
               </xsl:for-each>

            </xsl:element>
         </xsl:element>
      </xsl:for-each>


      <!-- CLOSE IDENTIFICATION_INFORMATION -->
      </xsl:element>

   </xsl:template>

   <!-- Address:R  match="Address" -->
<xsl:template name="Address">
   <xsl:element name="address">
      <xsl:value-of select="."/>
   </xsl:element>
</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>
-->
