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


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
    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"
    exclude-result-prefixes="xd"
    >

    <xd:doc scope="stylesheet">
        <xd:desc>
            <xd:p><xd:b>Created on:</xd:b> Dec 11, 2013</xd:p>
            <xd:p><xd:b>Author:</xd:b> mccre004</xd:p>
            <xd:p/>
        </xd:desc>
    </xd:doc>

    <xsl:template name="MetadataParentTitle">
        <!-- Series Information File for the 2012 Cartographic Boundary File, State-Congressional District (113th), 1:500,000 -->
        <!-- 2012 Cartographic Boundary File, 2013 State-State Legislative District (Lower Chamber) for California, 1:500,000 -->
        
        <!-- county shapefile -->
        <!-- TIGER/Line Shapefile, 2013, county, Autauga County, AL, Address Range-Feature County-based -->
        <!-- TIGER/Line Shapefile, 2013, Series Information for the Address Range-Feature County-based 
            TIGER/Line Shapefile 2013Series Information File for the  Current Block Group State-based
        -->
        
        <!-- state shapefile -->
        <!--  TIGER/Line Shapefile, 2013, state, Alabama, Current Block Group State-based-->
        <!--  TIGER/Line Shapefile, 2013, Series Information for the Current Block Group State-based-->
        
        <!-- national -->
        <!-- TIGER/Line Shapefile, 2013, nation, U.S., Rails National Shapefile -->
        <xsl:variable name="BeginingOfTitle">Series Information File for the </xsl:variable>
        <xsl:element name="gmd:title">
               <xsl:element name="gco:CharacterString">
                   <xsl:variable name="mifTitle" select="//MIF/Title[@section='citation']"/>
                   <xsl:variable name="hasCarto" select="contains($mifTitle,'Cartographic Boundary File')"/>
                   <xsl:variable name="hasTiger" select="contains($mifTitle,'TIGER/Line Shapefile')"/>
                   <xsl:choose>
                       <xsl:when test="$hasCarto='true'">
                           <xsl:variable name="preFor" select="substring-before($mifTitle,'for')"/>
                           <xsl:variable name="postFor" select="substring-after($mifTitle,'for')"/>
                           <xsl:variable name="scale" select="substring-after($postFor,',')"/>
                           <xsl:variable name="newTitle" select="concat($BeginingOfTitle,$preFor,',',$scale)"/>
                           <xsl:value-of select="$newTitle"/>
                           
                       </xsl:when>
                       <xsl:when test="$hasTiger='true'">
                           <xsl:comment>In the TIGER section!!!!!!!!!!!!!!!!!!!!!!!!!!!</xsl:comment>
                           <xsl:variable name="TigerBegining" select="substring-before($mifTitle,',')"/>
                           <xsl:variable name="postTiger" select="substring-after($mifTitle,',')"/>
                           <xsl:variable name="year" select="substring-before($postTiger,',')"/>
                           <xsl:variable name="postYear" select="substring-after($postTiger,',')"/>
                           <xsl:variable name="postYear1" select="substring-after($postYear,',')"/>
                           <xsl:variable name="theme" select="substring-after($postYear1,',')"/>
                           <xsl:variable name="newTitle" select="concat($TigerBegining,',',$year, ', ',$BeginingOfTitle, $theme)"/>
                           <xsl:value-of select="$newTitle"/>
                       </xsl:when>
                       <xsl:otherwise>
                           <xsl:comment>In the otherwise</xsl:comment>
                       </xsl:otherwise>
                   </xsl:choose>
                   
                   
               
            </xsl:element>
        </xsl:element>
        <xsl:if test="/MRF/Identification_Information/Citation/Alternate_Title">
        <xsl:element name="Alternate_Title">
            <xsl:element name="gco:CharacterString"> <xsl:value-of select="/MRF/Identification_Information/Citation/Alternate_Title"/> </xsl:element>
        </xsl:element></xsl:if>
    </xsl:template>
</xsl:stylesheet>
