<?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:

-->

<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="FeatureCatolog">Feature Catolog for the</xsl:variable>
<xsl:variable name="Theme" select="/MIF/Title"/>

<xsl:choose>


<xsl:when test="contains($Theme,'Census')">
<!-- <xsl:comment> IN the new when </xsl:comment> -->
<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: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="featureType" select="substring-before($finalTheme, 'County')"/>
<xsl:variable name="finalTitle" select="concat($FeatureCatolog, $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:comment> IN the old when </xsl:comment> -->
</xsl:element><!-- gco:LocalName -->

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

</xsl:when>

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



<xsl:template name="ContentTitle">
   <!-- <xsl:comment>In the ContentTitle template</xsl:comment> -->
<xsl:variable name="FeatureCatolog">Feature Catalog for the</xsl:variable>
<xsl:variable name="Theme" select="/MIF/Title"/>

<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:title">
<xsl:element name="gco:CharacterString">   <xsl:value-of select="$Title"/> </xsl:element> <!-- gco:CharacterString -->
</xsl:element> <!-- gmd:title -->
</xsl:when>

<xsl:when test="contains($Theme,'County')">
<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="featureType" select="substring-before($finalTheme, 'County')"/>
<xsl:variable name="finalTitle" select="concat($FeatureCatolog, $EAyear, ' ', $type, $finalTheme)"/>

<xsl:element name="gmd:title">
<xsl:element name="gco:CharacterString">   <xsl:value-of select="$finalTitle"/> </xsl:element> <!-- gco:CharacterString -->

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


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

</xsl:stylesheet>
