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

<!--
   Name:  12_gmd:contentInfo.xsl
   Author:  Matthew J. McCready
   Date:  20110601
   Description:  XSLT stylesheet that provides the link to the feature catolog, which contains the entity and attribute information.
   Modification History:
      Initial   Date      Change Request ID   Description
      MMC          07/07/2011                 Changed the contentInfo to gmd:contentInfo
      MMC          07/07/2011                 Created the featureCatalogueCitationDate template to handle the date under the CI_Citation package
                                               changed CI_Citation gmd:CI_Citation.
      MMC          07/07/2011                 Added the gco:CharacterString under the gmd:title element.
      MMC          05/31/2012                 Added the FC_CitedResponsibleParty template. This template contains the URL link for the EA file.
                                               This section is basically CI_ResponsibleParty package. 
      MMC          03/22/2013                 Corrected the url in the ContentInfo section to reflect the new metadata server                                
-->


<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:xlink="http://www.w3.org/1999/xlink"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        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">
        <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>



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

                <xsl:element name="gmd:contentInfo">
                        <xsl:element name="gmd:MD_FeatureCatalogueDescription">

                                <xsl:element name="gmd:includedWithDataset">
                                        <xsl:call-template name="includedWithDataset"/>
                                </xsl:element>
                                <!-- gmd:includedWithDataset -->

                                <!-- <xsl:comment> calling the FeatureType Template </xsl:comment>
                                <xsl:comment> Now calling the FeatureType template </xsl:comment> -->
                                <xsl:text>
</xsl:text>
                                <xsl:call-template name="FeatureType"/>



                                <xsl:element name="gmd:featureCatalogueCitation">
                                        <xsl:element name="gmd:CI_Citation">

                                               <!-- <xsl:comment> calling the ContentTitle Template </xsl:comment> -->
                                                <xsl:call-template name="ContentTitle"/>
                                                <xsl:element name="gmd:date">
                                                  <xsl:element name="gmd:CI_Date">
                                                  <xsl:element name="gmd:date">

                                                  <xsl:call-template
                                                  name="featureCatalogueCitationDate"/>
                                                  </xsl:element>
                                                  <!-- gmd:date -->


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

                                                  <xsl:element name="gmd:CI_DateTypeCode">
                                                  <xsl:attribute name="codeList"
                                                  >./resources/codeList.xml#CI_DateTypeCode</xsl:attribute>
                                                  <xsl:attribute name="codeListValue">publication </xsl:attribute>
                                                  <xsl:attribute name="codeSpace"
                                                  >002</xsl:attribute>
                                                  </xsl:element>
                                                  <!-- gmd:CI_DateTypeCode -->

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

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

                                               <!-- <xsl:comment>Calling the Responsible Party
                                                  Template</xsl:comment> -->
                                                <xsl:text>
