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

<!--
   Name:  MD_MaintenanceFrequencyCode.xsl 
   Author:  Matthew J. McCready
   Date:  20110706
   Description:  XSLT stylesheet that is called by the 11_gmd:identificationInfo.xsl and the  15_gmd:metadataMaintenance.xsl stylesheets. It transforms the element in the /metadata/idinfo/status/update element into a value in the MD_MaintenanceFrequencyCode code list, which can be found on page 99 of the ISO standard.
   Modification History:
      Initial   Date         Change Request ID   Description
      MMC       07122011                         Insered the MD_MaintenanceFrequencyCodeMetMaint template. This template is similiar to the MD_MaintenanceFrequencyCode
                                                  template, but does not have the gmd:resourceMaintenance and gmd:MD_MaintenanceInformation elements. This is due to                                                     the fact that the gmd:resourceMaintenance element is not in the gmd:resourceMaintenance section.  For the 
                                                  The gmd:MD_MaintenanceInformation element contains only the gmd:MD_MaintenanceFrequencyCode for the 
                                                  identificationInfo section but contains additional elements in the gmd:metadataMaintenance section. 
      MMC       103111                           Inserted the 'None planned' for the choose decision structure. This was done for the MIF files
-->


<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:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>

 <xsl:template name="MD_MaintenanceFrequencyCode">
  <xsl:variable name="CodeListLoc"
   >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_MaintenanceFrequencyCode</xsl:variable>
  <xsl:variable name="MaintenanceFrequencyCode" select="//metadata/idinfo/status/update"/>
  <xsl:variable name="TigerChange">No changes or updates will be made to this version</xsl:variable>
  <!-- None planned -->
  <xsl:variable name="TigerChangeB">None planned</xsl:variable>
  <xsl:variable name="MaintenanceFrequencyCodeChange"
   select="contains($MaintenanceFrequencyCode,$TigerChange)"/>
  <xsl:variable name="MaintenanceFrequencyCodeChangeB"
   select="contains($MaintenanceFrequencyCode,$TigerChangeB)"/>
  <!-- <xsl:comment> Calling MD_MaintenanceFrequencyCode </xsl:comment> -->
  
  <!-- <xsl:comment> In the MD_MaintenanceFrequencyCode template</xsl:comment> -->
  
  <xsl:choose>
   <!-- <xsl:comment> In the first choice </xsl:comment> -->
   <xsl:when test="$MaintenanceFrequencyCodeChange='true'">
    <!--  <xsl:comment> In the first choice </xsl:comment> -->
    <xsl:element name="gmd:resourceMaintenance">
     <xsl:element name="gmd:MD_MaintenanceInformation">
      <xsl:element name="gmd:maintenanceAndUpdateFrequency">
       <xsl:element name="gmd:MD_MaintenanceFrequencyCode">
        <xsl:attribute name="codeList"><xsl:value-of select="$CodeListLoc"/></xsl:attribute>
        <xsl:attribute name="codeListValue">notPlanned</xsl:attribute>
        <xsl:attribute name="codeSpace">011</xsl:attribute> notPlanned </xsl:element><!-- gmd:MD_MaintenanceFrequencyCode -->
      </xsl:element><!-- gmd:maintenanceAndUpdateFrequency -->
      
      <xsl:if test="/metadata/idinfo/status/update">
      <xsl:element name="gmd:maintenanceNote"> 
       <xsl:element name="gco:CharacterString">
          <xsl:value-of select="/metadata/idinfo/status/update"/>  
        </xsl:element>
      </xsl:element>
      </xsl:if>
      
     </xsl:element><!-- gmd:MD_MaintenanceInformation -->
    </xsl:element><!-- gmd:resourceMaintenance -->
   </xsl:when>

   <xsl:when test="$MaintenanceFrequencyCodeChangeB='true'">
    <!--  <xsl:comment> In the second choice </xsl:comment> -->
    <xsl:element name="gmd:resourceMaintenance">
     <xsl:element name="gmd:MD_MaintenanceInformation">
      <xsl:element name="gmd:maintenanceAndUpdateFrequency">
       <xsl:element name="gmd:MD_MaintenanceFrequencyCode">
        <xsl:attribute name="codeList"><xsl:value-of select="$CodeListLoc"/></xsl:attribute>
        <xsl:attribute name="codeListValue">notPlanned</xsl:attribute>
        <xsl:attribute name="codeSpace">011</xsl:attribute> notPlanned </xsl:element>
       <!-- gmd:MD_MaintenanceFrequencyCode -->
      </xsl:element><!-- gmd:maintenanceAndUpdateFrequency -->
      
      <xsl:if test="/metadata/idinfo/status/update">
      <xsl:element name="gmd:maintenanceNote"> 
       <xsl:element name="gco:CharacterString">
        <xsl:value-of select="/metadata/idinfo/status/update"/>  
       </xsl:element>
      </xsl:element>
      </xsl:if>
      
     </xsl:element> <!-- gmd:MD_MaintenanceInformation -->
    </xsl:element><!-- gmd:resourceMaintenance -->
   </xsl:when>


   <xsl:otherwise>
     <xsl:comment> In the otherwise </xsl:comment>
    <xsl:element name="gmd:resourceMaintenance">
     <xsl:element name="gmd:MD_MaintenanceInformation">
      <xsl:element name="gmd:maintenanceAndUpdateFrequency">
       <xsl:attribute name="gco:nilReason">unknown:<xsl:value-of select="$MaintenanceFrequencyCode"/>
       </xsl:attribute>
      </xsl:element>
     </xsl:element>
    </xsl:element>
    <!-- gmd:maintenanceAndUpdateFrequency -->
   </xsl:otherwise>

  </xsl:choose>
 </xsl:template>

 <xsl:template name="MD_MaintenanceFrequencyCodeMetMaint">
  <xsl:variable name="CodeListLoc"
   >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_MaintenanceFrequencyCode</xsl:variable>
  <xsl:variable name="MaintenanceFrequencyCode" select="//metadata/idinfo/status/update"/>
  <xsl:variable name="TigerChange">No changes or updates will be made to this version</xsl:variable>
  <xsl:variable name="MaintenanceFrequencyCodeChange"
   select="contains($MaintenanceFrequencyCode,$TigerChange)"/>
  <!-- <xsl:comment> Calling MD_MaintenanceFrequencyCode </xsl:comment> -->
  <xsl:choose>
   <xsl:when test="$MaintenanceFrequencyCodeChange='true'">
    <!-- xsl:element name="gmd:resourceMaintenance"> -->
    <!--  <xsl:element name="gmd:MD_MaintenanceInformation"> -->
    <xsl:element name="gmd:maintenanceAndUpdateFrequency">
     <xsl:element name="gmd:MD_MaintenanceFrequencyCode">
      <xsl:attribute name="codeList"><xsl:value-of select="$CodeListLoc"/></xsl:attribute>
      <xsl:attribute name="codeListValue">notPlanned</xsl:attribute>
      <xsl:attribute name="codeSpace">011</xsl:attribute> notPlanned </xsl:element>
     <!-- gmd:MD_MaintenanceFrequencyCode -->
    </xsl:element>
    <!-- gmd:maintenanceAndUpdateFrequency -->
    <!--   </xsl:element>-->
    <!-- gmd:MD_MaintenanceInformation -->
    <!--  </xsl:element> -->
    <!-- gmd:resourceMaintenance -->
   </xsl:when>

   <xsl:otherwise>
    <xsl:comment> right place A</xsl:comment>
    <xsl:element name="gmd:maintenanceAndUpdateFrequency">
     <xsl:attribute name="gco:nilReason">unknown:<xsl:value-of select="$MaintenanceFrequencyCode"/>
     </xsl:attribute>
    </xsl:element>
    <!-- gmd:maintenanceAndUpdateFrequency -->
   </xsl:otherwise>

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