<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version = "1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>

<xsl:template name="Distribution_Information" match="/">

   <!-- Distribution_Information PARENT ELEMENT -->
   <xsl:element name="distinfo">

      <!-- Distributor PARENT ELEMENT -->
      <xsl:element name="distrib">

         <!-- FGDC PARENT ELEMENT -->
         <xsl:element name="cntinfo">
            <!-- FGDC PARENT ELEMENT -->
            <xsl:element name="cntorgp">
               <!-- Contact_Organization: DATA -->
               <xsl:element name="cntorg">
                  <xsl:apply-templates select="//Distribution_Information/Distributor/Contact_Organization" />
               </xsl:element>
            </xsl:element>
            <!-- Contact_Address PARENT ELEMENT -->
            <xsl:element name="cntaddr">
               <!-- Address_Type: DATA -->
               <xsl:element name="addrtype">
                  <xsl:apply-templates select="//Distribution_Information/Distributor/Contact_Address/Address_Type" />
               </xsl:element>
               <!-- Address:R REPEATING DATA -->
               <xsl:for-each select="//Distribution_Information/Distributor/Contact_Address/Address">
                  <xsl:element name="address">
                     <xsl:value-of select="."/>
                  </xsl:element>
                  <!--
                  <xsl:call-template name="Address" />
                  -->
               </xsl:for-each>
               <!-- City: DATA -->
               <xsl:element name="city">
                  <xsl:apply-templates select="//Distribution_Information/Distributor/Contact_Address/City" />
               </xsl:element>
               <!-- State_or_Province: DATA -->
               <xsl:element name="state">
                  <xsl:apply-templates select="//Distribution_Information/Distributor/Contact_Address/State_or_Province" />
               </xsl:element>
               <!-- Postal_Code: DATA -->
               <xsl:element name="postal">
                  <xsl:apply-templates select="//Distribution_Information/Distributor/Contact_Address/Postal_Code" />
               </xsl:element>
               <!-- Country: DATA -->
               <xsl:element name="country">
                  <xsl:apply-templates select="//Distribution_Information/Distributor/Contact_Address/Country" />
               </xsl:element>
            </xsl:element>
            <!-- Contact_Voice_Telephone:R REPEATING DATA -->
            <xsl:for-each select="//Distribution_Information/Distributor/Contact_Voice_Telephone">
               <xsl:call-template name="Contact_Voice_Telephone" />
            </xsl:for-each>

            <xsl:if test="//Distribution_Information/Distributor/Contact_Facsimile_Telephone">
               <!-- Contact_Facsimile: DATA -->
               <xsl:element name="cntfax">
                  <xsl:apply-templates select="//Distribution_Information/Distributor/Contact_Facsimile_Telephone" />
               </xsl:element>
            </xsl:if>

            <xsl:if test="//Distribution_Information/Distributor/Contact_Electronic_Mail_Address">
               <!-- Contact_Electronic_Mail_Address: DATA -->
               <xsl:element name="cntemail">
                  <xsl:apply-templates select="//Distribution_Information/Distributor/Contact_Electronic_Mail_Address" />
               </xsl:element>
            </xsl:if>
         </xsl:element>
      </xsl:element>

      <xsl:if test="//Distribution_Information/Resource_Description">
         <!-- Resource_Description: DATA -->
         <xsl:element name="resdesc">
            <xsl:apply-templates select="//Distribution_Information/Resource_Description" />
         </xsl:element>
      </xsl:if>

         <!-- Distribution_Liability: DATA -->
         <xsl:element name="distliab">
            <xsl:apply-templates select="//Distribution_Information/Distribution_Liability" />
         </xsl:element>

      <!-- Standard_Order_Process*R REPEATING CONTAINER -->
      <xsl:for-each select="//Distribution_Information/Standard_Order_Process">
         <xsl:element name="stdorder">
            <!-- Capital "D" IN NON-dIGITAL ?????? -->
            <xsl:if test="Non-Digital_Form">
               <!-- Non-digital_Form: DATA -->
               <xsl:element name="nondig">
                  <xsl:apply-templates select="Non-Digital_Form" />
               </xsl:element>
            </xsl:if>

            <!-- <xsl:if test="Digital_Form"> -->

               <xsl:for-each select="Digital_Form">
                  <xsl:element name="digform">
                     <xsl:element name="digtinfo">
                        <!-- Format_Name: DATA -->
                        <xsl:element name="formname">
                           <xsl:apply-templates select="Format_Name" />
                        </xsl:element>
                        <!-- File_Decompression_Technique: DATA -->
                        <xsl:element name="filedec">
                           <xsl:apply-templates select="File_Decompression_Technique" />
                        </xsl:element>
                        <!-- OPTIONAL Transfer_Size -->
                        <xsl:if test="Transfer_Size">
                           <!-- Transfer_Size: DATA -->
                           <xsl:element name="transize">
                              <xsl:apply-templates select="Transfer_Size" />
                           </xsl:element>
                        </xsl:if>
                     </xsl:element>

                     <!-- Digital_Transfer_Option*R REPEATING CONTAINER -->
                     <xsl:for-each select="Digital_Transfer_Option">
                        <xsl:element name="digtopt">

                           <xsl:if test="Network_Resource_Name">
                              <!-- FGDC PARENT ELEMENT -->
                              <xsl:element name="onlinopt">
                                 <!-- FGDC PARENT ELEMENT -->
                                 <xsl:element name="computer">
                                    <!-- FGDC PARENT ELEMENT -->
                                    <xsl:element name="networka">
                                       <!-- Network_Resource_Name:R REPEATING DATA -->
                                       <xsl:for-each select="Network_Resource_Name">
                                          <xsl:element name="networkr">
                                             <xsl:value-of select="."/>
                                          </xsl:element>
                                       </xsl:for-each>
                                    </xsl:element>
                                 </xsl:element>
                              </xsl:element>
                           </xsl:if>
                           <!-- OR -->
                           <xsl:if test="(Offline_Media) and (Recording_Format)">
                              <!-- FGDC PARENT ELEMENT -->
                              <xsl:element name="offoptn">
                                 <!-- Offline_Media: DATA -->
                                 <xsl:element name="offmedia">
                                    <xsl:apply-templates select="Offline_Media" />
                                 </xsl:element>
                                 <!-- Recording_Format:R REPEATING DATA -->
                                 <xsl:for-each select="Recording_Format">
                                    <xsl:element name="recfmt">
                                       <xsl:value-of select="."/>
                                    </xsl:element>
                                 </xsl:for-each>
                              </xsl:element>
                           </xsl:if>

                        </xsl:element>
                     </xsl:for-each>
                     <!-- END FOR-EACH LOOP FOR Digital_Transfer_Option*R REPEATING CONTAINER -->
                  </xsl:element>

               </xsl:for-each>

            <xsl:element name="fees">
               <xsl:apply-templates select="Fees" />
            </xsl:element>

            <xsl:if test="//Distribution_Information/Standard_Order_Process/Ordering_Instructions">
               <xsl:element name="ordering">
                  <xsl:apply-templates select="Ordering_Instructions" />
               </xsl:element>
            </xsl:if>
         </xsl:element>
      </xsl:for-each>

      <!-- Technical_Prerequisites: DATA -->
      <xsl:if test="//Distribution_Information/Technical_Prerequisites">
         <xsl:element name="techpreq">
            <xsl:apply-templates select="//Distribution_Information/Technical_Prerequisites" />
         </xsl:element>
      </xsl:if>
   <!-- CLOSE MASTER PARENT -->
   </xsl:element>

</xsl:template>

<!-- Address:R -->
<xsl:template name="Address">
   <xsl:element name="address">
      <xsl:value-of select="."/>
   </xsl:element>
</xsl:template>
<!-- Contact_Voice_Telephone:R -->
<xsl:template name="Contact_Voice_Telephone">
   <xsl:element name="cntvoice">
      <xsl:value-of select="."/>
   </xsl:element>
</xsl:template>


</xsl:stylesheet>
