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

<!--
   Name: ExtraContent.xsl 
   Author:  Matthew J. McCready
   Date:  20120418
   Description:  XSLT stylesheet that provides the correct values for the gmd:featureTypes and gmd:title elements of the gmd:contentInfo section. This stylesheet is called by the 
                 12_gmd:contentInfo.xsl stylesheet.  
   Modification History:
   Date:                          Initials                           Description
   5/10/2012                       MJM                                Added code to insert the correct feature type and correct title for the Entity and Attribute File for TIGER, Cartographic and Censes 
-->

<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="FeatureType">
<xsl:variable name="Theme" select="/metadata/idinfo/citation/citeinfo/title"/>

<!--  <xsl:comment> $theme = <xsl:value-of select="$Theme"/> For the Feature Type </xsl:comment> 
<xsl:text>
</xsl:text> -->
<xsl:choose>


<xsl:when test="contains($Theme,'Census')">
<xsl:variable name="PreTitle" select="substring-after($Theme,'-')"/>
<xsl:variable name="Title" select="substring-before($PreTitle,'for')"/>

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

<xsl:element name="gco:LocalName">
<xsl:attribute name="codeSpace">unknown</xsl:attribute>

<xsl:value-of select="$Title"/>
</xsl:element><!-- gco:LocalName -->

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

</xsl:when>


 <xsl:when test="contains($Theme,'TIGER/Line')">
<!-- <xsl:comment> In the Tiger Feature Type Section </xsl:comment>
<xsl:text>
</xsl:text> -->

<xsl:choose>
    <xsl:when test="contains($Theme,'County')">

<xsl:variable name="PostFirstComma1" select="substring-after($Theme, ',')"/>
       <xsl:variable name ="year" select="substring-before($PostFirstComma1,',')"/>
       <xsl:variable name="PostFirstComma2" select="substring-after($PostFirstComma1,',')"/>
       <xsl:variable name="PostFirstComma3" select="substring-after($PostFirstComma2,',')"/>
       <xsl:variable name="PostFirstComma4" select="substring-after($PostFirstComma3,',')"/>
       <xsl:variable name="PostFirstComma5" select="substring-after($PostFirstComma4,',')"/>
        <xsl:variable name="FinalTheme" select="substring-before($PostFirstComma5,'County')"/>
 <!--      <xsl:variable name="FinalTitle" select="concat($year, ' ' , $PostFirstComma5)"/> -->

<xsl:element name="gmd:featureTypes">
<xsl:element name="gco:LocalName">
<xsl:attribute name="codeSpace">unknown</xsl:attribute>
<xsl:value-of select="$FinalTheme"/>
</xsl:element>
</xsl:element>

<!-- </xsl:when> -->
<!-- </xsl:element> -->
</xsl:when>


 <xsl:when test="contains($Theme,'state')">
<!-- <xsl:comment>in the state section </xsl:comment>
<xsl:text>
</xsl:text> -->

       <xsl:variable name="PostFirstComma1" select="substring-after($Theme,',')"/>
       <xsl:variable name="PostFirstComma2" select="substring-after($PostFirstComma1,',')"/>
       <xsl:variable name ="year" select="substring-before($PostFirstComma1,',')"/>
       <xsl:variable name="PostFirstComma3" select="substring-after($PostFirstComma2,',')"/>
       <xsl:variable name="PostFirstComma4" select="substring-after($PostFirstComma3,',')"/>
<!--       <xsl:variable name="FinalTitle" select="concat($year, ' ',$PostFirstComma4)"/> -->

<xsl:element name="gmd:featureTypes">
<xsl:element name="gco:LocalName">
<xsl:attribute name="codeSpace">unknown</xsl:attribute>
      <xsl:value-of select="$PostFirstComma4"/>
</xsl:element>
     </xsl:element>
      </xsl:when>

<xsl:when test="contains($Theme, 'nation')">
<!--  <xsl:comment> IN the nation - Citation </xsl:comment> 
<xsl:text>
</xsl:text> -->
       <xsl:variable name="PostFirstComma1" select="substring-after($Theme,',')"/>
       <!-- <xsl:comment> PostFirstComma1 <xsl:value-of select="$PostFirstComma1"/></xsl:comment> -->
