<?xml version="1.0" encoding="UTF-8"?>
<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"
    xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" exclude-result-prefixes="xd">
    <xd:doc scope="stylesheet">
        <xd:desc>
            <xd:p><xd:b>Created on:</xd:b> Apr 16, 2014</xd:p>
            <xd:p><xd:b>Author:</xd:b> mccre004</xd:p>
            <xd:p>
                This template handles the optional gmd:processor element for the process step. This elements lists the responsible party and uses the 
                CI_ResponsibleParty package.
            </xd:p>
        </xd:desc>
    </xd:doc>
    
    <xsl:template name="DataQualityProccessor">
        <xsl:if test="./proccont/cntinfo">
            <xsl:element name="gmd:processor">
                
                <xsl:element name="gmd:CI_ResponsibleParty">
                   
                    <xsl:text>
</xsl:text>
                    
                    <xsl:text>
                        </xsl:text>
                    
                    <xsl:if test="./proccont/cntinfo/cntperp/cntper">
                        <xsl:element name="gmd:individualName">
                            <xsl:element name="gco:CharacterString">
                                <xsl:value-of
                                    select="./proccont/cntinfo/cntperp/cntper"/>
                            </xsl:element>
                        </xsl:element>
                    </xsl:if>
                    
                    <xsl:element name="gmd:organisationName">
                        <xsl:element name="gco:CharacterString">
                            
                            <xsl:choose>
                                <xsl:when
                                    test="./proccont/cntinfo/cntorgp/cntorg">
                                    <xsl:value-of
                                        select="./proccont/cntinfo/cntorgp/cntorg"
                                    />
                                </xsl:when>
                                <xsl:when
                                    test="./proccont/cntinfo/cntperp/cntorg">
                                    <xsl:value-of
                                        select="./proccont/cntinfo/cntperp/cntorg"
                                    />
                                </xsl:when>
                            </xsl:choose>
                            
                        </xsl:element>
                        
                    </xsl:element>
                    <!-- gmd:organisationName -->
                    
                    <xsl:if test="./proccont/cntinfo/cntpos">
                        <xsl:element name="gmd:positionName">
                            <xsl:element name="gco:CharacterString">
                                <xsl:value-of select="./proccont/cntinfo/cntpos"/>
                            </xsl:element>
                        </xsl:element>
                    </xsl:if>
                    
                    
                    <xsl:element name="gmd:contactInfo">
                        <xsl:element name="gmd:CI_Contact">
                            <xsl:element name="gmd:phone">
                                <xsl:element name="gmd:CI_Telephone">
                                    
                                    <xsl:element name="gmd:voice">
                                        <xsl:element name="gco:CharacterString">
                                            <xsl:value-of
                                                select="./proccont/cntinfo/cntvoice"/>
                                        </xsl:element>
                                        <!-- gco:CharacterString -->
                                    </xsl:element>
                                    <!--  gmd:voice -->
                                    
                                    <xsl:if test="./proccont/cntinfo/cntfax">
                                        <xsl:element name="gmd:facsimile">
                                            <xsl:element name="gco:CharacterString">
                                                <xsl:value-of
                                                    select="./proccont/cntinfo/cntfax"/>
                                            </xsl:element>
                                            <!-- gco:CharacterString -->
                                        </xsl:element>
                                    </xsl:if>
                                    <!--  gmd:facsimile -->
                                    
                                    
                                </xsl:element>
                                <!-- gmd:CI_Telephone -->
                            </xsl:element>
                            <!-- gmd:phone -->
                            
                            <xsl:element name="gmd:address">
                                <xsl:element name="gmd:CI_Address">
                                    
                                    <xsl:element name="gmd:deliveryPoint">
                                        <xsl:element name="gco:CharacterString">
                                            <xsl:value-of select="./proccont/cntinfo/cntaddr/address"/>
                                        </xsl:element>
                                        <!-- gco:CharacterString -->
                                    </xsl:element>
                                    <!-- gmd:deliveryPoint -->
                                    
                                    <xsl:element name="gmd:city">
                                        <xsl:element name="gco:CharacterString">
                                            <xsl:value-of
                                                select="./proccont/cntinfo/cntaddr/city"/>
                                        </xsl:element>
                                        <!-- gco:CharacterString -->
                                    </xsl:element>
                                    <!-- gmd:city -->
                                    
                                    <xsl:element name="gmd:administrativeArea">
                                        <xsl:element name="gco:CharacterString">
                                            <xsl:value-of
                                                select="./proccont/cntinfo/cntaddr/state"/>
                                        </xsl:element>
                                        <!-- gco:CharacterString -->
                                    </xsl:element>
                                    <!-- gmd:administrativeArea -->
                                    
                                    <xsl:element name="gmd:postalCode">
                                        <xsl:element name="gco:CharacterString">
                                            <xsl:value-of
                                                select="./proccont/cntinfo/cntaddr/postal"/>
                                        </xsl:element>
                                        <!-- gco:CharacterString -->
                                    </xsl:element>
                                    <!-- gmd:postalCode -->
                                    
                                    <xsl:element name="gmd:country">
                                        <xsl:element name="gco:CharacterString">
                                            <xsl:value-of
                                                select="./proccont/cntinfo/cntaddr/country"/>
                                        </xsl:element>
                                        <!-- gco:CharacterString -->
                                    </xsl:element>
                                    <!-- gmd:country -->
                                    
                                    <xsl:element name="gmd:electronicMailAddress">
                                        <xsl:element name="gco:CharacterString">
                                            <xsl:value-of
                                                select="./proccont[1]/cntinfo[1]/cntemail[1]"/>
                                        </xsl:element>
                                        <!-- gco:CharacterString -->
                                    </xsl:element>
                                    <!-- gmd:electronicMailAddress -->
                                    
                                </xsl:element>
                                <!-- gmd:CI_Address -->
                            </xsl:element>
                            <!-- gmd:address -->
                            
                        </xsl:element>
                        <!-- gmd:CI_Contact -->
                    </xsl:element>
                    <!-- gmd:contactInfo -->
                    
                    <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">pointOfContact</xsl:attribute>
                            <xsl:attribute name="codeSpace">007</xsl:attribute> pointOfContact </xsl:element>
                        <!-- gmd:CI_RoleCode -->
                        
                    </xsl:element>
                    <!-- gmd:role -->
                    
                </xsl:element>
                <!-- gmd:CI_ResponsibleParty -->
                
                
                
            </xsl:element>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>