</xsl:text>
                                                <xsl:call-template name="FC_CitedResponsibleParty"/>

                                                <xsl:element name="gmd:otherCitationDetails">
                                                  <xsl:element name="gco:CharacterString">
                                                  <!-- URL: Please Insert URL -->
                                                  <xsl:variable name="webSite"
                                                  >http://web8.geo.census.gov:7777/metaFiles/existing/decennial/GEO/GPMB/TIGERline/</xsl:variable>
                                                  <xsl:variable name="onlink"
                                                  select="/metadata/idinfo[1]/citation[1]/citeinfo[1]/onlink[1]"/>
                                                  <xsl:variable name="postTiger"
                                                  select="substring-after($onlink,'tiger')"/>
                                                  <xsl:variable name="postTiger2"
                                                  select="substring-after($postTiger,'/')"/>
                                                  <xsl:variable name="postTiger3"
                                                  select="substring-after($postTiger2,'/')"/>
                                                  <xsl:variable name="filename"
                                                  select="substring-after($postTiger3,'/')"/>
                                                  <xsl:variable name="postDash1"
                                                  select="substring-after($filename,'_')"/>
                                                  <xsl:variable name="year"
                                                  select="substring-before($postDash1,'_')"/>
                                                  <xsl:variable name="postDash2"
                                                  select="substring-after($postDash1,'_')"/>
                                                  <xsl:variable name="postDash3"
                                                  select="substring-after($postDash2,'_')"/>
                                                  <xsl:variable name="theme"
                                                  select="substring-before($postDash3,'.')"/>
                                                  <xsl:variable name="vintage"
                                                  select="concat('TL',$year)"/>
                                                  <xsl:variable name="EAFilename"
                                                  select="concat('ISO_EA_',$year,'_',$theme,'.xml')"/>
                                                  <xsl:variable name="path"
                                                  select="concat($webSite,$vintage,'/','ISO','/',$theme,'/','EAFiles','/',$EAFilename)"/>

                                                  <!--  <xsl:comment> postTiger= <xsl:value-of select="$postTiger"/> </xsl:comment>
        <xsl:comment> postTiger2 = <xsl:value-of select="$postTiger2"/></xsl:comment>
        <xsl:comment> postTiger3 = <xsl:value-of select="$postTiger3"/></xsl:comment>
        <xsl:comment> filename= <xsl:value-of select="$filename"/></xsl:comment>
        <xsl:comment> postDash1 = <xsl:value-of select="$postDash1"/></xsl:comment>
        <xsl:comment> year = <xsl:value-of select="$year"/></xsl:comment>
        <xsl:comment> postDash2 = <xsl:value-of select="$postDash2"/></xsl:comment>
        <xsl:comment> postDash3 = <xsl:value-of select="$postDash3"/></xsl:comment>
        <xsl:comment> theme = <xsl:value-of select="$theme"/></xsl:comment> -->
                                                  <xsl:value-of select="$path"/>
                                                  </xsl:element>
                                                </xsl:element>


                                        </xsl:element>
                                        <!-- CI_Citation -->
                                </xsl:element>
                                <!-- gmd:featureCatalogueCitation -->


                        </xsl:element>
                        <!-- gmd:MD_FeatureCatalogueDescription -->
                </xsl:element>
                <!--  contentInfo -->

        </xsl:template>

        <xsl:template name="includedWithDataset">
                <xsl:choose>

                        <xsl:when test="/metadata/eainfo/detailed">
                                <xsl:element name="gco:Boolean">true</xsl:element>
                        </xsl:when>
                        <xsl:otherwise>
                                <xsl:element name="gco:Boolean">false</xsl:element>
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:template>

        <xsl:template name="featureCatalogueCitationDate">
                <xsl:variable name="MetDate" select="//metadata/metainfo/metd"/>
                <xsl:variable name="year" select="substring($MetDate,1,4)"/>
                <xsl:variable name="month" select="substring($MetDate,5,2)"/>
                <xsl:variable name="monthLength" select="string-length($month)"/>
                <xsl:variable name="day" select="substring($MetDate,7,2)"/>
                <xsl:variable name="dayLength" select="string-length($day)"/>

                <xsl:choose>
                        <xsl:when test="$dayLength>0">

                                <xsl:variable name="dateFormat"
                                        select="concat($year, '-',$month,'-',$day)"/>
                                <xsl:element name="gco:Date">
                                        <xsl:value-of select="$dateFormat"/>
                                </xsl:element>
                        </xsl:when>

                        <xsl:when test="$monthLength >0">
                                <xsl:variable name="dateFormat" select="concat($year, '-',$month)"/>
                                <xsl:element name="gco:Date">
                                        <xsl:value-of select="$dateFormat"/>
                                </xsl:element>
                        </xsl:when>
                        <xsl:otherwise>
                                <xsl:variable name="dateFormat" select="$year"/>
                                <xsl:element name="gco:Date">
                                        <xsl:value-of select="$dateFormat"/>
                                </xsl:element>

                        </xsl:otherwise>
                </xsl:choose>

        </xsl:template>



        <xsl:template name="FC_CitedResponsibleParty">
                 <!-- <xsl:comment>in FC Responsible Party</xsl:comment> -->
                <xsl:variable name="FullOrg" select="/metadata/idinfo/citation/citeinfo/origin"/>
                <xsl:variable name="postComma1" select="substring-after($FullOrg,',')"/>
                <xsl:variable name="division" select="substring-after($postComma1,',')"/>
                <xsl:variable name="finalDivision" select="substring-before($division,' Division')"/>
                <xsl:variable name="finalDivision2" select="substring-before($finalDivision,'g')"/>
                
               <!-- <xsl:comment> The division is:<xsl:value-of select="$finalDivision"/></xsl:comment>
                <xsl:comment> The new division:<xsl:value-of select="$finalDivision2"/>:The
                End</xsl:comment> -->
                
                <xsl:choose>
                        <xsl:when test="$finalDivision =' Geography '">
                                
                                <xsl:attribute name="xlink:href">https://www.ngdc.noaa.gov/docucomp/186104a8-278b-412d-9b61-d4d488142f3c </xsl:attribute>
                                <xsl:attribute name="xlink:title">pointofContact - U.S. Department of Commerce, U.S. Census Bureau, Geography Division</xsl:attribute>
                        </xsl:when>

                        <xsl:when test="$finalDivision2=' Geo' ">
                                <xsl:element name="gmd:citedResponsibleParty">
                                        <xsl:attribute name="xlink:href">https://www.ngdc.noaa.gov/docucomp/186104a8-278b-412d-9b61-d4d488142f3c </xsl:attribute>
                                        <xsl:attribute name="xlink:title">pointofContact - U.S. Department of Commerce, U.S. Census Bureau, Geography Division</xsl:attribute>
                                </xsl:element>
                        </xsl:when>
                        <xsl:otherwise>


                                <xsl:element name="gmd:citedResponsibleParty">
                                        <xsl:element name="gmd:CI_ResponsibleParty">

                                                <xsl:element name="gmd:organisationName">
                                                  <xsl:element name="gco:CharacterString">
                                                  <xsl:value-of
                                                  select="/metadata/idinfo/citation/citeinfo/origin"
                                                  />
                                                  </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:value-of
                                                  select="/metadata/idinfo/ptcontac/cntinfo/cntvoice"
                                                  />
                                                  </xsl:element>
                                                  </xsl:element>
                                                  <!-- gmd:voice -->

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


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

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

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

                                                  <xsl:element name="gmd:deliveryPoint">
                                                  <xsl:element name="gco:CharacterString">
                                                  <xsl:value-of
                                                  select="/metadata/idinfo/ptcontac/cntinfo/cntaddr/address"
                                                  />
                                                  </xsl:element>
                                                  </xsl:element>
                                                  <!-- gmd:deliveryPoint -->

                                                  <xsl:element name="gmd:city">
                                                  <xsl:element name="gco:CharacterString">
                                                  <xsl:value-of
                                                  select="/metadata/idinfo/ptcontac/cntinfo/cntaddr/city"
                                                  />
                                                  </xsl:element>
                                                  </xsl:element>
                                                  <!-- gmd:city -->

                                                  <xsl:element name="gmd:administrativeArea">
                                                  <xsl:element name="gco:CharacterString">
                                                  <xsl:value-of
                                                  select="/metadata/idinfo/ptcontac/cntinfo/cntaddr/state"
                                                  />
                                                  </xsl:element>
                                                  </xsl:element>
                                                  <!-- gmd:administrativeArea -->

                                                  <xsl:element name="gmd:postalCode">
                                                  <xsl:element name="gco:CharacterString">
                                                  <xsl:value-of
                                                  select="/metadata/idinfo/ptcontac/cntinfo/cntaddr/postal"
                                                  />
                                                  </xsl:element>
                                                  </xsl:element>
                                                  <!-- gmd:postalCode -->

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

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

                                                  </xsl:element>
                                                  <!-- gmd:CI_Address -->
                                                  </xsl:element>
                                                  <!-- gmd:address -->

                                                  <xsl:element name="gmd:onlineResource">
                                                  <xsl:element name="gmd:CI_OnlineResource">

                                                  <xsl:element name="gmd:linkage">
                                                  <xsl:element name="gmd:URL"> </xsl:element>
                                                  </xsl:element>
                                                  <!-- gmd:linkage -->


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

                                                  </xsl:element>
                                                  <!-- gmd:CI_Contact -->
                                                </xsl:element>
                                                <!-- gmd:contactInfo -->

                                                <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>
                                                  <!-- gmd:CI_RoleCode -->

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



                                        </xsl:element>
                                        <!-- gmd:CI_ResponsibleParty -->
                                </xsl:element>
                                <!--  citedResponsibleParty -->
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:template>






</xsl:stylesheet>
<!-- End Heere !!!!!!!!!!!!!!!!!!!!!!!!! -->