<xsl:text>
</xsl:text>
       <xsl:variable name="PostFirstComma2" select="substring-after($PostFirstComma1,',')"/>
       <xsl:variable name ="year" select="substring-before($PostFirstComma1,',')"/>
       <xsl:variable name="PostFirstComma3" select="substring-after($PostFirstComma2,',')"/>
       <xsl:variable name="PostFirstComma4" select="substring-after($PostFirstComma3,',')"/>
       <xsl:variable name="FinalTheme" select="substring-before($PostFirstComma4,'National')"/> 
      <!--  <xsl:variable name="FinalTitle" select="concat('Feature Catalog for',$year, ' ', $PostFirstComma4)"/> -->

<xsl:element name="gmd:featureTypes">
<xsl:element name="gco:LocalName">
<xsl:attribute name="codeSpace">unknown</xsl:attribute>
      <xsl:value-of select="$FinalTheme"/>
</xsl:element>
     </xsl:element>

      </xsl:when>
</xsl:choose>

</xsl:when>


<xsl:when test="contains($Theme,'Cartographic')">
<xsl:variable name="PreTitle" select="substring-after($Theme,'-')"/>
<xsl:variable name="Title" select="substring-before($PreTitle,'for')"/>
<xsl:variable name="type" select="substring-before($Theme,',')"/>
<xsl:variable name="first" select="substring-after($Theme,',')"/>
<xsl:variable name="EAyear" select="substring-before($first,',')"/>
<xsl:variable name="second" select="substring-after($first,',')"/>
<xsl:variable name="third" select="substring-after($second,',')"/>
<xsl:variable name="fourth" select="substring-after($third,',')"/>
<xsl:variable name="finalTheme" select="substring-after($fourth,',')"/>
<xsl:variable name="featureTypeA" select="substring-after($Theme, 'File,')"/>
<xsl:variable name="featureTypeB" select="substring-before($featureTypeA, ',')"/> 
<xsl:variable name="featureType"  select="substring-before($featureTypeB,'for')"/>
<xsl:variable name="finalTitle" select="concat($EAyear, ' ', $type, $finalTheme)"/>

<xsl:element name="gmd:featureTypes">
<xsl:element name="gco:LocalName">
<xsl:attribute name="codeSpace">unknown</xsl:attribute>
<xsl:value-of select="$featureType"/>
</xsl:element>
</xsl:element>

</xsl:when> 

<xsl:otherwise>
<xsl:element name="gmd:featureTypes">
<xsl:element name="gco:LocalName">
<xsl:attribute name="codeSpace">unknown</xsl:attribute> 
<!-- <xsl:attribute name="nilReason">missing </xsl:attribute> -->
 </xsl:element> 
</xsl:element>
</xsl:otherwise>

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










<xsl:template name="ContentTitle">
<xsl:text>
</xsl:text>
<!-- <xsl:comment> In the Content Title Template (For the Title of the Feature Catolog ) </xsl:comment> -->
<xsl:text>
</xsl:text>
<xsl:variable name="FeatureCatolog">Feature Catolog for the</xsl:variable>
<xsl:variable name="Theme" select="/metadata/idinfo/citation/citeinfo/title"/>

<xsl:choose>

<xsl:when test="contains($Theme,'Census')">
<xsl:variable name="PreTitle" select="substring-after($Theme,'-')"/>
<xsl:variable name="TitleA" select="substring-before($PreTitle,'for')"/>
<xsl:variable name="Title" select="concat($FeatureCatolog, $TitleA)"/>
<xsl:element name="gmd:title">
<xsl:element name="gco:CharacterString">   <xsl:value-of select="$Title"/> </xsl:element> 
</xsl:element> 
</xsl:when>

<xsl:when test="contains($Theme,'Cartographic')">
<xsl:variable name="type" select="substring-before($Theme,',')"/>
<xsl:variable name="EAyear" select="substring-before($Theme,'Cartographic')"/>
<xsl:variable name="second" select="substring-after($Theme,',')"/>
<xsl:variable name="finalTheme" select="substring-before($second,'for')"/>
<xsl:variable name="finalTitle" select="concat($FeatureCatolog,' ', $EAyear, $finalTheme)"/>
<xsl:element name="gmd:title">
<xsl:element name="gco:CharacterString">   <xsl:value-of select="$finalTitle"/> </xsl:element> 
</xsl:element> 
</xsl:when>

 <xsl:when test="contains($Theme,'TIGER')">
<!-- <xsl:comment> In the Title Tiger Section (Try Two) </xsl:comment> 
<xsl:text>
</xsl:text> -->
<!-- <xsl:comment> Theme = <xsl:value-of select="$Theme"/> </xsl:comment>
<xsl:text>
</xsl:text> -->


<xsl:choose>
    <xsl:when test="contains($Theme,'County')">
