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

<!--
   Name: 11_gmd:identificationInfo.xsl 
   Author:  Matthew J. McCready
   Date:  20110608
   Description:  XSLT stylesheet that transforms Section 1 of an FGDC format file into a ISO file. This style sheet calls on eight templates located in other stylesheets: CI_PresentationFormCode,               MD_ProgressCode, MD_MaintenanceFrequencyCode, NonISOKeywords, MD_SpatialRepresentationTypeCode, ISO_TopicCategories, BegDateTemp  and EndDateTemp. The CI_PresentationFormCode template, located in the         CI_PresentationFormCode.xsl stylesheet, transforms the value in the  citation/citeinfo/geoform (Geospatial Data Presentation Form) element into the correct CI_PresentationFormCode codeList value. The         MD_ProgressCode template, located in the MD_ProgressCode.xsl styleshet, transforms the value in the  timeperd/current (Currentness Reference) element into the correct MD_ProgressCode codeList value. The      MD_MaintenanceFrequencyCode template, located in the MD_MaintenanceFrequencyCode.xsl stylesheet, transforms the element in the /metadata/idinfo/status/update element into a value in the                       MD_MaintenanceFrequencyCode code list. The NonISOKeywords template, located in the NonISOKeywords.xsl stylesheet, transforms the values stored in  the keywords/theme and keywords/place FGDC elements to the   gmd:descriptiveKeywords element. The MD_SpatialRepresentationTypeCode template, stored in the MD_SpatialRepresentationTypeCode.xsl stylesheet, transforms the value in the  /metadata/spdoinfo/direct(Direct    Spatial Reference) element into the correct MD_SpatialRepresentationTypeCode.xsl codeList value. The ISO_TopicCategories template, located in the stylesheet, transforms the value in the keywords/theme        element that are related to the ISO Topic Categories to the ISO_TopicCategories element. The BegDateTemp template, located in the DateFormat.xsl stylesheet, formats the date stored in the                      metadata/idinfo/timeperd/timeinfo/rngdates/begdate FGDC element and inserts in the gml:beginPosition ISO element. Finally, the EndDateTemp template, also stored inthe  DateFormat.xsl stylesheet, formats     the value stored  in the metadata/idinfo/timeperd/timeinfo/rngdates/enddate FGDC element and inserts in the gml:endPosition ISO element. 
   Modification History:
      Initial   Date      Change Request ID   Description
      07/07/2011                              Changed the gmd:southBoundLongitude and gmd:northBoundLongitude to gmd:southBoundLatitude and 
                                               gmd:northBoundLatitude repectively to conform to the ISO standard.
      07/07/2011                              Changed the boundingTemporalExtent element under  gmd:temporalElement to gml:description
      03/01/2012                              Removed the extra space in the codeListValue of the  gmd:accessConstraints/gmd:MD_RestrictionCode and  gmd:accessConstraints/gmd:useConstraints element.
      03/06/2012                              Seperated the access contraints and the use constraints into two  gmd:otherConstraints elements. Also added a gmd:otherConstraints for the Distribution
                                               Liability.  
     03/06/2012                               Inserted the gmd:environmentDescription element so that the Technical Prerequisites (techpreq) from the FGDC Standard could be included in the ISO file. 
-->


<!-- 
List of Related Templates and associated stylesheets
Template                                     Stylesheet/File
CI_PresentationFormCode                      CI_PresentationFormCode.xsl
MD_ProgressCode                              MD_ProgressCode.xsl
MD_MaintenanceFrequencyCode                  MD_MaintenanceFrequencyCode.xsl
NonISOKeywords                               NonISOKeywords.xsl
MD_SpatialRepresentationTypeCode             MD_SpatialRepresentationTypeCode.xsl
ISO_TopicCategories                          ISO_TopicCategories.xsl
BegDateTemp                                  DateFormat.xsl
EndDateTemp                                  DateFormat.xsl  
-->

