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

<!--
   Name:    09_gmd:spatialRepresentationInfo.xsl
   Author:  Matthew J. McCready
   Date:  20110601
   Description:  XSLT stylesheet that transforms  ptvctinf/sdtsterm/sdtstype (the SDTS Point and Vector Object Type from Section 3) of an
                 FGDC format file into a ISO file.This stylesheet consists of two templates: spatialRepresentationInfo and SDTSListValueTemp. The
                 spatialRepresentationInfo template sets up the gmd:MD_GeometricObjects and gmd:geometricObjectCount elements. The SDTSListValueTemp
                 template sets up the md:geometricObjectType/gmd:MD_GeometricObjectTypeCode and translates the value found in
                 //metadata/spdoinfo/ptvctinf/sdtsterm/sdtstype of the FGDC into the correct ISO value based  on the MD_GeometricObjectTypeCode codelist, which is
                 found on page 97 of the ISO standard.
   Modification History:
      Initial   Date      Change Request ID   Description

-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gco="http://www.isotc211.org/2005/gco">
        <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>
        <xsl:variable name="MetDate" select="//metadata/metainfo/metd"/>
        <!-- <xsl:variable name="SDTSPntVot" select="//metadata/spdoinfo/ptvctinf/sdtsterm/sdtstype"/> -->



        <xsl:template name="SDTSListValueTemp">
                <!-- <xsl:comment> in the SDTSListValueTemp Template </xsl:comment> -->
                <xsl:variable name="SDTSPntVot"
                        select="//metadata/spdoinfo/ptvctinf/sdtsterm/sdtstype"/>
                <xsl:choose>
                        <xsl:when test="$SDTSPntVot='Point'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >point</xsl:attribute>
                                                <xsl:attribute name="codeSpace">004</xsl:attribute>
                                                point </xsl:element> <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element><!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Entity point'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue">point</xsl:attribute>
                                                <xsl:attribute name="codeSpace">004</xsl:attribute>
                                                point </xsl:element><!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element><!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Label point'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >point</xsl:attribute>
                                                <xsl:attribute name="codeSpace">004</xsl:attribute>
                                                point </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Area Point'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >point</xsl:attribute>
                                                <xsl:attribute name="codeSpace">004</xsl:attribute>
                                                point </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Node, planar graph'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >surface</xsl:attribute>
                                                <xsl:attribute name="codeSpace">006</xsl:attribute>
                                                surface </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->

                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Node, network'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >surface</xsl:attribute>
                                                <xsl:attribute name="codeSpace">006</xsl:attribute>
                                                surface </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='String'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >curve</xsl:attribute>
                                                <xsl:attribute name="codeSpace">003</xsl:attribute>
                                                curve </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->

                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='LINK'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >curve</xsl:attribute>
                                                <xsl:attribute name="codeSpace">003</xsl:attribute>
                                                curve </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Complete chain'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >curve</xsl:attribute>
                                                <xsl:attribute name="codeSpace">003</xsl:attribute>
                                                curve </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Area chain'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >composite</xsl:attribute>
                                                <xsl:attribute name="codeSpace">002</xsl:attribute>
                                                curve </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Network chain, planar graph'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >surface</xsl:attribute>
                                                <xsl:attribute name="codeSpace">006</xsl:attribute>
                                                surface </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Network chain, nonplanar graph'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >composite</xsl:attribute>
                                                <xsl:attribute name="codeSpace">002</xsl:attribute>
                                                composite </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->

                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Circular arc, three point center'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >composite</xsl:attribute>
                                                <xsl:attribute name="codeSpace">002</xsl:attribute>
                                                composite </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Elliptical arc'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >curve</xsl:attribute>
                                                <xsl:attribute name="codeSpace">003</xsl:attribute>
                                                curve </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->

                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Uniform B-spline'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >curve</xsl:attribute>
                                                <xsl:attribute name="codeSpace">003</xsl:attribute>
                                                curve </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->

                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Piecewise Bezier'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >curve</xsl:attribute>
                                                <xsl:attribute name="codeSpace">003</xsl:attribute>
                                                curve </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Ring with mixed composition'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >composite</xsl:attribute>
                                                <xsl:attribute name="codeSpace">002</xsl:attribute>
                                                composite </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Ring composed of strings'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >composite</xsl:attribute>
                                                <xsl:attribute name="codeSpace">002</xsl:attribute>
                                                composite </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->

                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Ring composed of chains'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >composite</xsl:attribute>
                                                <xsl:attribute name="codeSpace">002</xsl:attribute>
                                                composite </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Ring composed of arcs'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >composite</xsl:attribute>
                                                <xsl:attribute name="codeSpace">002</xsl:attribute>
                                                composite </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->

                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='G-polygon'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >complex</xsl:attribute>
                                                <xsl:attribute name="codeSpace">001</xsl:attribute>
                                                complex </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='GT-polygon composed of rings'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >complex</xsl:attribute>
                                                <xsl:attribute name="codeSpace">001</xsl:attribute>
                                                complex </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->

                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='GT-polygon composed of chains'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >complex</xsl:attribute>
                                                <xsl:attribute name="codeSpace">001</xsl:attribute>
                                                complex </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Universe polygon composed of rings'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >complex</xsl:attribute>
                                                <xsl:attribute name="codeSpace">001</xsl:attribute>
                                                complex </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                        <xsl:when test="$SDTSPntVot='Universe polygon composed of chains'">
                                <xsl:element name="gmd:geometricObjectType">
                                        <xsl:element name="gmd:MD_GeometricObjectTypeCode">
                                                <xsl:attribute name="codeList"
                                                  >http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode</xsl:attribute>
                                                <xsl:attribute name="codeListValue"
                                                  >complex</xsl:attribute>
                                                <xsl:attribute name="codeSpace">001</xsl:attribute>
                                                complex </xsl:element>
                                        <!-- gmd:geometricObjectsTypeCode -->
                                </xsl:element>
                                <!-- gmd:geometricObjectType -->
                        </xsl:when>
                </xsl:choose>
        </xsl:template>

        <xsl:template name="spatialRepresentationInfo" match="/">
                <xsl:comment> This is the ptvctinf/sdtsterm/sdtstype from section 3 of the FGDC
                        Standard (Spatial Data Organization) </xsl:comment>

                <xsl:text>
