<?xml version="1.0" encoding="ISO-8859-1"?>

<!--
   Name:  DataQualityInformation.xsl
   Author:  James W. Allor
   Date:  20050906
   Description:  XSLT stylesheet that transforms the Data Quality Information
                 section of the GPMS 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="Data_Quality_Information">

  <xsl:element name="Data_Quality_Information">

    <xsl:copy-of select="Attribute_Accuracy_Report"/>
    <xsl:copy-of select="Logical_Consistency_Report"/>
    <xsl:copy-of select="Completeness_Report"/>
    <xsl:copy-of select="Horizontal_Positional_Accuracy_Report"/>

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

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

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

  </xsl:element>

</xsl:template>


<xsl:template name="Quantitative_Horizontal_Positional_Accuracy_Assessment">

  <xsl:for-each-group select="Horizontal_Positional_Accuracy_Value,
                              Horizontal_Positional_Accuracy_Explanation"
                      group-by="@gid1">
    <xsl:sort select="current-grouping-key()" data-type="number"/>
    <xsl:sort select="current-grouping-key()" data-type="text"/>

    <xsl:element name="Quantitative_Horizontal_Positional_Accuracy_Assessment">
      <xsl:for-each select="current-group()">
        <xsl:copy>
          <xsl:apply-templates select="."/>
        </xsl:copy>
      </xsl:for-each>
    </xsl:element>

  </xsl:for-each-group>

</xsl:template>


<xsl:template name="Source_Information">

  <xsl:for-each-group select="Originator[@section='source'],
                              Publication_Date[@section='source'],
                              Title[@section='source'],
                              Source_Scale_Denominator,
                              Type_of_Source_Media,
                              Beginning_Date[@section='source'],
                              Ending_Date[@section='source'],
                              Source_Currentness_Reference,
                              Source_Citation_Abbreviation,
                              Source_Contribution"
                      group-by="@gid1">
    <xsl:sort select="current-grouping-key()" data-type="number"/>
    <xsl:sort select="current-grouping-key()" data-type="text"/>

    <xsl:element name="Source_Information">

      <xsl:for-each select="current-group()">
        <xsl:sort select="@gid2" data-type="number"/>
        <xsl:sort select="@gid2" data-type="text"/>
        <xsl:if test="name()='Originator'">
          <xsl:copy>
            <xsl:apply-templates select="."/>
          </xsl:copy>
        </xsl:if>
      </xsl:for-each>

      <xsl:for-each select="current-group()">
        <xsl:if test="name()!='Originator'">
          <xsl:copy>
            <xsl:apply-templates select="."/>
          </xsl:copy>
        </xsl:if>
      </xsl:for-each>

    </xsl:element>

  </xsl:for-each-group>

</xsl:template>


<xsl:template name="Process_Step">

  <xsl:for-each-group select="Process_Description,
                              Source_Used_Citation_Abbreviation,
                              Process_Date,
                              Source_Produced_Citation_Abbreviation"
                              group-by="@gid1">
    <xsl:sort select="current-grouping-key()" data-type="number"/>
    <xsl:sort select="current-grouping-key()" data-type="text"/>

    <xsl:element name="Process_Step">
      <xsl:for-each select="current-group()">
        <xsl:copy>
          <xsl:apply-templates select="."/>
        </xsl:copy>
      </xsl:for-each>
    </xsl:element>

  </xsl:for-each-group>

</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>
-->