<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"
   xmlns:gml="http://www.opengis.net/gml/3.2">

   <xsl:import href="../FGDC2ISO/IdPointOfContact.xsl"/>
   <xsl:import href="../FGDC2ISO/NGDA_Themes.xsl"/>

   <!-- xmlns:gmd="http://www.isotc211.org/2005/gmd" -->
   <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>


   <xsl:template name="identificationInfo" match="/">
      <xsl:comment> This part represents Section 1 of the FGDC Metadata Standard </xsl:comment>

      <xsl:text>
</xsl:text>


      <xsl:if test="metadata/idinfo">


         <xsl:element name="gmd:identificationInfo">
            <xsl:element name="gmd:MD_DataIdentification">
               <xsl:element name="gmd:citation">
                  <xsl:element name="gmd:CI_Citation">

                     <xsl:element name="gmd:title">
                        <xsl:element name="gco:CharacterString">
                           <xsl:apply-templates select="//metadata/idinfo/citation/citeinfo/title"/>
                        </xsl:element>
                     </xsl:element>
                     <!-- gmd:title -->


                     <xsl:element name="gmd:date">
                        <xsl:element name="gmd:CI_Date">
                           <xsl:text>
</xsl:text>
                           <xsl:comment> This is the publication date </xsl:comment>
                           <xsl:text>
</xsl:text>
                           <xsl:element name="gmd:date">
                              <!-- <xsl:variable name="dateFormat" select="concat($year, '-',$month,'-',$day)"/> -->
                              <!-- <xsl:variable name="dateFormat" select="concat($year, '-',$month)"/> -->

                              <xsl:element name="gco:Date">
                                 <xsl:value-of select="//metadata/idinfo/citation/citeinfo/pubdate"
                                 />
                              </xsl:element>
                              <!--gco:date -->
                           </xsl:element>
                           <!-- gmd:date -->

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

                        </xsl:element>
                        <!-- gmd:CI_Date -->
                     </xsl:element>
                     <!-- gmd:date -->

                     <xsl:if test="/metadata/idinfo/citation/citeinfo/edition">
                        <xsl:element name="gmd:edition">
                           <xsl:element name="gco:CharacterString">
                              <xsl:value-of select="//metadata/idinfo/citation/citeinfo/edition"/>
                           </xsl:element>
                           <!-- gco:CharacterString -->
                        </xsl:element>
                     </xsl:if>
                     <!-- gmd:edition -->


                     <xsl:call-template name="IDOriginator"/>



                   

                     <xsl:if test="//metadata/idinfo/citation/citeinfo/geoform">
                        <!-- <xsl:comment>The geoform goes here</xsl:comment> -->
                        <xsl:call-template name="CI_PresentationFormCode"/>
                     </xsl:if>


                     <!-- <xsl:if test="//metadata/idinfo/keywords/theme">
