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

<!--
   Name:  03B_gmd_parentIdentifier.xsl
   Author:  Matthew J. McCready
   Date:  20121219
   Description:  XSLT stylesheet that insert the parentIdentifier element. It is done based on the title
   Modification History:
      Initial   Date      Change Request ID   Description

-->




<xsl:stylesheet version="1.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: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"
   xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" xmlns:fn="http://www.w3.org/2005/xpath-functions"
   xmlns:grp="http://www.altova.com/Mapforce/grouping"
   xmlns:mdb="	http://www.isotc211.org/schemas/2012/mdb"
   xmlns:ci="http://www.isotc211.org/schemas/2012/ci" exclude-result-prefixes="fn grp xs xsi xsl xd"
   xmlns="http://www.isotc211.org/2005/gfc">




   <xsl:template name="parentIdentifier" match="/">

      <xsl:comment> This part represents a link to the Series Collection File </xsl:comment>
      <!--  <xsl:comment> in the parentIdentifier template </xsl:comment> -->


      <xsl:variable name="CollectString">Series Information for the </xsl:variable>
      <xsl:variable name="Title" select="/MIF/Title[@section='citation']"/>

     <!--  <xsl:comment>The title is: <xsl:value-of select="$Title"/> 
      </xsl:comment>-->
      <xsl:choose>
         <xsl:when test="contains($Title,'TIGER/Line')">
            <xsl:variable name="PreComma" select="substring-before($Title, ',')"/>
            <xsl:variable name="PostComma" select="substring-after($Title, ',')"/>
            <xsl:variable name="PreFor" select="substring-before($PostComma, ' for')"/>
            <xsl:variable name="PostCommaB" select="substring-after($PostComma, ',')"/>
            <xsl:variable name="WholeTitle"
               select="concat($CollectString, $PreComma,',', $PreFor,',', $PostCommaB)"/>

          <!--  <xsl:comment>The Value of PreComma is <xsl:value-of select="$PreComma"/>
            </xsl:comment>
            <xsl:comment>The Value of PostComma is <xsl:value-of select="$PostComma"/>
            </xsl:comment>
            <xsl:comment>The Value of PreFor is <xsl:value-of select="$PreFor"/></xsl:comment>
            <xsl:comment>The Value of PostCommaB <xsl:value-of select="$PostCommaB"/></xsl:comment>
            <xsl:comment>The Value of WholeTitle <xsl:value-of select="$WholeTitle"/>
            </xsl:comment> -->

            <xsl:element name="gmd:parentIdentifier">
               <xsl:element name="gco:CharacterString">
                  <xsl:value-of select="$WholeTitle"/>
               </xsl:element>
            </xsl:element>

         </xsl:when>
         <xsl:when test="contains($Title,'Maps')">
            <xsl:variable name="PreFor" select="substring-before($Title,'for')"/>
            
            <xsl:comment>The Value of PreFor is <xsl:value-of select="$PreFor"/>
            </xsl:comment>

            <xsl:choose>
               <xsl:when test="contains($Title,'(')">
                  <xsl:variable name="par" select="substring-after($Title,'(')"></xsl:variable>
                  <xsl:variable name="WholeTitle" select="concat($CollectString,$PreFor, '(',$par)"/>
                  <xsl:element name="mdb:parentIdentifier">
                     <xsl:element name="gco:CharacterString">
                        <xsl:value-of select="$WholeTitle"/>
                     </xsl:element>
                  </xsl:element>
               </xsl:when>
            </xsl:choose>
         </xsl:when>
         
         <xsl:when test="contains($Title,'Cartographic Boundary File')">
            <xsl:variable name="yearCartTheme" select="substring-before($Title, 'for')"/>
            <xsl:variable name="postFor" select="substring-after($Title,'for')"/>
            <xsl:variable name="scale" select="substring-after($postFor,',')"/>
            <xsl:variable name="WholeTitle" select="concat($CollectString,$yearCartTheme,',',$scale)"/>
            
            <!-- <xsl:comment>yearCartTheme:<xsl:value-of select="$yearCartTheme"/></xsl:comment>
            <xsl:comment>postFor<xsl:value-of select="$postFor"/></xsl:comment> -->
            
            <xsl:element name="gmd:parentIdentifier">
               <xsl:element name="gco:CharacterString">
                  <xsl:value-of select="$WholeTitle"/>
               </xsl:element>
            </xsl:element>
         </xsl:when>
            
         
      </xsl:choose>



   </xsl:template>
</xsl:stylesheet>
