<!--
   Name:  MD_MaintenanceFrequencyCode.xsl 
   Author:  Matthew J. McCready
   Date:  20111012
   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  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        120420113                       Ensured that all the calls to the ISO codelist have the correct URL                                             
-->


<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" 
>
<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="//MIF/Maintenance_and_Update_Frequency"/>
<xsl:variable name="TigerChange">No changes or updates will be made to this version</xsl:variable>
<xsl:variable name="NonePlanned">None planned</xsl:variable>
<xsl:variable name="MaintenanceFrequencyCodeChange" select="contains($MaintenanceFrequencyCode,$TigerChange)"/>
<xsl:variable name="MaintenanceFrequencyCodeChangeB" select="contains($MaintenanceFrequencyCode,$NonePlanned)"/>
<!-- <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:when test="$MaintenanceFrequencyCodeChangeB='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: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>