<xsl:comment>The NON-ISO theme keywords go here&#xa;</xsl:comment>
<xsl:call-template name="Non-ISOKeywords"/> 
</xsl:if>-->
                  </xsl:element>
                  <!-- gmd:CI_Citation -->
               </xsl:element>
               <!-- gmd:citation-->

               <xsl:element name="gmd:abstract">
                  <xsl:element name="gco:CharacterString">
                     <xsl:value-of select="//metadata/idinfo/descript/abstract"/>
                  </xsl:element>
                  <!-- gco:CharacterString -->
               </xsl:element>
               <!-- gmd:abstract -->

               <xsl:element name="gmd:purpose">
                  <xsl:element name="gco:CharacterString">
                     <xsl:value-of select="//metadata/idinfo/descript/purpose"/>
                  </xsl:element>
                  <!-- gco:CharacterString -->
               </xsl:element>
               <!-- gmd:purpose -->

               <xsl:if test="//metadata/idinfo/status/progress">
                  <!-- <xsl:comment>The progress goes here</xsl:comment> -->
                  <xsl:call-template name="MD_ProgressCode"/>
               </xsl:if>

               <xsl:call-template name="IdPointOfContact"/>


               <xsl:if test="//metadata/idinfo/citation/citeinfo/geoform">
                  <!-- <xsl:comment>The Maintenance and Update Frequency information goes here for section 1 from the 11_gmd:identificationInfo.xsl stylesheet</xsl:comment> -->
                  <xsl:call-template name="MD_MaintenanceFrequencyCode"/>
               </xsl:if>


               <!-- <xsl:if test="//metadata/idinfo/citation/citeinfo/geoform" -->
               <xsl:if test=" /metadata/idinfo/keywords/theme">
                  <!-- <xsl:comment>The non-ISO theme keywords go here (NonISOKeywords.xsl) &#xa;</xsl:comment> -->
                  <xsl:call-template name="NonISOKeywords"/>
               </xsl:if>

               <xsl:call-template name="NGDAThemes"/>

               <xsl:element name="gmd:resourceConstraints">
                  <xsl:element name="gmd:MD_LegalConstraints">

                     <xsl:element name="gmd:accessConstraints">

                        <xsl:element name="gmd:MD_RestrictionCode">
                           <xsl:attribute name="codeList"
                              >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_RestrictionCode</xsl:attribute>
                           <xsl:attribute name="codeListValue">otherRestrictions</xsl:attribute>
                           <xsl:attribute name="codeSpace">008 </xsl:attribute> otherRestrictions </xsl:element>
                        <!-- gmd:MD_RestrictionCode -->
                     </xsl:element>
                     <!-- gmd:accessConstraints -->

                     <xsl:element name="gmd:useConstraints">
                        <xsl:element name="gmd:MD_RestrictionCode">
                           <xsl:attribute name="codeList"
                              >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_RestrictionCode</xsl:attribute>
                           <xsl:attribute name="codeListValue">otherRestrictions</xsl:attribute>
                           <xsl:attribute name="codeSpace">008 </xsl:attribute>
                        </xsl:element>
                        <!-- gmd:MD_RestrictionCode -->
                     </xsl:element>
                     <!-- gmd:useConstraints -->

                     <xsl:element name="gmd:otherConstraints">
                        <xsl:element name="gco:CharacterString">
                           <xsl:text>Access Constraints: </xsl:text>
                           <xsl:value-of select="/metadata/idinfo/accconst"/>
                        </xsl:element>
                        <!-- gco:CharacterString -->
                     </xsl:element>
                     <!-- gmd:otherConstraints -->


                     <xsl:element name="gmd:otherConstraints">
                        <xsl:element name="gco:CharacterString">
                           <xsl:text>Use Constraints: </xsl:text>
                           <xsl:value-of select="/metadata/idinfo/useconst"/>
                        </xsl:element>
                        <!-- gco:CharacterString -->
                     </xsl:element>
                     <!-- gmd:otherConstraints -->

                     <!-- DISTRIBUTION LIABILITY -->
                     <xsl:element name="gmd:otherConstraints">
                        <xsl:element name="gco:CharacterString">
                           <xsl:text>Distribution Liability: </xsl:text>
                           <xsl:value-of select="/metadata/distinfo/distliab"/>
                        </xsl:element>
                        <!-- gco:CharacterString -->
                     </xsl:element>
                     <!-- gmd:otherConstraints -->


                     <!-- </xsl:element> -->
                     <!-- gmd:accessConstraints -->

                  </xsl:element>
                  <!-- gmd:MD_LegalConstraints -->
               </xsl:element>
               <!-- gmd:resourceConstraints -->
               <xsl:text>
</xsl:text>

               <xsl:comment> This is from the Direct Spatial Reference from Chapter 3 </xsl:comment>
               <xsl:text>
</xsl:text>

               <!-- <xsl:element name="gmd:spatialRepresentationType">
<xsl:attribute name="codeList">http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_SpatialRepresentationTypeCode </xsl:attribute>