<!-- <xsl:comment>In the county section</xsl:comment> 
<xsl:text>
</xsl:text> -->

<xsl:variable name="PostFirstComma1" select="substring-after($Theme, ',')"/>
       <xsl:variable name ="year" select="substring-before($PostFirstComma1,',')"/>
       <xsl:variable name="PostFirstComma2" select="substring-after($PostFirstComma1,',')"/>
       <xsl:variable name="PostFirstComma3" select="substring-after($PostFirstComma2,',')"/>
       <xsl:variable name="PostFirstComma4" select="substring-after($PostFirstComma3,',')"/>
       <xsl:variable name="PostFirstComma5" select="substring-after($PostFirstComma4,',')"/>
      <xsl:variable name="FinalTitle" select="concat($FeatureCatolog, ' ', $year, ' ' , $PostFirstComma5)"/> 

<xsl:element name="gmd:title">
<xsl:element name="gco:CharacterString">

<xsl:value-of select="$FinalTitle"/>
</xsl:element>
</xsl:element>
</xsl:when> 


 <xsl:when test="contains($Theme,'state')">
<!-- <xsl:comment>in the state section </xsl:comment> 
<xsl:text>
</xsl:text>  -->

       <xsl:variable name="PostFirstComma1" select="substring-after($Theme,',')"/>
       <xsl:variable name="PostFirstComma2" select="substring-after($PostFirstComma1,',')"/>
       <xsl:variable name ="year" select="substring-before($PostFirstComma1,',')"/>
       <xsl:variable name="PostFirstComma3" select="substring-after($PostFirstComma2,',')"/>
       <xsl:variable name="PostFirstComma4" select="substring-after($PostFirstComma3,',')"/>
       <xsl:variable name="FinalTitle" select="concat($FeatureCatolog, $year, $PostFirstComma4)"/> 
<xsl:element name="gmd:title">
<xsl:element name="gco:CharacterString">
      <xsl:value-of select="$FinalTitle"/>
     </xsl:element>
</xsl:element>
      </xsl:when> 

<xsl:when test="contains($Theme, 'nation')">
<!--  <xsl:comment> IN the nation - Citation </xsl:comment> 
<xsl:text>
</xsl:text> -->
       <xsl:variable name="PostFirstComma1" select="substring-after($Theme,',')"/>
       <!-- <xsl:comment> PostFirstComma1 <xsl:value-of select="$PostFirstComma1"/></xsl:comment> -->
<xsl:text>
</xsl:text>
       <xsl:variable name="PostFirstComma2" select="substring-after($PostFirstComma1,',')"/>
       <xsl:variable name ="year" select="substring-before($PostFirstComma1,',')"/>
       <xsl:variable name="PostFirstComma3" select="substring-after($PostFirstComma2,',')"/>
       <xsl:variable name="PostFirstComma4" select="substring-after($PostFirstComma3,',')"/>
       <xsl:variable name="FinalTitle" select="concat('Feature Catalog for',$year, ' ', $PostFirstComma4)"/>
<xsl:element name="gmd:title">
<xsl:element name="gco:CharacterString">
      <xsl:value-of select="$FinalTitle"/>
     </xsl:element>
 </xsl:element>
      </xsl:when>


 </xsl:choose> 

</xsl:when> 

<xsl:when test="contains($Theme, 'nation')">
<!--  <xsl:comment> IN the nation - Citation </xsl:comment> -->
<xsl:text>
</xsl:text>
       <xsl:variable name="PostFirstComma1" select="substring-after($Theme,',')"/>
        <!--  <xsl:comment> PostFirstComma1 <xsl:value-of select="$PostFirstComma1"/></xsl:comment> -->
<xsl:text>
</xsl:text>
       <xsl:variable name="PostFirstComma2" select="substring-after($PostFirstComma1,',')"/>
       <xsl:variable name ="year" select="substring-before($PostFirstComma1,',')"/>
       <xsl:variable name="PostFirstComma3" select="substring-after($PostFirstComma2,',')"/>
       <xsl:variable name="PostFirstComma4" select="substring-after($PostFirstComma3,',')"/>
       <xsl:variable name="FinalTitle" select="concat('Feature Catalog for',$year, ' ', $PostFirstComma4)"/>

<xsl:element name="gco:CharacterString">
      <xsl:value-of select="$FinalTitle"/>
     </xsl:element>
      </xsl:when>


<!-- </xsl:when> -->
<!-- </xsl:element> -->
<!-- </xsl:when>

</xsl:choose>






</xsl:when> -->


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


</xsl:stylesheet>