</xsl:text>

                <xsl:element name="gmd:spatialRepresentationInfo">
                        <!-- <xsl:comment> comment 1  </xsl:comment> -->
                        <xsl:element name="gmd:MD_VectorSpatialRepresentation">
                                <!-- <xsl:comment> comment 2  </xsl:comment> -->
                                <xsl:element name="gmd:geometricObjects">

                                        <!-- getting the values for the codeListValue and codeSpace attributes -->
                                        <!-- These values are based on the SDTS Point and Vector Object Type FGDC element (spdoinfo/ptvctinf/sdtstype) -->
                                        <!-- MD_GeometricObjects -->

                                        <xsl:element name="gmd:MD_GeometricObjects ">

                                                <xsl:if
                                                  test="//metadata/spdoinfo/ptvctinf/sdtsterm/sdtstype">
                                                  <xsl:call-template name="SDTSListValueTemp"/>
                                                </xsl:if>

                                                <xsl:if
                                                  test="//metadata/spdoinfo/ptvctinf/sdtsterm/ptvctcnt">
                                                  <xsl:element name="gmd:geometricObjectCount">
                                                  <xsl:element name="gco:Integer">
                                                  <xsl:apply-templates
                                                  select="//metadata/spdoinfo/ptvctinf/sdtsterm/ptvctcnt"
                                                  />
                                                  </xsl:element>
                                                  <!-- gco:Integer -->
                                                  </xsl:element>
                                                  <!-- gmd:geometricObjectCount -->
                                                </xsl:if>

                                        </xsl:element>
                                        <!-- gmd:geometricObjectsType -->


                                </xsl:element>
                                <!-- gmd:geometricObjects -->
                        </xsl:element>
                        <!-- gmd:MD_VectorSpatialRepresentation -->
                </xsl:element>
                <!-- gmd:spatialRepresentationInfo -->


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