</xsl:element> gmd:spatialRepresentationType -->

               <xsl:if test="/metadata/spdoinfo/direct">
                  <xsl:call-template name="MD_SpatialRepresentationTypeCode"/>
               </xsl:if>

               <!-- <xsl:comment> Here is the language </xsl:comment> -->
               <xsl:element name="gmd:language">
                  <xsl:choose>
                     <xsl:when test="//metadata/idinfo/Metadata_Language">
                        <xsl:element name="gco:CharacterString">
                           <xsl:value-of select="//metadata/idinfo/Metadata_Language"/>
                        </xsl:element>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:element name="gco:CharacterString">eng</xsl:element>
                     </xsl:otherwise>
                  </xsl:choose>

               </xsl:element>
               <!-- language -->
               <!-- <xsl:comment>Calling the ISO_TopicCategories </xsl:comment> -->
               <xsl:call-template name="ISO_TopicCategories"/>

               <xsl:element name="gmd:environmentDescription">
                  <xsl:element name="gco:CharacterString">
                     <xsl:text>Technical Prerequisites: </xsl:text>
                     <xsl:value-of select="/metadata/distinfo/techpreq"/>
                  </xsl:element>
                  <!-- gco:CharacterString -->
               </xsl:element>
               <!-- gmd:environmentDescription -->




               <xsl:element name="gmd:extent">
                  <xsl:element name="gmd:EX_Extent">
                     <xsl:attribute name="id">boundingExtent</xsl:attribute>

                     <xsl:element name="gmd:geographicElement">
                        <xsl:element name="gmd:EX_GeographicBoundingBox">
                           <xsl:attribute name="id">boundingGeographicBoundingBox</xsl:attribute>

                           <xsl:element name="gmd:westBoundLongitude">
                              <xsl:element name="gco:Decimal">
                                 <xsl:value-of select="/metadata/idinfo/spdom/bounding/westbc"/>
                              </xsl:element>
                              <!-- gco:Decimal -->
                           </xsl:element>
                           <!-- gmd:westBoundLongitude -->

                           <xsl:element name="gmd:eastBoundLongitude">
                              <xsl:element name="gco:Decimal">
                                 <xsl:value-of select="/metadata/idinfo/spdom/bounding/eastbc"/>
                              </xsl:element>
                              <!-- gco:Decimal -->
                           </xsl:element>
                           <!-- gmd:eastBoundLongitude -->

                           <xsl:element name="gmd:southBoundLatitude">
                              <xsl:element name="gco:Decimal">
                                 <xsl:value-of select="/metadata/idinfo/spdom/bounding/southbc"/>
                              </xsl:element>
                              <!-- gco:Decimal -->
                           </xsl:element>
                           <!-- gmd:southBoundLongitude -->

                           <xsl:element name="gmd:northBoundLatitude">
                              <xsl:element name="gco:Decimal">
                                 <xsl:value-of select="/metadata/idinfo/spdom/bounding/northbc"/>
                              </xsl:element>
                              <!-- gco:Decimal -->
                           </xsl:element>
                           <!-- gmd:southBoundLongitude -->

                        </xsl:element>
                        <!-- gmd:EX_GeographicBoundingBox -->
                     </xsl:element>
                     <!-- gmd:geographicElement -->

                     <xsl:element name="gmd:temporalElement">
                        <xsl:element name="gmd:EX_TemporalExtent">
                           <xsl:attribute name="id">boundingTemporalExtent</xsl:attribute>
                           <!-- <xsl:attribute name="gml:id">boundingTimePeriodExtent</xsl:attribute> -->
                           <xsl:element name="gmd:extent">
                              <xsl:element name="gml:TimePeriod">
                                 <xsl:attribute name="gml:id"
                                    >boundingTemporalExtent1</xsl:attribute>

                                 <xsl:text>

</xsl:text>
                                 <xsl:element name="gml:description">
                                    <xsl:value-of select="/metadata/idinfo/timeperd/current"/>
                                 </xsl:element>

                                 <xsl:call-template name="BegDateTemp"/>
                                 <xsl:call-template name="EndDateTemp"/>

                              </xsl:element>
                              <!-- gml:TimePeriod -->
                           </xsl:element>
                           <!-- gmd:extent -->
                        </xsl:element>
                        <!-- gmd:EX_TemporalExtent -->
                     </xsl:element>
                     <!-- gmd:temporalElement -->

                  </xsl:element>
                  <!-- gmd:EX_Extent -->
               </xsl:element>
               <!-- gmd:extent -->

            </xsl:element>
            <!-- gmd:MD_DataIdentification -->
         </xsl:element>
         <!-- gmd:identificationInfo -->
      </xsl:if>




   </xsl:template>
</xsl:stylesheet>
