<?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> Apr 14, 2014</xd:p>
            <xd:p><xd:b>Author:</xd:b> mccre004</xd:p>
            <xd:p/>
        </xd:desc>
    </xd:doc>

    <xsl:template name="DataQualityID">
        <xsl:variable name="SourceTitle" select="./srccite/citeinfo/title"/>
        <xsl:choose>
            <xsl:when test="contains($SourceTitle,' ')">
                <!-- <xsl:comment>We have spaces!!!!!!!!!!!!!</xsl:comment> -->
                <xsl:variable name="part1" select="substring-before($SourceTitle,' ')"/>
                <xsl:variable name="part2" select="substring-after($SourceTitle, ' ')"/>

                <xsl:variable name="part3" select="substring-before($part2,' ')"/>
                <xsl:variable name="part4" select="substring-after($part2,' ')"/>



                <!-- <xsl:comment>part5:<xsl:value-of select="$part5"/></xsl:comment> -->

                <xsl:choose>
                    <xsl:when test="contains($part4,' ')">
                        <xsl:variable name="part5" select="substring-before($part4,' ')"/>
                        <xsl:variable name="newId" select="concat($part1,$part3,$part5)"/>
                        <xsl:value-of select="$newId"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:variable name="newId" select="concat($part1,$part3,$part4)"/>
                        <xsl:value-of select="$newId"/>
                    </xsl:otherwise>
                </xsl:choose>





                <!--  <xsl:comment>  SourceTitle: <xsl:value-of select="$SourceTitle"/></xsl:comment>
                    <xsl:comment>   Part4 <xsl:value-of select="$part4"/></xsl:comment>
                    <xsl:comment>   part5: <xsl:value-of select="$part5"/></xsl:comment> -->

            </xsl:when>
            <xsl:when test="contains($SourceTitle,'_')">
                <xsl:choose>
                    <xsl:when test="contains($SourceTitle,'19')">
                        <xsl:variable name="PostfirstUnder"
                            select="substring-after($SourceTitle,'_')"/>
                        <xsl:value-of select="$PostfirstUnder"/>

                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$SourceTitle"/>
                    </xsl:otherwise>
                </xsl:choose>

            </xsl:when>
        </xsl:choose>









    </xsl:template>
    
    <xsl:template name="DataQualityGMLID">
        <xsl:variable name="SourceTitle" select="./srccite/citeinfo/title"/>
        <xsl:choose>
            <xsl:when test="contains($SourceTitle,' ')">
                <!-- <xsl:comment>We have spaces!!!!!!!!!!!!!</xsl:comment> -->
                <xsl:variable name="part1" select="substring-before($SourceTitle,' ')"/>
                <xsl:variable name="part2" select="substring-after($SourceTitle, ' ')"/>
                
                <xsl:variable name="part3" select="substring-before($part2,' ')"/>
                <xsl:variable name="part4" select="substring-after($part2,' ')"/>
                
                
                
                <!-- <xsl:comment>part5:<xsl:value-of select="$part5"/></xsl:comment> -->
                
                <xsl:choose>
                    <xsl:when test="contains($part4,' ')">
                        <xsl:variable name="part5" select="substring-before($part4,' ')"/>
                        <xsl:variable name="newId" select="concat($part1,$part3,$part5,'GMLID')"/>
                        <xsl:value-of select="$newId"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:variable name="newId" select="concat($part1,$part3,$part4,'GMLID')"/>
                        <xsl:value-of select="$newId"/>
                    </xsl:otherwise>
                </xsl:choose>
                
                
                
                
                
                <!--  <xsl:comment>  SourceTitle: <xsl:value-of select="$SourceTitle"/></xsl:comment>
                    <xsl:comment>   Part4 <xsl:value-of select="$part4"/></xsl:comment>
                    <xsl:comment>   part5: <xsl:value-of select="$part5"/></xsl:comment> -->
                
            </xsl:when>
            <xsl:when test="contains($SourceTitle,'_')">
                <xsl:choose>
                    <xsl:when test="contains($SourceTitle,'19')">
                        <xsl:variable name="PostfirstUnder"
                            select="substring-after($SourceTitle,'_')"/>
                        <xsl:variable name="FinalPostFirstUnder" select="concat($PostfirstUnder,'GMLID')"/>
                        <xsl:value-of select="$FinalPostFirstUnder"/>
                        
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:variable name="FinalPostFirstUnder" select="concat($SourceTitle,'GMLID')"/>
                        <xsl:value-of select="$FinalPostFirstUnder"/>
                    </xsl:otherwise>
                </xsl:choose>
                
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    
</xsl:stylesheet>
