<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
    exclude-result-prefixes="xd"
    version="1.0">
    <xd:doc scope="stylesheet">
        <xd:desc>
            <xd:p><xd:b>Created on:</xd:b> Jun 10, 2015</xd:p>
            <xd:p><xd:b>Author:</xd:b> mccre004</xd:p>
            <xd:p></xd:p>
        </xd:desc>
    </xd:doc>
    
    <xsl:template name="isPartOf">
        <xsl:variable name="title" select="/MRF/Identification_Information/Citation/Title"/>
        <xsl:choose>
            <xsl:when test="contains($title,'Series Information')"/>
            <xsl:otherwise>
                <!--    <xsl:element name="isPartOf"> -->
                <xsl:variable name="SeriesString">Series Information for the </xsl:variable>
                
                <xsl:choose>
                    <!--         <xsl:when test="contains($title,'Nation')">
                        <xsl:variable name="preComma" select="substring-before($title,',')"/>
                        <xsl:variable name="post" select="substring-after($title,'for')"></xsl:variable>
                        <xsl:variable name="SeriesInfoTitle" select="concat($SeriesString,$preComma,$post)"/>
                        <xsl:value-of select="$SeriesInfoTitle"/>
                        </xsl:when>
                        <xsl:when test="contains($title,'United States')">
                        <xsl:variable name="preComma" select="substring-before($title,',')"/>
                        <xsl:variable name="post" select="substring-after($title,'for')"></xsl:variable>
                        <xsl:variable name="SeriesInfoTitle" select="concat($SeriesString,$preComma,$post)"/>
                        <xsl:value-of select="$SeriesInfoTitle"/>
                        </xsl:when> -->
                    <xsl:when test="contains($title,'State')">
                        
                        <xsl:choose>
                            <xsl:when test="contains($title,'Cartographic')">
                                <xsl:variable name="preComma" select="substring-before($title,',')"/>
                                <xsl:variable name="postState" select="substring-after($title,'State-')"/>
                                <xsl:variable name="preFor" select="substring-before($postState,'for')"/>
                                <xsl:variable name="postFor" select="substring-after($postState,'for')"/>
                                <xsl:variable name="scale" select="substring-after($postFor,',')"/>
                                <xsl:variable name="SeriesInfoTitle" select="concat($SeriesString,'2014 ',$preFor,$scale)"/>
                                <xsl:element name="isPartOf">
                                    <xsl:value-of select="$SeriesInfoTitle"/>
                                </xsl:element>    
                            </xsl:when>
                        </xsl:choose>
                        
                    </xsl:when>
                    <xsl:when test="contains($title,'county')">
                        <xsl:choose>
                            <xsl:when test="contains($title,'TIGER')">
                                <xsl:variable name="preComma" select="substring-before($title,',')"/>
                                <xsl:variable name="postCounty" select="substring-after($title,'county,')"/>
                                <!--   <xsl:comment>post County:<xsl:value-of select="$postCounty"/></xsl:comment>-->
                                <xsl:variable name="postcomma1" select="substring-after($postCounty,',')"/>
                                <xsl:variable name="theme" select="substring-after($postcomma1,',')"/>
                                <!-- <xsl:comment>theme:<xsl:value-of select="$theme"/></xsl:comment>   -->      
                                <xsl:variable name="SeriesInfoTitle" select="concat($SeriesString,'2015 ',$theme)"/>
                                <xsl:element name="isPartOf">
                                    <xsl:value-of select="$SeriesInfoTitle"/>
                                </xsl:element>      
                            </xsl:when>
                        </xsl:choose>
                    </xsl:when>
                </xsl:choose>
                
                <!--  </xsl:element>-->
            </xsl:otherwise>
        </xsl:choose>
        
    </xsl:template>
</xsl:stylesheet>