<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
   Name:  MetadataReferenceInformation.xsl
   Author:  James W. Allor
   Date:  20050906
   Description:  XSLT stylesheet that transforms the Metadata Reference
                 Information from the MIF to the MRF.
                 Please reference the MIF Specification and the GPMS, Table 1.
   Modification History:
      Initial   Date      Change Request ID   Description
      JWA       20050906   N/A                Initial Version 
      JWA       20051109   N/A                Updated to reflect current MIF Spec..
-->


<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>


<xsl:template name="Metadata_Reference_Information">

  <xsl:element name="Metadata_Reference_Information">

    <xsl:copy-of select="Metadata_Date"/>

    <xsl:call-template name="Metadata_Contact"/>

    <xsl:copy-of select="Metadata_Standard_Name"/>
    <xsl:copy-of select="Metadata_Standard_Version"/>
    <xsl:copy-of select="Metadata_Character_Set"/>
    <xsl:copy-of select="Metadata_File_Identifier"/>
    <xsl:copy-of select="Metadata_Language"/>

  </xsl:element>

</xsl:template>


<xsl:template name="Metadata_Contact">

  <xsl:element name="Metadata_Contact">

    <xsl:for-each select="Contact_Organization[@section='metadata']">
      <xsl:copy>
        <xsl:apply-templates select="."/>
      </xsl:copy>
    </xsl:for-each>

    <xsl:element name="Contact_Address">

      <xsl:for-each select="Address_Type[@section='metadata']">
        <xsl:copy>
          <xsl:apply-templates select="."/>
        </xsl:copy>
      </xsl:for-each>

      <xsl:for-each select="Address[@section='metadata']">
        <xsl:sort select="@gid1" data-type="number"/>
        <xsl:sort select="@gid1" data-type="text"/>

        <xsl:copy>
          <xsl:apply-templates select="."/>
        </xsl:copy>
      </xsl:for-each>

      <xsl:for-each select="City[@section='metadata'],
                            State_or_Province[@section='metadata'],
                            Postal_Code[@section='metadata'],
                            Country[@section='metadata']">
        <xsl:copy>
          <xsl:apply-templates select="."/>
        </xsl:copy>
      </xsl:for-each>

    </xsl:element>

   <xsl:if test="Contact_Voice_Telephone[@section='metadata']">
    <xsl:for-each select="Contact_Voice_Telephone[@section='metadata']">
      <xsl:sort select="@gid1" data-type="number"/>
      <xsl:sort select="@gid1" data-type="text"/>
      <xsl:copy>
        <xsl:apply-templates select="."/>
      </xsl:copy>
    </xsl:for-each>
</xsl:if>

    <xsl:for-each select="Contact_Facsimile_Telephone[@section='metadata'],
                          Contact_Electronic_Mail_Address[@section='metadata']">
      <xsl:copy>
        <xsl:apply-templates select="."/>
      </xsl:copy>
    </xsl:for-each>

  </xsl:element>

</xsl:template>


</xsl:stylesheet>


<!-- Stylus Studio meta-information - (c) 2004-2005. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios/><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition><template match="MIF"></template><template name="IdentificationInformation"></template></MapperBlockPosition></MapperMetaTag>
</metaInformation>
-->
