<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.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:gmd="http://www.isotc211.org/2005/gmd"
    xmlns:gmi="http://www.isotc211.org/2005/gmi" 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:gfc="http://www.isotc211.org/2005/gfc" xmlns:vmf="http://www.altova.com/MapForce/UDF/vmf"
    xmlns:fn="http://www.w3.org/2005/xpath-functions"
    xmlns:grp="http://www.altova.com/Mapforce/grouping"
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
    exclude-result-prefixes="fn grp vmf xs xsi xsl xd" xmlns="http://www.isotc211.org/2005/gmi">
    <xd:doc scope="stylesheet">
        <xd:desc>
            <xd:p><xd:b>Created on:</xd:b> Jan 2, 2014</xd:p>
            <xd:p><xd:b>Author:</xd:b> mccre004</xd:p>
            <xd:p/>
        </xd:desc>
    </xd:doc>
    <xsl:template name="carrierOfCharacteristicsDefault">



        <xsl:for-each select="/MRF/Entity_and_Attribute_Information/Detailed_Description/Attribute">


            <xsl:element name="gfc:carrierOfCharacteristics">
                <xsl:element name="gfc:FC_FeatureAttribute">

                    <xsl:if test="./Attribute_Label">
                        <xsl:element name="gfc:memberName">
                            <xsl:element name="gco:LocalName">
                                <xsl:value-of select="./Attribute_Label"/>
                            </xsl:element>
                        </xsl:element>

                        <xsl:element name="gfc:definition">
                            <xsl:element name="gco:CharacterString">
                                <xsl:value-of select="./Attribute_Definition"/>
                            </xsl:element>
                        </xsl:element>

                        <xsl:element name="gfc:cardinality">
                            <xsl:attribute name="gco:nilReason">unknown</xsl:attribute>
                        </xsl:element>
                        <xsl:variable name="defSource" select="./Attribute_Definition_Source"/>
                        <xsl:choose>

                            <xsl:when test="contains($defSource,'Census')">
                                <xsl:element name="gfc:definitionReference">
                                    <xsl:attribute name="xlink:title">U.S. Census Bureau</xsl:attribute>
                                    <xsl:attribute name="xlink:href"
                                        >http://www.ngdc.noaa.gov/docucomp/eb139e38-ee29-4d59-b157-5e874d4420c4</xsl:attribute>
                                </xsl:element>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:element name="gfc:definitionReference">
                                    <xsl:element name="gfc:definitionSource">
                                        <xsl:element name="gfc:FC_DefinitionSource">
                                            <xsl:element name="gfc:source">
                                                <xsl:element name="gmd:CI_Citation">

                                                  <xsl:element name="gmd:title">
                                                  <xsl:attribute name="gco:nilReason"
                                                  >inapplicable</xsl:attribute>
                                                  </xsl:element>

                                                  <xsl:element name="gmd:date">
                                                  <xsl:attribute name="gco:nilReason"
                                                  >unknown</xsl:attribute>
                                                  </xsl:element>

                                                  <xsl:element name="gmd:citedResponsibleParty">
                                                  <xsl:element name="gmd:CI_ResponsibleParty">

                                                  <xsl:element name="gmd:organisationName">
                                                  <xsl:element name="gco:CharacterString"
                                                  > </xsl:element>
                                                  </xsl:element>

                                                  <xsl:element name="gmd:role">
                                                  <xsl:element name="gmd:CI_RoleCode">
                                                  <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_RoleCode</xsl:attribute>
                                                  <xsl:attribute name="codeListValue"
                                                  >resourceProvider</xsl:attribute>
                                                  <xsl:attribute name="codeSpace"
                                                  >001</xsl:attribute>resourceProvider
                                                  </xsl:element>
                                                  </xsl:element>
                                                  </xsl:element>
                                                  </xsl:element>
                                                </xsl:element>
                                            </xsl:element>
                                        </xsl:element>
                                    </xsl:element>
                                </xsl:element>
                            </xsl:otherwise>
                        </xsl:choose>
                        
                        <xsl:for-each select="./Attribute_Domain_Values/Codeset_Domain">
                            <xsl:element name="gfc:FC_ListedValue">
                                <xsl:element name="gfc:label">
                                    <xsl:element name="gco:CharacterString"><xsl:value-of select="./Codeset_Name"/></xsl:element>
                                </xsl:element>
                                <xsl:variable name="defSourceCodeset" select="./Codeset_Source"></xsl:variable>
                                <xsl:choose>
                                    
                                    <xsl:when test="contains($defSourceCodeset,'Census')">
                                        <xsl:element name="gfc:definitionReference">
                                            <xsl:attribute name="xlink:title">U.S. Census
                                                Bureau</xsl:attribute>
                                            <xsl:attribute name="xlink:href"
                                                >http://www.ngdc.noaa.gov/docucomp/eb139e38-ee29-4d59-b157-5e874d4420c4</xsl:attribute>
                                        </xsl:element>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:element name="gfc:definitionReference">
                                            <xsl:element name="gfc:definitionSource">
                                                <xsl:element name="gfc:FC_DefinitionSource">
                                                    <xsl:element name="gfc:source">
                                                        <xsl:element name="gmd:CI_Citation">
                                                            
                                                            <xsl:element name="gmd:title">
                                                                <xsl:attribute name="gco:nilReason"
                                                                    >inapplicable</xsl:attribute>
                                                            </xsl:element>
                                                            
                                                            <xsl:element name="gmd:date">
                                                                <xsl:attribute name="gco:nilReason"
                                                                    >unknown</xsl:attribute>
                                                            </xsl:element>
                                                            
                                                            <xsl:element name="gmd:citedResponsibleParty">
                                                                <xsl:element name="gmd:CI_ResponsibleParty">
                                                                    
                                                                    <xsl:element name="gmd:organisationName">
                                                                        <xsl:element name="gco:CharacterString"
                                                                            > </xsl:element>
                                                                    </xsl:element>
                                                                    
                                                                    <xsl:element name="gmd:role">
                                                                        <xsl:element name="gmd:CI_RoleCode">
                                                                            <xsl:attribute name="codeList"
                                                                                >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_RoleCode</xsl:attribute>
                                                                            <xsl:attribute name="codeListValue"
                                                                                >resourceProvider</xsl:attribute>
                                                                            <xsl:attribute name="codeSpace"
                                                                                >001</xsl:attribute>resourceProvider
                                                                        </xsl:element>
                                                                    </xsl:element>
                                                                </xsl:element>
                                                            </xsl:element>
                                                        </xsl:element>
                                                    </xsl:element>
                                                </xsl:element>
                                            </xsl:element>
                                        </xsl:element>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:element>
                        </xsl:for-each>

                    </xsl:if>
                </xsl:element>
            </xsl:element>

        </xsl:for-each>




    </xsl:template>






    <!-- <xsl:template name="gfcDefinitionReference">
        <xsl:element name="gfc:definitionReference">
            <xsl:element name="gfc:definitionSource">
                <xsl:element name="gfc:FC_DefinitionSource">
                    <xsl:element name="gfc:source"> 
                        <xsl:element name="gmd:CI_Citation">
                            
                            <xsl:element name="gmd:title">
                                <xsl:attribute name="gco:nilReason">inapplicable</xsl:attribute>
                            </xsl:element>
                            
                            <xsl:element name="gmd:date">
                                <xsl:attribute name="gco:nilReason">unknown</xsl:attribute>
                            </xsl:element>
                            
                            <xsl:element name="gmd:citedResponsibleParty">
                                <xsl:element name="gmd:CI_ResponsibleParty">
                                    
                                    <xsl:element name="gmd:organisationName">
                                        <xsl:element name="gco:CharacterString"> <xsl:value-of select="/MIF/Attribute_Definition_Source[]"></xsl:value-of></xsl:element>     
                                    </xsl:element>
                                </xsl:element>
                            </xsl:element>
                            
                        </xsl:element>
                    </xsl:element>
                </xsl:element>
            </xsl:element>
        </xsl:element>
    </xsl:template> -->


</xsl:stylesheet>
