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

<xsl:stylesheet version="2.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:gmd="http://www.isotc211.org/2005/gmd" 
    xmlns:gmi="http://www.isotc211.org/2005/gmi" 
    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:xd="http://www.oxygenxml.com/ns/doc/xsl"
    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:vmf="http://www.altova.com/MapForce/UDF/vmf" 
    xmlns:fn="http://www.w3.org/2005/xpath-functions" 
    xmlns:grp="http://www.altova.com/Mapforce/grouping" 
    exclude-result-prefixes="fn grp vmf xs xsi xd xsl" 
    xmlns="http://www.isotc211.org/2005/gmi">
    
    <xd:doc scope="stylesheet">
        <xd:desc>
            <xd:p><xd:b>Created on:</xd:b> Jul 16, 2013</xd:p>
            <xd:p><xd:b>Author:</xd:b> matt</xd:p>
            <xd:p>Parent Title</xd:p>
        </xd:desc>
    </xd:doc>
    
    
    <!--  <xsl:element name="gmd:title">
  <xsl:element name="gco:CharacterString"> <xsl:apply-templates select="//MIF/Title[@section='citation']"/> </xsl:element>
   </xsl:element> -->
    
    <xsl:template name="ParentTitle">
        <xsl:variable name="FullTitle"  select="//MIF/Title[@section='citation']"/> 
        <xsl:variable name="SeriesInfo">Series Information for the</xsl:variable>
        
        <xsl:comment> FullTitle:<xsl:value-of select="$FullTitle"/></xsl:comment>
        
        <xsl:choose>
            <xsl:when test="contains($FullTitle,'county')">
                
                <xsl:variable name="preComma1" select="substring-before($FullTitle,',')"/>
                <xsl:variable name="postComma1" select="substring-after($FullTitle,',')"/>
                <xsl:variable name="year" select="substring-before($postComma1,',')"/>
                <xsl:variable name="postComma2" select="substring-after($postComma1,',')"/>
                <xsl:variable name="postComma3" select=" substring-after($postComma2,',')"/>
                <xsl:variable name="postComma4" select="substring-after($postComma3,',')"/>
                <xsl:variable name="theme" select="substring-after($postComma4,',')"/>
                <xsl:variable name="newTitle" select="concat($preComma1,',',$year,', ',$SeriesInfo,$theme)"/>
                
                
               <!-- <xsl:comment>In the county template</xsl:comment>
                <xsl:comment>precomma1:<xsl:value-of select="$preComma1"/></xsl:comment>
                <xsl:comment>year:<xsl:value-of select="$year"/></xsl:comment>
                <xsl:comment>postComma2:<xsl:value-of select="$postComma2"/></xsl:comment>
                <xsl:comment>postComma3<xsl:value-of select="$postComma3"/></xsl:comment>
                <xsl:comment>postComma4 <xsl:value-of select="$postComma4"/></xsl:comment>
                <xsl:comment>Theme: <xsl:value-of select="$theme"/></xsl:comment> -->
                
                <xsl:element name="gmd:title">
                    <xsl:element name="gco:CharacterString"> <xsl:value-of select="$newTitle"/> </xsl:element>
                </xsl:element>
                
                            </xsl:when>
            <xsl:when test="contains($FullTitle,'state')"> 
                <xsl:variable name="preComma1" select="substring-before($FullTitle,',')"/>
                <xsl:variable name="postComma1" select="substring-after($FullTitle,',')"/>
                <xsl:variable name="year" select="substring-before($postComma1,',')"/>
                <xsl:variable name="postComma2" select="substring-after($postComma1,',')"/>
                <xsl:variable name="postComma3" select=" substring-after($postComma2,',')"/>
                <xsl:variable name="theme" select="substring-after($postComma3,',')"/>
                <xsl:variable name="newTitle" select="concat($preComma1,',',$year,', ',$SeriesInfo,$theme)"/>
                
               <!--  <xsl:comment>precomma1:<xsl:value-of select="$preComma1"/></xsl:comment>
                <xsl:comment>year:<xsl:value-of select="$year"/></xsl:comment>
                <xsl:comment>postComma2:<xsl:value-of select="$postComma2"/></xsl:comment>
                <xsl:comment>postComma3<xsl:value-of select="$postComma3"/></xsl:comment>
                <xsl:comment>Theme: <xsl:value-of select="$theme"/></xsl:comment> 
                <xsl:comment>In the state template</xsl:comment>
               -->
                
                <xsl:element name="gmd:title">
                    <xsl:element name="gco:CharacterString"> <xsl:value-of select="$newTitle"/> </xsl:element>
                </xsl:element>
            
             
                
               
            </xsl:when>
            <xsl:when test="contains($FullTitle,'Nation')"> 
               <xsl:variable name="preComma1" select="substring-before($FullTitle,',')"/>
                <xsl:variable name="postComma1" select="substring-after($FullTitle,',')"/>
                <xsl:variable name="year" select="substring-before($postComma1,',')"/>
                <xsl:variable name="postComma2" select="substring-after($postComma1,',')"/>
                <xsl:variable name="postComma3" select=" substring-after($postComma2,',')"/>
                <xsl:variable name="theme" select="substring-after($postComma3,',')"/>
                <xsl:variable name="newTitle" select="concat($preComma1,',',$year,', ',$SeriesInfo,$theme)"/>
                
                <xsl:element name="gmd:title">
                    <xsl:element name="gco:CharacterString"> <xsl:value-of select="$newTitle"/> </xsl:element>
                </xsl:element>
                
                <xsl:comment>In the nation template</xsl:comment>
            </xsl:when>
        </xsl:choose>
        
    </xsl:template>
</xsl:stylesheet>