<?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: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:fn="http://www.w3.org/2005/xpath-functions" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
    xmlns:grp="http://www.altova.com/Mapforce/grouping"
    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> May 16, 2013</xd:p>
            <xd:p><xd:b>Author:</xd:b> mccre004</xd:p>
            <xd:p/>
        </xd:desc>
    </xd:doc>
    <xsl:template name="FC_FeatureAttribute">
        <gfc:FC_FeatureAttribute>
            <xsl:comment> in the FC_FeatureAttribute Template!!!!!!</xsl:comment>
            <xsl:for-each select="/metadata/eainfo/detailed/attr">
                <xsl:for-each select="attrdomv/rdom">
                    <xsl:variable name="var62_rdom" as="node()" select="."/>
                    <gfc:constrainedBy>
                        <gfc:FC_Constraint>
                            <gfc:description>
                                <xsl:variable name="var64_cond_result_exists" as="xs:string?"
                                    select="(if (fn:exists(rdommin)) then 'Range Domain Min: ' else ())"/>
                                <xsl:if test="fn:exists($var64_cond_result_exists)">
                                    <xsl:for-each select="rdommin">
                                        <xsl:variable name="var65_rdommin" as="node()" select="."/>
                                        <xsl:variable name="var67_cond_result_exists"
                                            as="xs:string?"
                                            select="(if (fn:exists($var62_rdom/rdommax)) then ' Range Domain Max: ' else ())"/>
                                        <xsl:if test="fn:exists($var67_cond_result_exists)">
                                            <xsl:for-each select="$var62_rdom/rdommax">
                                                <xsl:variable name="var68_rdommax" as="node()"
                                                  select="."/>
                                                <xsl:variable name="var73_map_select_attrmres"
                                                  as="xs:string*">
                                                  <xsl:for-each select="$var62_rdom/attrmres">
                                                  <xsl:sequence select="fn:string(.)"/>
                                                  </xsl:for-each>
                                                </xsl:variable>
                                                <xsl:variable name="var70_cond_result_exists"
                                                  as="xs:string?"
                                                  select="(if (fn:exists($var73_map_select_attrmres)) then ' Smallest unit increment: ' else ())"/>
                                                <xsl:if test="fn:exists($var70_cond_result_exists)">
                                                  <xsl:for-each select="$var62_rdom/attrmres">
                                                  <gco:CharacterString>
                                                  <xsl:sequence
                                                  select="fn:string(fn:concat(fn:concat(fn:concat(fn:concat(fn:concat($var64_cond_result_exists, xs:string($var65_rdommin)), $var67_cond_result_exists), xs:string($var68_rdommax)), $var70_cond_result_exists), fn:string(.)))"
                                                  />
                                                  </gco:CharacterString>
                                                  </xsl:for-each>
                                                </xsl:if>
                                            </xsl:for-each>
                                        </xsl:if>
                                    </xsl:for-each>
                                </xsl:if>
                            </gfc:description>
                        </gfc:FC_Constraint>
                    </gfc:constrainedBy>
                </xsl:for-each>
                <xsl:for-each select="attrlabl">
                    <gfc:memberName>
                        <gco:LocalName>
                            <xsl:sequence select="fn:normalize-space(xs:string(.))"/>
                        </gco:LocalName>
                    </gfc:memberName>
                </xsl:for-each>
                <xsl:for-each select="attrdef">
                    <gfc:definition>
                        <gco:CharacterString>
                            <xsl:sequence select="fn:normalize-space(xs:string(.))"/>
                        </gco:CharacterString>
                    </gfc:definition>
                </xsl:for-each>
                <gfc:cardinality>
                    <xsl:attribute name="gco:nilReason">
                        <xsl:sequence select="xs:string(xs:string('unknown'))"/>
                    </xsl:attribute>
                </gfc:cardinality>
                <xsl:for-each select="attrdefs">
                    <gfc:definitionReference>
                        <gfc:FC_DefinitionReference>
                            <gfc:definitionSource>
                                <gfc:FC_DefinitionSource>
                                    <gfc:source>
                                        <gmd:CI_Citation>
                                            <gmd:title>
                                                <xsl:attribute name="gco:nilReason">
                                                  <xsl:sequence
                                                  select="xs:string(xs:string('inapplicable'))"/>
                                                </xsl:attribute>
                                            </gmd:title>
                                            <gmd:date>
                                                <xsl:attribute name="gco:nilReason">
                                                  <xsl:sequence
                                                  select="xs:string(xs:string('unknown'))"/>
                                                </xsl:attribute>
                                            </gmd:date>
                                            <gmd:citedResponsibleParty>
                                                <gmd:CI_ResponsibleParty>
                                                  <gmd:organisationName>
                                                  <gco:CharacterString>
                                                  <xsl:sequence
                                                  select="fn:normalize-space(xs:string(.))"/>
                                                  </gco:CharacterString>
                                                  </gmd:organisationName>
                                                  <gmd:role>
                                                  <gmd:CI_RoleCode>
                                                  <xsl:attribute name="codeList">
                                                  <xsl:sequence
                                                  select="xs:string(xs:anyURI('http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_RoleCode'))"
                                                  />
                                                  </xsl:attribute>
                                                  <xsl:attribute name="codeListValue">
                                                  <xsl:sequence
                                                  select="xs:string(xs:anyURI('resourceProvider'))"
                                                  />
                                                  </xsl:attribute>
                                                  <xsl:attribute name="codeSpace">
                                                  <xsl:sequence select="xs:string(xs:anyURI('001'))"
                                                  />
                                                  </xsl:attribute>
                                                  </gmd:CI_RoleCode>
                                                  </gmd:role>
                                                </gmd:CI_ResponsibleParty>
                                            </gmd:citedResponsibleParty>
                                        </gmd:CI_Citation>
                                    </gfc:source>
                                </gfc:FC_DefinitionSource>
                            </gfc:definitionSource>
                        </gfc:FC_DefinitionReference>
                    </gfc:definitionReference>
                </xsl:for-each>
                <xsl:for-each select="attrdomv/rdom/attrunit">
                    <gfc:valueMeasurementUnit>
                        <gml:BaseUnit>
                            <xsl:attribute name="gml:id">
                                <xsl:sequence select="xs:string(xs:ID('baseUnit'))"/>
                            </xsl:attribute>
                            <gml:identifier>
                                <xsl:attribute name="codeSpace">
                                    <xsl:sequence select="xs:string(xs:anyURI(xs:string(.)))"/>
                                </xsl:attribute>
                            </gml:identifier>
                            <gml:unitsSystem>
                                <xsl:attribute name="nilReason">
                                    <xsl:sequence select="xs:string(xs:string('unknown'))"/>
                                </xsl:attribute>
                            </gml:unitsSystem>
                        </gml:BaseUnit>
                    </gfc:valueMeasurementUnit>
                </xsl:for-each>
                <xsl:for-each select="attrdomv/edom">
                    <gfc:listedValue>
                        <gfc:FC_ListedValue>
                            <xsl:for-each select="edomv">
                                <gfc:label>
                                    <gco:CharacterString>
                                        <xsl:sequence select="fn:normalize-space(xs:string(.))"/>
                                    </gco:CharacterString>
                                </gfc:label>
                            </xsl:for-each>
                            <xsl:for-each select="edomvd">
                                <gfc:definition>
                                    <gco:CharacterString>
                                        <xsl:sequence select="fn:normalize-space(xs:string(.))"/>
                                    </gco:CharacterString>
                                </gfc:definition>
                            </xsl:for-each>
                            <xsl:for-each select="edomvds">
                                <gfc:definitionReference>
                                    <gfc:FC_DefinitionReference>
                                        <gfc:definitionSource>
                                            <gfc:FC_DefinitionSource>
                                                <gfc:source>
                                                  <gmd:CI_Citation>
                                                  <gmd:title>
                                                  <xsl:attribute name="gco:nilReason">
                                                  <xsl:sequence
                                                  select="xs:string(xs:string('unknown'))"/>
                                                  </xsl:attribute>
                                                  </gmd:title>
                                                  <gmd:date>
                                                  <xsl:attribute name="gco:nilReason">
                                                  <xsl:sequence
                                                  select="xs:string(xs:string('unknown'))"/>
                                                  </xsl:attribute>
                                                  </gmd:date>
                                                  <gmd:citedResponsibleParty>
                                                  <gmd:CI_ResponsibleParty>
                                                  <gmd:organisationName>
                                                  <gco:CharacterString>
                                                  <xsl:sequence
                                                  select="fn:normalize-space(xs:string(.))"/>
                                                  </gco:CharacterString>
                                                  </gmd:organisationName>
                                                  <gmd:role>
                                                  <gmd:CI_RoleCode>
                                                  <xsl:attribute name="codeList">
                                                  <xsl:sequence
                                                  select="xs:string(xs:anyURI('http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_RoleCode'))"
                                                  />
                                                  </xsl:attribute>
                                                  <xsl:attribute name="codeListValue">
                                                  <xsl:sequence
                                                  select="xs:string(xs:anyURI('resourceProvider'))"
                                                  />
                                                  </xsl:attribute>
                                                  <xsl:attribute name="codeSpace">
                                                  <xsl:sequence select="xs:string(xs:anyURI('001'))"
                                                  />
                                                  </xsl:attribute>
                                                  </gmd:CI_RoleCode>
                                                  </gmd:role>
                                                  </gmd:CI_ResponsibleParty>
                                                  </gmd:citedResponsibleParty>
                                                  </gmd:CI_Citation>
                                                </gfc:source>
                                            </gfc:FC_DefinitionSource>
                                        </gfc:definitionSource>
                                    </gfc:FC_DefinitionReference>
                                </gfc:definitionReference>
                            </xsl:for-each>
                        </gfc:FC_ListedValue>
                    </gfc:listedValue>
                </xsl:for-each>
                <xsl:for-each select="attrdomv/codesetd">
                    <gfc:listedValue>
                        <gfc:FC_ListedValue>
                            <xsl:for-each select="codesetn">
                                <gfc:label>
                                    <gco:CharacterString>
                                        <xsl:sequence select="fn:normalize-space(xs:string(.))"/>
                                    </gco:CharacterString>
                                </gfc:label>
                            </xsl:for-each>
                            <gfc:definitionReference>
                                <gfc:FC_DefinitionReference>
                                    <xsl:for-each select="codesets">
                                        <gfc:definitionSource>
                                            <gfc:FC_DefinitionSource>
                                                <gfc:source>
                                                  <gmd:CI_Citation>
                                                  <gmd:title>
                                                  <xsl:attribute name="gco:nilReason">
                                                  <xsl:sequence
                                                  select="xs:string(xs:string('unknown'))"/>
                                                  </xsl:attribute>
                                                  </gmd:title>
                                                  <gmd:date>
                                                  <xsl:attribute name="gco:nilReason">
                                                  <xsl:sequence
                                                  select="xs:string(xs:string('unknown'))"/>
                                                  </xsl:attribute>
                                                  </gmd:date>
                                                  <gmd:citedResponsibleParty>
                                                  <gmd:CI_ResponsibleParty>
                                                  <gmd:organisationName>
                                                  <gco:CharacterString>
                                                  <xsl:sequence
                                                  select="fn:normalize-space(xs:string(.))"/>
                                                  </gco:CharacterString>
                                                  </gmd:organisationName>
                                                  <gmd:role>
                                                  <gmd:CI_RoleCode>
                                                  <xsl:attribute name="codeList">
                                                  <xsl:sequence
                                                  select="xs:string(xs:anyURI('http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_RoleCode'))"
                                                  />
                                                  </xsl:attribute>
                                                  <xsl:attribute name="codeListValue">
                                                  <xsl:sequence
                                                  select="xs:string(xs:anyURI('resourceProvider'))"
                                                  />
                                                  </xsl:attribute>
                                                  <xsl:attribute name="codeSpace">
                                                  <xsl:sequence select="xs:string(xs:anyURI('001'))"
                                                  />
                                                  </xsl:attribute>
                                                  </gmd:CI_RoleCode>
                                                  </gmd:role>
                                                  </gmd:CI_ResponsibleParty>
                                                  </gmd:citedResponsibleParty>
                                                  </gmd:CI_Citation>
                                                </gfc:source>
                                            </gfc:FC_DefinitionSource>
                                        </gfc:definitionSource>
                                    </xsl:for-each>
                                </gfc:FC_DefinitionReference>
                            </gfc:definitionReference>
                        </gfc:FC_ListedValue>
                    </gfc:listedValue>
                </xsl:for-each>
            </xsl:for-each>
        </gfc:FC_FeatureAttribute>
    </xsl:template>
</xsl:stylesheet>
