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

<!--
   Name:  05_gmd:contact.xsl
   Author:  Matthew J. McCready
   Date:  20110601
   Description:  XSLT stylesheet that transforms the  contact information from Section 1 of FGDC format to the gmd:contact ISO element.
   Modification History:
      Initial   Date      Change Request ID   Description

-->


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gco="http://www.isotc211.org/2005/gco"
  xmlns:gfc="http://www.isotc211.org/2005/gfc" xmlns:gmd="http://www.isotc211.org/2005/gmd"
  xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:gsr="http://www.isotc211.org/2005/gsr"
  xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:gts="http://www.isotc211.org/2005/gts"
  xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"
  xmlns:grp="http://www.altova.com/Mapforce/grouping" exclude-result-prefixes="fn grp xs xsi xsl"
  xmlns="http://www.isotc211.org/2005/gfc">
  <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>



  <xsl:template name="contact" match="/">

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



        <xsl:variable name="FullOrg" select="/metadata/idinfo/ptcontac/cntinfo/cntorgp/cntorg"/>
        <xsl:variable name="postComma1" select="substring-after($FullOrg,',')"/>
        <xsl:variable name="division" select="substring-after($postComma1,',')"/>
        <xsl:variable name="finalDivision" select="substring-before($division,',')"/>
        <xsl:variable name="branch" select="substring-after($division,',')"/>

        <!-- <xsl:comment> postComma1=<xsl:value-of select="$postComma1"/></xsl:comment>
  <xsl:comment> division = <xsl:value-of select="$division"/></xsl:comment>
  <xsl:comment> final division= <xsl:value-of select="$finalDivision"/></xsl:comment>-->
        <xsl:comment> branch=<xsl:value-of select="$branch"/></xsl:comment>

        <xsl:choose>

          <xsl:when test="$branch=' Geographic Products Branch'">
            <xsl:element name="gmd:contact">
              <xsl:attribute name="xlink:href">https://www.ngdc.noaa.gov/docucomp/c5ceb003-1ed6-4126-8a16-bc08ce8fc267</xsl:attribute>
              <xsl:attribute name="xlink:title">U.S. Department of Commerce, U.S. Census Bureau, Geography Division, Geographic Products Branch</xsl:attribute>
            </xsl:element>
            <!-- gmd:contact -->
          </xsl:when>

          <!-- <xsl:element name="gmd:CI_ResponsibleParty">

<xsl:element name="gmd:organisationName">
<xsl:element name="gco:CharacterString"> 
- <xsl:apply-templates select="//metadata/metainfo/Metadata_Language"/>  
<xsl:apply-templates select="//metadata/idinfo/ptcontac/cntinfo/cntorgp/cntorg"/> 
</xsl:element>
</xsl:element>

<xsl:element name="gmd:contactInfo"> 
<xsl:element name="gmd:CI_Contact">
<xsl:element name="gmd:phone">
<xsl:element name="gmd:CI_Telephone">

<xsl:element name="gmd:voice">
<xsl:element name="gco:CharacterString">
  <xsl:apply-templates select="//metadata/idinfo/ptcontac/cntinfo/cntvoice"/>
</xsl:element>
</xsl:element>

<xsl:element name="gmd:facsimile">
<xsl:element name="gco:CharacterString">
  <xsl:apply-templates select="//metadata/idinfo/ptcontac/cntinfo/cntfax"/>
</xsl:element>
</xsl:element>

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


<xsl:element name="gmd:address">
<xsl:element name="gmd:CI_Address">

<xsl:element name="gmd:deliveryPoint">
<xsl:element name="gco:CharacterString">
  <xsl:apply-templates select="//metadata/idinfo/ptcontac/cntinfo/cntaddr/address"/>
</xsl:element>
</xsl:element>
<xsl:element name="gmd:city">
<xsl:element name="gco:CharacterString">
  <xsl:apply-templates select="//metadata/idinfo/ptcontac/cntinfo/cntaddr/city"/>
</xsl:element>
</xsl:element>


<xsl:element name="gmd:administrativeArea">
<xsl:element name="gco:CharacterString">
  <xsl:apply-templates select="//metadata/idinfo/ptcontac/cntinfo/cntaddr/state"/>
</xsl:element>
</xsl:element>
<xsl:element name="gmd:postalCode">
<xsl:element name="gco:CharacterString"> 
  <xsl:apply-templates select="//metadata/idinfo/ptcontac/cntinfo/cntaddr/postal"/>
</xsl:element>
</xsl:element>

<xsl:element name="gmd:country"> 
<xsl:element name="gco:CharacterString">  
  <xsl:apply-templates select="//metadata/idinfo/ptcontac/cntinfo/cntaddr/country"/>
</xsl:element>
</xsl:element>

<xsl:element name="gmd:electronicMailAddress">     
<xsl:element name="gco:CharacterString">
  <xsl:apply-templates select="//metadata/idinfo/ptcontac/cntinfo/cntemail"/>
</xsl:element> 
</xsl:element>


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


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

<xsl:element name="gmd:role">
<xsl:element name="gmd:CI_RoleCode">

<xsl:attribute name="codeList">http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_RoleCode</xsl:attribute>
<xsl:attribute name="codeListValue">pointofContact</xsl:attribute>
pointofContact
</xsl:element>
</xsl:element>

</xsl:element> -->
        </xsl:choose>



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

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