<?xml version="1.0" encoding="UTF-8"?>
<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">

    <xd:doc scope="stylesheet">
        <xd:desc>
            <xd:p><xd:b>Created on:</xd:b> Jun 21, 2013</xd:p>
            <xd:p><xd:b>Author:</xd:b> Matthew McCready</xd:p>
            <xd:p> This stylesheet was created to replace the 04_gmd_hierarchSet.xsl stylesheet. This was done to implement the latest version of the ISO
            metadata standard: 19115-1, released on May 5, 2013. In this new version, the HierarcyLevel attributes were replaced by the MD_Scope class
            to improve the description of the scope of the metadata. 
            
            The MD_Metadata/hierchyLevel and MD_Metadata/hierchyLevelName elements were moved to the new MD_MetadataScope class in order to avoid ambiguity in
            cases were multiple scope codes and names are associated with a single record. The word hierarchy was dropped from the names because scopes can be 
            used in non-hierarchial structures.
            </xd:p>
        </xd:desc>
    </xd:doc>


    <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>

    <xsl:template name="MD_Scope">

        <xsl:variable name="fullTitle" select="/MIF/Title"/>

        <xsl:element name="mdb:metadataScope">
            <xsl:element name="mdb:MD_MetadataScope">
                <xsl:element name="mdb:resourceCode">
                   
                    <xsl:choose>
                        <xsl:when test="contains($fullTitle,'Series Information File')">
                            <xsl:element name="ci:MD_ScopeCode">
                                <xsl:attribute name="codeList">codeListLocation#MD_ScopeCode</xsl:attribute>
                                <xsl:attribute name="codeListValue">series</xsl:attribute> series
                            </xsl:element>
                        </xsl:when>
                        <xsl:when test="contains($fullTitle,'TIGERweb')">
                            <xsl:element name="ci:MD_ScopeCode">
                                <xsl:attribute name="codeList">codeListLocation#MD_ScopeCode</xsl:attribute>
                                <xsl:attribute name="codeListValue">software</xsl:attribute>
                                software </xsl:element>
                        </xsl:when>
                        <xsl:when test="contains($fullTitle,'Web Map Service')">
                            <xsl:element name="ci:MD_ScopeCode">
                                <xsl:attribute name="codeList">codeListLocation#MD_ScopeCode</xsl:attribute>
                                <xsl:attribute name="codeListValue"> service</xsl:attribute> service
                            </xsl:element>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:element name="ci:MD_ScopeCode">
                                <xsl:attribute name="codeList">codeListLocation#MD_ScopeCode</xsl:attribute>
                                <xsl:attribute name="codeListValue">dataset</xsl:attribute> dataset
                            </xsl:element>
                        </xsl:otherwise>
                    </xsl:choose>

                </xsl:element><!-- mdb:resourceCode -->

                <xsl:element name="mdb:name">
                    <xsl:element name="gco:CharacterString">hierarchyLevelName</xsl:element>
                </xsl:element>
            </xsl:element><!-- mdb:metadataScope -->
            
        </xsl:element><!-- MD_Scope -->
    </xsl:template>
</xsl:stylesheet>
