<?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">
    <xsl:include href="../SeriesCollectionXSDs/NationalAbstracts.xsl"></xsl:include>
    <xd:doc scope="stylesheet">
        <xd:desc>
            <xd:p><xd:b>Created on:</xd:b> Apr 2, 2013</xd:p>
            <xd:p><xd:b>Author:</xd:b> mccre004</xd:p>
            <xd:p></xd:p>
        </xd:desc>
    </xd:doc>
    
    <xsl:template name="NewAbstracts">
        
        <xsl:variable name="WholeTitle" select="/metadata/idinfo/citation/citeinfo/title"/>
        <xsl:variable name="postComma1" select="substring-after($WholeTitle,',')"></xsl:variable>
        <xsl:variable name="postComma2" select="substring-after($postComma1,',')"></xsl:variable>
        <xsl:variable name="geoLevel" select="substring-before($postComma2,',')"></xsl:variable>
        <xsl:variable name="postgeoLevel" select="substring-after($geoLevel,' ')"></xsl:variable>
        <xsl:variable name="postgeoLevel2" select="substring-after($postgeoLevel,' ')"> </xsl:variable>
        
      <xsl:comment> The title is: <xsl:value-of select="$WholeTitle"/></xsl:comment>
        <xsl:comment>postComma1= <xsl:value-of select="$postComma1"/> </xsl:comment>
        <xsl:comment> postComma2 = <xsl:value-of select="$postComma2"/></xsl:comment>
        <xsl:comment> postFeoLevel<xsl:value-of select="$postgeoLevel"/></xsl:comment>
        <xsl:comment>postgeoLevel2<xsl:value-of select="$postgeoLevel2"/> </xsl:comment>
        <xsl:comment> The level of Geography is: <xsl:value-of select="$geoLevel"/></xsl:comment> 
        
        <xsl:choose>
            <xsl:when test="$postgeoLevel='nation'">
              <xsl:comment>in the First nation</xsl:comment> 
                <xsl:variable name="postComma3" select="substring-after($postComma2,',')"/>
                <xsl:variable name="preTheme" select="substring-after($postComma3,',')"/>
                <xsl:variable name="Theme" select="substring-before($preTheme, 'National')"/>
                <xsl:variable name="PostTheme" select="substring-after($Theme,' ')"/>
                <xsl:variable name="currentCheck" select="substring-before($PostTheme,'/')"/>
                <xsl:variable name="thCheck" select="substring-after($PostTheme,'th')"/>
                <xsl:variable name="thCheck2" select="substring-after($thCheck,' ')"></xsl:variable>
                <xsl:variable name="thCheck3" select="substring-before($thCheck2,' ')"></xsl:variable>
                <xsl:variable name="postPar" select="substring-after($PostTheme,'(')"> </xsl:variable>
                
                <xsl:comment> postComma 3 = <xsl:value-of select="$postComma3"/></xsl:comment>
                <xsl:comment> <xsl:value-of select="$preTheme"/></xsl:comment>
                <xsl:comment>The theme is:<xsl:value-of select="$Theme"/></xsl:comment>
               <xsl:comment> The post Theme is:<xsl:value-of select="$PostTheme"/></xsl:comment>
                <xsl:comment>currentCheck:<xsl:value-of select="$currentCheck"/></xsl:comment>
                <xsl:comment> thCheck=<xsl:value-of select="$thCheck"/></xsl:comment>
                <xsl:comment> thCheck2 <xsl:value-of select="$thCheck2"/></xsl:comment>
                <xsl:comment> thCheck3:<xsl:value-of select="$thCheck3"/> </xsl:comment>
                <xsl:comment>postPar:<xsl:value-of select="$postPar"/></xsl:comment>
                
                <xsl:choose>
                    <xsl:when test="$PostTheme='Rails '">
                        <xsl:comment> in the rails</xsl:comment>
                        <xsl:call-template name="rails"/>
                    </xsl:when>
                    <xsl:when test="$currentCheck='Current American Indian'">
                        <xsl:comment> in the AAiNNH</xsl:comment>
                        <xsl:call-template name="AAINH"/>
                    </xsl:when>
                    
                    <xsl:when test="$currentCheck ='Current Metropolitan Statistical Area'">
                        <xsl:comment>In the CBSA</xsl:comment>
                        <xsl:call-template name="cbsa"/>
                    </xsl:when>
                    <xsl:when test="$thCheck3='Congressional'">
                        <xsl:comment>IN Congress !!!!!!!!!!</xsl:comment>
                        <xsl:call-template name="congress"/>
                    </xsl:when>
                    <xsl:when test="$postPar='CNECTA) '">
                        <xsl:comment>CNECTA</xsl:comment>
                    </xsl:when>
                </xsl:choose>
                
                
            </xsl:when>
            <xsl:when test="$postgeoLevel=' nation'">
                <xsl:comment>Second Nation</xsl:comment>
                <xsl:variable name="postComma3" select="substring-after($postComma2,',')"/>
                <xsl:variable name="preTheme" select="substring-after($postComma3,',')"/>
                <xsl:variable name="Theme" select="substring-before($preTheme, 'National')"/>
                <xsl:variable name="PostTheme" select="substring-after($Theme,' ')"/>
                <xsl:variable name="currentCheck" select="substring-before($PostTheme,'/')"/>
                <xsl:variable name="thCheck" select="substring-after($PostTheme,'th')"/>
                <xsl:variable name="thCheck2" select="substring-after($thCheck,' ')"></xsl:variable>
                <xsl:variable name="thCheck3" select="substring-before($thCheck2,' ')"></xsl:variable>
                
                <xsl:comment> postComma 3 = <xsl:value-of select="$postComma3"/></xsl:comment>
                <xsl:comment> <xsl:value-of select="$preTheme"/></xsl:comment>
                <xsl:comment>The theme is:<xsl:value-of select="$Theme"/></xsl:comment>
                <xsl:comment> The post Theme is:<xsl:value-of select="$PostTheme"/></xsl:comment>
                <xsl:comment>currentCheck:<xsl:value-of select="$currentCheck"/></xsl:comment>
                <xsl:comment> thCheck=<xsl:value-of select="$thCheck"/></xsl:comment>
                <xsl:choose>
                    <xsl:when test="$PostTheme='Current American Indian Tribal Subdivision (AITS) '">
                        <xsl:comment>in the AITS</xsl:comment>
                        <xsl:call-template name="aitsn"/>
                    </xsl:when>
                    <xsl:when test="$currentCheck ='Current Metropolitan Statistical Area'">
                        <xsl:comment>In the CBSA</xsl:comment>
                        <xsl:call-template name="cbsa"/>
                    </xsl:when>
                    <!--<xsl:when test="$PostTheme='Current Metropolitan Statistical Area/Micropolitan Statistical Area (CBSA) '">
                        <xsl:comment>In the CBSA</xsl:comment>
                        <xsl:call-template name="cbsa"/>
                        </xsl:when> -->
                    <xsl:when test="$thCheck3='Congressional'">
                        <xsl:comment>IN Congress !!!!!!!!!!</xsl:comment>
                        <xsl:call-template name="congress"/>
                    </xsl:when>
                </xsl:choose>
            </xsl:when> 
            <xsl:when test="$geoLevel='  state'">
              <xsl:comment> in the state</xsl:comment>  
            </xsl:when>
            <xsl:when test="$geoLevel='  county'">
                <xsl:comment> in the county</xsl:comment>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    
    
</xsl:stylesheet>