<axsl:stylesheet xmlns:xx="http://xml.sandre.eaufrance.fr/scenario/fct_assain/4" xmlns:fn="http://www.w3.org/2006/xpath-functions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sch="http://www.ascc.net/xml/schematron" xmlns:sa_ref="http://xml.sandre.eaufrance.fr/scenario/referentiel/2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:axsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <axsl:output method="text" omit-xml-declaration="no" standalone="yes" indent="yes"/>

    <axsl:variable name="DateMAJ">2022-12-23</axsl:variable>
    
    <axsl:variable name="DateMAJ.1">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.1">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.2">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.2">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.3">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.3">Validé</axsl:variable>    
    
    <axsl:variable name="DateMAJ.4">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.4">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.5">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.5">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.6">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.6">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.8">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.8">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.9">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.9">Validé</axsl:variable> 
    
    <axsl:variable name="DateMAJ.10">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.10">Gelé</axsl:variable>     
    
    <axsl:variable name="DateMAJ.11">2020-02-17</axsl:variable>
    <axsl:variable name="Statut.11">Validé</axsl:variable> 
    
    <axsl:variable name="DateMAJ.12">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.12">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.13">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.13">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.14">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.14">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.15">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.15">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.16">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.16">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.17">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.17">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.18">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.18">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.20">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.20">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.21">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.21">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.22">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.22">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.23">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.23">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.24">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.24">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.25">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.25">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.26">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.26">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.28">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.28">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.29">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.29">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.30">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.30">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.31">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.31">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.32">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.32">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.33">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.33">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.34">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.34">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.35">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.35">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.36">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.36">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.37">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.37">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.38">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.38">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.39">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.39">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.40">2020-01-08</axsl:variable>
    <axsl:variable name="Statut.40">Gelé</axsl:variable>
    
    <axsl:variable name="DateMAJ.41">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.41">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.42">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.42">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.43">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.43">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.44">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.44">Gelé</axsl:variable>   
    
    <axsl:variable name="DateMAJ.46">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.46">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.47">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.47">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.48">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.48">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.49">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.49">Gelé</axsl:variable>
    
    <axsl:variable name="DateMAJ.50">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.50">Gelé</axsl:variable>
    
    <axsl:variable name="DateMAJ.51">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.51">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.52">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.52">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.53">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.53">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.54">2020-02-17</axsl:variable>
    <axsl:variable name="Statut.54">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.55">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.55">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.56">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.56">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.57">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.57">Gelé</axsl:variable>
    
    <axsl:variable name="DateMAJ.58">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.58">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.59">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.59">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.60">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.60">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.61">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.61">Validé</axsl:variable>    
    
    <axsl:variable name="DateMAJ.62">2020-02-17</axsl:variable>
    <axsl:variable name="Statut.62">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.63">2020-02-17</axsl:variable>
    <axsl:variable name="Statut.63">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.64">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.64">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.65">2020-08-20</axsl:variable>
    <axsl:variable name="Statut.65">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.66">2020-01-08</axsl:variable>
    <axsl:variable name="Statut.66">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.67">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.67">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.69">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.69">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.70">2020-09-02</axsl:variable>
    <axsl:variable name="Statut.70">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.71">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.71">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.72">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.72">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.73">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.73">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.74">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.74">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.75">2020-02-10</axsl:variable>
    <axsl:variable name="Statut.75">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.76">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.76">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.77">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.77">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.78">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.78">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.79">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.79">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.80">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.80">Validé</axsl:variable>
    
    <axsl:variable name="DateMAJ.81">2019-12-05</axsl:variable>
    <axsl:variable name="Statut.81">Validé</axsl:variable>
	
	<axsl:variable name="DateMAJ.82">2020-09-02</axsl:variable>
	<axsl:variable name="Statut.82">Validé</axsl:variable>
	
	<axsl:variable name="DateMAJ.83">2025-01-30</axsl:variable>
	<axsl:variable name="Statut.83">Validé</axsl:variable>
    	
	<axsl:variable name="DateMAJ.84">2025-03-28</axsl:variable>
	<axsl:variable name="Statut.84">Validé</axsl:variable>
	 <!--AJOUT DU SOUS PRODUIT 3 (dans la cadre de la REUT) DANS LA REGLE E4.36-->
	 <!--MISE A JOUR DES VALEUR EN LIEN AVEC LA NOMENCALTURE 37 DANS LA REGLE E4.39-->
	 
	 <axsl:variable name="DateMAJ.85">2025-09-04</axsl:variable>
	<axsl:variable name="Statut.85">Validé</axsl:variable>
	<!--Mise à jour de la règle E4.64 ajoute de la priorité et que la règle s'applique également sur les système de collecte-->
	
	<axsl:variable name="DateMAJ.86">2026-01-27</axsl:variable>
	<axsl:variable name="Statut.86">Validé</axsl:variable>	
	<!--Règle A4.40 décommentée et changée en E4.40, le 27/01/26-->
	
	<axsl:variable name="DateMAJ.87">2026-02-05</axsl:variable>
	<axsl:variable name="Statut.87">Validé</axsl:variable>	
	<!--Règle E4.40 commentée, le 05/02/26-->
	
	<axsl:variable name="DateMAJ.88">2026-05-21</axsl:variable>
	<axsl:variable name="Statut.88">Validé</axsl:variable>	
	<!--Règle A4.49 et Règle A4.82 mise à jour afin quelle se déclenche uniquement pour [1552] + MAJ E4.23 sur ODP (car conditions toujours validées)-->
	 
    <!--<axsl:variable name="cheminPAR">http://xml.sandre.eaufrance.fr/exist/sandre/Referentiels/PAR.xml</axsl:variable>-->
    <axsl:variable name="cheminPAR">http://xml.sandre.eaufrance.fr/exist/sandre/Referentiels/PAR.xml</axsl:variable>
    <axsl:variable name="cheminSUP">http://xml.sandre.eaufrance.fr/exist/sandre/Referentiels/SUP.xml</axsl:variable>
    <axsl:variable name="cheminFAN">http://xml.sandre.eaufrance.fr/exist/sandre/Referentiels/FAN.xml</axsl:variable>
    <axsl:variable name="testFanSup">
        <axsl:for-each select="document($cheminFAN)//sa_ref:Referentiel/sa_ref:FractionAnalysee">
            <axsl:text>'</axsl:text>
            <xsl:value-of select="current()/sa_ref:CdFractionAnalysee/text()"/>
            <axsl:text>-</axsl:text>
            <xsl:value-of select="current()/sa_ref:Support/sa_ref:CdSupport/text()"/>
            <axsl:text>'</axsl:text>
            <axsl:if test="position() != last()">
                <axsl:text>, </axsl:text>
            </axsl:if>
        </axsl:for-each>
    </axsl:variable>
    <axsl:variable name="testParMicrobiologique">
        <axsl:for-each select="document($cheminPAR)//sa_ref:Referentiel/sa_ref:Parametre">
            <axsl:if test="current()/sa_ref:ParametreMicrobiologique">
                <axsl:text>'</axsl:text>
                <xsl:value-of select="current()/sa_ref:CdParametre/text()"/>
                <axsl:text>'</axsl:text>
                <axsl:text>, </axsl:text>
            </axsl:if>
        </axsl:for-each>
    </axsl:variable>
    <axsl:variable name="testParChimiquePhysique">
        <axsl:for-each select="document($cheminPAR)//sa_ref:Referentiel/sa_ref:Parametre">
            <axsl:if test="(current()/sa_ref:ParametreChimique) or (current()/sa_ref:ParametrePhysique)">
                <axsl:text>'</axsl:text>
                <xsl:value-of select="current()/sa_ref:CdParametre/text()"/>
                <axsl:text>'</axsl:text>
                <axsl:text>, </axsl:text>
            </axsl:if>
        </axsl:for-each>
    </axsl:variable>
    <axsl:variable name="testParPos">
        <axsl:for-each select="document($cheminPAR)//sa_ref:Referentiel/sa_ref:Parametre[descendant::sa_ref:CdValeursPossiblesParametre]">
            <axsl:text>'</axsl:text>
            <xsl:value-of select="current()/sa_ref:CdParametre/text()"/>
            <axsl:text>'</axsl:text>
            <axsl:text>, </axsl:text>
        </axsl:for-each>
    </axsl:variable>
    <axsl:variable name="DateDebut" select="number(translate(/xx:FctAssain/xx:Scenario/xx:DateDebutReference/text(), '-', ''))"/>
    <axsl:variable name="DateFin" select="number(translate(/xx:FctAssain/xx:Scenario/xx:DateFinReference/text(), '-', ''))"/>
    <axsl:template match="* | @*" mode="schematron-get-full-path">
        <axsl:apply-templates select="parent::*" mode="schematron-get-full-path"/>
        <axsl:text>/</axsl:text>
        <axsl:if test="count(. | ../@*) = count(../@*)">@</axsl:if>
        <xsl:value-of select="name()"/>
        <axsl:text>[</axsl:text>
        <xsl:value-of select="1 + count(preceding-sibling::*[name() = name(current())])"/>
        <axsl:text>]</axsl:text>
    </axsl:template>
    <axsl:template match="/">
        <axsl:apply-templates select="/" mode="M1"/>
    </axsl:template>

    <!--////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////-->
    <!--REGLES EN RAPPORT AVEC LA COHERENCE DES DONNEES METIERS ENTRE ELLES-->
    <!--////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////-->
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/xx:Prlvt/xx:Analyse[./xx:Parametre/xx:CdParametre = '1552' and ./xx:RsAnalyse = 0]" priority="5000" mode="M1">
        
        <!--70-->
        <xsl:choose>           
            <axsl:when test="(ancestor::xx:Prlvt/xx:Analyse[./xx:Parametre/xx:CdParametre != '1552' and ./xx:RsAnalyse != 0 and ./xx:Parametre/xx:CdParametre!='1553' and ./xx:Parametre/xx:CdParametre!='2521' and ./xx:Parametre/xx:CdParametre!='1098' and ./xx:Parametre/xx:CdParametre!='1099'])"> A4.70/Erreur de résultat car le débit moyen journalier (code 1552) est nul et il
                existe un résultat de paramètre supérieur à 0. Les références de l'analyse, dont les
                valeurs sont incorrectes, sont: code de l'ouvrage de dépollution '<xsl:value-of select="ancestor::xx:OuvrageDepollution/xx:CdOuvrageDepollution"/>'; code du
                point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>' ;
                code Sandre du paramètre '<xsl:value-of select="ancestor::xx:Prlvt/xx:Analyse[./xx:Parametre/xx:CdParametre != '1552' and ./xx:RsAnalyse != 0]/xx:Parametre/xx:CdParametre"/>'.#</axsl:when>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>

    <!-- E4.83 Résultat du PAR 1305 doit avoir A4 < A3, methode PAR -->
    <!-- 
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/xx:Prlvt/xx:Analyse[./xx:Parametre/xx:CdParametre = '1305']" priority="5000" mode="M1"> 
        <axsl:variable name="CdOuvrage" select="ancestor::xx:OuvrageDepollution/xx:CdOuvrageDepollution"/>
        <axsl:variable name="CdPoint" select="ancestor::xx:PointMesure/xx:NumeroPointMesure"/>
        <axsl:variable name="DatePrlvt" select="ancestor::xx:Prlvt/xx:DatePrlvt"/>
          
        <xsl:choose>           
            <axsl:when test="ancestor::xx:Prlvt[./xx:LocGlobalePointMesure/text()='A3']/xx:Analyse[./xx:Parametre/xx:CdParametre/text() = '1305']/xx:RsAnalyse <= ancestor::xx:Prlvt[xx:LocGlobalePointMesure/text()='A4']/xx:Analyse[xx:Parametre/xx:CdParametre/text() = '1305']/xx:RsAnalyse and ancestor::xx:Prlvt[./xx:LocGlobalePointMesure/text()='A3' and ./xx:Analyse/xx:Parametre/xx:CdParametre = '1305']/xx:DatePrlvt=$DatePrel and ancestor::xx:OuvrageDepollution[./xx:PointMesure/xx:Prlvt/xx:LocGlobalePointMesure/text()='A3' and ./xx:Parametre/xx:CdParametre = '1305']/xx:CdOuvrageDepollution=$CdOuvrage and ancestor::xx:OuvrageDepollution/xx:PointMesure[./xx:Prlvt/xx:LocGlobalePointMesure/text()='A3' and ./xx:Prlvt/xx:Analyse/xx:Parametre/xx:CdParametre = '1305']/xx:NumeroPointMesure=$CdPoint">E4.83/ Le résultat du paramètre 1305 (MES) en sortie (A4) doit être inférieur au résultat en entrée (A3), au même jour '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>', pour le même code de l'ouvrage de dépollution '<xsl:value-of select="$CdOuvrage"/>' et code du
                point de mesure '<xsl:value-of select="$CdPoint"/>'.#</axsl:when>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>   
    -->    


    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure[./xx:LocGlobalePointMesure = 'A4']/xx:Prlvt" mode="M1">
        <axsl:for-each select="./xx:Analyse">
            <axsl:variable name="DatePrel" select="./xx:DatePrlvt"/>
            <axsl:variable name="CdParametre" select="./xx:Parametre/xx:CdParametre/text()"/>
            <axsl:variable name="CdOuvrage" select="../../xx:CdOuvrageDepollution/text()"/>
            <axsl:variable name="CdPoint" select="../xx:NumeroPointMesure/text()"/>
           
            <!--71-->     
            <xsl:choose>
                <axsl:when test="./xx:FinaliteAnalyse != '1' or (($CdParametre = '1301') or ($CdParametre = '1553') or ($CdParametre = '2521') or ($CdParametre = '1302') or ($CdParametre = '1330') or ($CdParametre = '1332') or ($CdParametre = '1312') or ($CdParametre = '1356') or ($CdParametre = '2833') or ($CdParametre = '2840') or ($CdParametre = '1303') or ($CdParametre = '1304') or ($CdParametre = '1307') or (../../../xx:PointMesure[./xx:LocGlobalePointMesure = 'A3']/xx:Prlvt[./xx:DatePrlvt = $DatePrel]/xx:Analyse[(./xx:Parametre/xx:CdParametre = $CdParametre)] and ./xx:FinaliteAnalyse = '1'))"/>
                <axsl:otherwise>A4.71/Erreur de résultat car le paramètre '<xsl:value-of select="$CdParametre"/>' a été mesuré seulement en
                    sortie de station, mais pas en entrée de station, pour la finalité '1'
                    autosurveillance réglementaire. Les références de l'analyse, dont les valeurs
                    sont incorrectes, sont: code de l'ouvrage de dépollution '<xsl:value-of select="ancestor::xx:OuvrageDepollution/xx:CdOuvrageDepollution"/>' ; code
                    du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>';
                    Date du prélèvement: '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>' ; code Sandre du
                    paramètre '<xsl:value-of select="$CdParametre"/>'.# </axsl:otherwise>
            </xsl:choose>

             <!-- E4.83 Résultat du PAR 1305 doit avoir A4 < A3, methode prlvt --> 
            <xsl:choose>           
                <axsl:when test="$CdParametre = '1305' and (../xx:Prlvt[./xx:LocGlobalePointMesure/text()='A3']/xx:Analyse[./xx:Parametre/xx:CdParametre/text() = $CdParametre]/xx:RsAnalyse &lt;= ./xx:RsAnalyse) and ../xx:Prlvt[./xx:LocGlobalePointMesure/text()='A3' and ./xx:Analyse/xx:Parametre/xx:CdParametre/text() = $CdParametre]/xx:DatePrlvt=$DatePrel and ancestor::xx:OuvrageDepollution[./xx:PointMesure/xx:Prlvt/xx:LocGlobalePointMesure/text()='A3' and ./xx:PointMesure/xx:Prlvt/xx:Analyse/xx:Parametre/xx:CdParametre = $CdParametre]/xx:CdOuvrageDepollution=$CdOuvrage and ancestor::xx:OuvrageDepollution/xx:PointMesure[./xx:Prlvt/xx:LocGlobalePointMesure/text()='A3' and ./xx:Prlvt/xx:Analyse/xx:Parametre/xx:CdParametre = $CdParametre]/xx:NumeroPointMesure=$CdPoint">E4.83/ Le résultat du paramètre 1305 (MES) en sortie (A4) doit être inférieur au résultat en entrée (A3), au même jour '<xsl:value-of select="$DatePrel"/>', pour le même code de l'ouvrage de dépollution '<xsl:value-of select="$CdOuvrage"/>' et le code du point de mesure '<xsl:value-of select="$CdPoint"/>'.#</axsl:when>
            </xsl:choose>

        </axsl:for-each>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>

<axsl:template match="/xx:FctAssain//xx:Analyse[./xx:Parametre/xx:CdParametre = '1302']" priority="5000" mode="M1">
        <!--64-->
        <xsl:choose>
            <axsl:when test="(./xx:RsAnalyse &gt;= 0) and (./xx:RsAnalyse &lt;= 14)"/>
            <axsl:otherwise>E4.64/Erreur de résultat sur le paramètre pH (code 1302). Le résultat
                doit être compris entre 0 et 14. Les références de l'analyse, dont les valeurs sont
                incorrectes, sont: code du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>' ;
                code Sandre du paramètre '<xsl:value-of select="ancestor::xx:Analyse/xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>

    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/xx:Prlvt[(./xx:Analyse/xx:Parametre/xx:CdParametre = '1314') and (./xx:Analyse/xx:Parametre/xx:CdParametre = '1313')]" priority="3000" mode="M1">
       
        <!--65-->
        
        <xsl:choose>
            <axsl:when test="(./xx:Analyse[./xx:Parametre/xx:CdParametre = '1313' and ./xx:CdRemAnalyse='0']) or (./xx:Analyse[./xx:Parametre/xx:CdParametre = '1314' and ./xx:CdRemAnalyse='0']) or (./xx:Analyse[./xx:Parametre/xx:CdParametre = '1314' and ./xx:CdRemAnalyse!='0']/xx:RsAnalyse) &gt;= (./xx:Analyse[./xx:Parametre/xx:CdParametre = '1313' and ./xx:CdRemAnalyse!='0']/xx:RsAnalyse) "/>
            <axsl:otherwise>E4.65/Erreur de résultat entre le paramètre DCO (code 1314) et DBO5
                (code 1313). La DCO doit être strictement supérieure à la DBO5. Les références de
                l'analyse, dont les valeurs sont incorrectes, sont: code de l'ouvrage de dépollution
                    '<xsl:value-of select="ancestor::xx:OuvrageDepollution/xx:CdOuvrageDepollution"/>' ; code du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="./xx:DatePrlvt/text()"/>'#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    
    
    
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/xx:Prlvt[(./xx:Analyse/xx:Parametre/xx:CdParametre = '1551') and (./xx:Analyse/xx:Parametre/xx:CdParametre = '1319')]" priority="4" mode="M1">
        
        <!--67-->
        
        <xsl:choose>
            <axsl:when test="(./xx:Analyse[./xx:Parametre/xx:CdParametre = '1551']/xx:RsAnalyse) &gt;= (./xx:Analyse[./xx:Parametre/xx:CdParametre = '1319']/xx:RsAnalyse)"/>
            <axsl:otherwise>A4.67/Erreur de résultat entre le paramètre Azote global (code 1551) et
                Azote Kjeldahl (code 1319). L'azote global doit être supérieur ou égal à l'azote
                Kjeldahl. Les références de l'analyse, dont les valeurs sont incorrectes, sont: code
                du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="./xx:DatePrlvt/text()"/>'#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/xx:Prlvt[(./xx:Analyse/xx:Parametre/xx:CdParametre = '1350') and (./xx:Analyse/xx:Parametre/xx:CdParametre = '1433')]" mode="M1">
        
        <!--69-->
        
        <xsl:choose>
            <axsl:when test="(./xx:Analyse[./xx:Parametre/xx:CdParametre = '1433']/xx:RsAnalyse) * 0.3263 &lt;= (./xx:Analyse[./xx:Parametre/xx:CdParametre = '1350']/xx:RsAnalyse)"/>
            <axsl:otherwise>A4.69/Erreur de résultat entre le paramètre Phosphore total (code 1350)
                et Orthophosphates (code 1433). Le phosphore total doit être supérieure ou égal à la
                concentration en orthophosphates. Les références de l'analyse, dont les valeurs sont
                incorrectes, sont: code de l'ouvrage de dépollution '<xsl:value-of select="ancestor::xx:OuvrageDepollution/xx:CdOuvrageDepollution"/>' ; code du
                point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="./xx:DatePrlvt/text()"/>'#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/xx:Prlvt[(./xx:Analyse/xx:Parametre/xx:CdParametre = '1335') and (./xx:Analyse/xx:Parametre/xx:CdParametre = '1319')]" priority="5" mode="M1">
       
        <!--66-->
        
        <xsl:choose>
            <axsl:when test="(./xx:Analyse[./xx:Parametre/xx:CdParametre = '1335']/xx:RsAnalyse) * 0.77 &lt;= (./xx:Analyse[./xx:Parametre/xx:CdParametre = '1319']/xx:RsAnalyse)"/>
            <axsl:otherwise>A4.66/Erreur de résultat entre le paramètre Ammonium (code 1335) et
                l'azote Kjeldahl (code 1319). L'azote Kjeldahl doit être supérieure ou égal à la
                concentration en ammonium. Les références de l'analyse, dont les valeurs sont
                incorrectes, sont: code du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="./xx:DatePrlvt/text()"/>'#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>

    <!--////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////-->
    <!--REGLES METIERS EN RAPPORT AVEC LA FINALITE 11 RSDE SUR UNE STEU -->
    <!--////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////-->







    <!--////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////-->
    <axsl:template match="/xx:FctAssain" mode="M1">
       
        <!--32-->
        
        <xsl:choose>
            <axsl:when test="count(./xx:OuvrageDepollution[./xx:CdOuvrageDepollution/text() = preceding-sibling::xx:OuvrageDepollution/xx:CdOuvrageDepollution/text()]) = 0"/>
            <axsl:otherwise>E4.32/ Plusieurs stations d'épuration ont le même code '<xsl:value-of select="./xx:OuvrageDepollution[./xx:CdOuvrageDepollution/text() = preceding-sibling::xx:OuvrageDepollution/xx:CdOuvrageDepollution/text()]/xx:CdOuvrageDepollution"/>'.#</axsl:otherwise>
        </xsl:choose>
        
        <!--32-->
        
        <xsl:choose>
            <axsl:when test="count(./xx:SystemeCollecte[./xx:CdSystemeCollecte/text() = preceding-sibling::xx:SystemeCollecte/xx:CdSystemeCollecte/text()]) = 0"/>
            <axsl:otherwise>E4.32/ Plusieurs systèmes de collecte ont le même code <xsl:value-of select="./xx:SystemeCollecte[./xx:CdSystemeCollecte/text() = preceding-sibling::xx:SystemeCollecte/xx:CdSystemeCollecte/text()]/xx:CdSystemeCollecte"/>.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:Scenario" mode="M1">
       
        <!--1-->
        
        <xsl:choose>
            <axsl:when test="($DateFin) &gt;= ($DateDebut)"/>
            <axsl:otherwise>E4.1/La date de début de début de référence du fichier DOIT être
                inferieure ou égale à la demande de fin de référence. Date de début de référence:
                    <xsl:value-of select="./DateDebutReference"/>; Date de fin de référence:
                    <xsl:value-of select="./DateFinReference"/>.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution" mode="M1">
        
        <!--2-->
        
        <xsl:choose>
            <axsl:when test="count(./xx:PointMesure[./xx:LocGlobalePointMesure/text() = 'A3']) &lt;= '1'"/>
            <axsl:otherwise>E4.2/Plusieurs points réglementaires ont la même localisation 'A3' au
                sein du même ouvrage.# </axsl:otherwise>
        </xsl:choose>
        
        
        
        <xsl:choose>
            <axsl:when test="count(./xx:PointMesure[./xx:LocGlobalePointMesure/text() = 'A4']) &lt;= '1'"/>
            <axsl:otherwise>E4.2/Plusieurs points réglementaires ont la même localisation 'A4' au
                sein du même ouvrage.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="count(./xx:PointMesure[./xx:LocGlobalePointMesure/text() = 'A2']) &lt;= '1'"/>
            <axsl:otherwise>E4.2/Plusieurs points réglementaires ont la même localisation 'A2' au
                sein du même ouvrage.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="count(./xx:PointMesure[./xx:LocGlobalePointMesure/text() = 'A5']) &lt;= '1'"/>
            <axsl:otherwise>E4.2/Plusieurs points réglementaires ont la même localisation 'A5' au
                sein du même ouvrage.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="count(./xx:PointMesure[./xx:LocGlobalePointMesure/text() = 'A6']) &lt;= '1'"/>
            <axsl:otherwise>E4.2/Plusieurs points réglementaires ont la même localisation 'A6' au
                sein du même ouvrage.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="count(./xx:PointMesure[./xx:LocGlobalePointMesure/text() = 'A7']) &lt;= '1'"/>
            <axsl:otherwise>E4.2/Plusieurs points réglementaires ont la même localisation 'A7' au
                sein du même ouvrage.#</axsl:otherwise>
        </xsl:choose>
        
        <!--46-->
        
        <xsl:choose>
            <axsl:when test="(count(./xx:PointMesure/xx:LocGlobalePointMesure[./text() = 'M1']) &lt;= '1')"/>
            <axsl:otherwise>E4.46/Plusieurs points 'M1' ont été définis au sein du même
                ouvrage.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="(count(./xx:PointMesure/xx:LocGlobalePointMesure[./text() = 'M2']) &lt;= '1')"/>
            <axsl:otherwise>E4.46/Plusieurs points 'M2' ont été définis au sein du même
                ouvrage.#</axsl:otherwise>
        </xsl:choose>
        
        
        <!--3-->
        
        <xsl:choose>
            <axsl:when test="count(./xx:PointMesure[./xx:NumeroPointMesure/text() = preceding-sibling::xx:PointMesure/xx:NumeroPointMesure/text()]) = 0"/>
            <axsl:otherwise>E4.3/Plusieurs points ont le même code au sein de l'ouvrage
                    '<xsl:value-of select="./xx:CdOuvrageDepollution/text()"/>'.#</axsl:otherwise>
        </xsl:choose>
        
        <!--33-->
        <xsl:choose>
            <axsl:when test="./xx:TypeOuvrageDepollution = '4'"/>
            <axsl:otherwise>E4.33/Seul le type d'ouvrage de dépollution '4' (STEP) est
                toléré.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure[./xx:LocGlobalePointMesure/text() = 'A6']/xx:Prlvt[./xx:Analyse/xx:FinaliteAnalyse = '1']" priority="5000" mode="M1">
        
<!--Règle E4.40 commentée, le 05/02/26-->
	<!--	<xsl:choose>
            <axsl:when test="count(./xx:Analyse[./xx:Parametre/xx:CdParametre/text()='1799'])=1 and count(./xx:Analyse[./xx:Parametre/xx:CdParametre/text()='1307'])=1"/>
            <axsl:otherwise>E4.40/Sur le point A6, les quantités de matières sèches (paramètre 1799) et la siccité (paramètre 1307) doivent être transmises. Erreur au niveau du point de mesure:'<xsl:value-of select="ancestor::xx:PointMesure/xx:NumeroPointMesure"/>' pour le prélèvement en date du ''<xsl:value-of select="./xx:DatePrlvt"/>''#</axsl:otherwise>
        </xsl:choose>-->
        
        <!--64-->
        
        <xsl:choose>
            <axsl:when test="count(./xx:Analyse[./xx:Parametre/xx:CdParametre/text() = '1098']) = 0 and count(./xx:Analyse[./xx:Parametre/xx:CdParametre/text() = '1099']) = 0"/>
            <axsl:otherwise>E4.64/Sur le point A6, les paramètres de masse (paramètre 1099) ou de
                volume (paramètre 1098) ne doivent pas être transmis. Erreur au niveau du point de
                    mesure:'<xsl:value-of select="ancestor::xx:PointMesure/xx:NumeroPointMesure"/>'
                pour le prélèvement en date du ''<xsl:value-of select="./xx:DatePrlvt"/>''#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure" mode="M1">
        <axsl:variable name="Localisation" select="./xx:LocGlobalePointMesure/text()"/>
        
        <!--31-->
        
        <xsl:choose>
            <axsl:when test="($Localisation = 'A2') or ($Localisation = 'A3') or ($Localisation = 'A4') or ($Localisation = 'A5') or ($Localisation = 'A6') or ($Localisation = 'A7') or ($Localisation = 'A8') or (substring($Localisation, 1, 1) = 'S') or (substring($Localisation, 1, 1) = 'M')"/>
            <axsl:otherwise>E4.31/La localisation globale de point de mesure <xsl:value-of select="./xx:LocGlobalePointMesure/text()"/> n'est pas tolérée pour un système de traitement d'eaux usées.#</axsl:otherwise>
        </xsl:choose>
        
        <!--40-->
        
        <!--<xsl:choose>
            <axsl:when test="(./xx:LocGlobalePointMesure/text() = 'A6') and count(./xx:Prlvt) != 0 and count(./xx:Prlvt/xx:Analyse[(./xx:Parametre/xx:CdParametre/text() = '1799')]) = 0">E4.40/Sur le point A6, les quantités de matières sèches doivent être transmises
                (paramètre 1799). Code de l'ouvrage: '<xsl:value-of select="../xx:CdOuvrageDepollution"/>'. Code du point de mesure:'<xsl:value-of select="./xx:NumeroPointMesure"/>'# </axsl:when>
        </xsl:choose>-->
        
        <!--38-->
        <xsl:choose>
            <axsl:when test="((./xx:LocGlobalePointMesure/text() = 'S15') and count(./xx:Prlvt) != 0 and (count(./xx:Prlvt[./xx:Support/xx:CdSupport != '38']) != 0 or count(./xx:Prlvt/xx:Analyse[./xx:FractionAnalysee/xx:CdFractionAnalysee != '157']) != 0))"> E4.38/Seul le support 'Réactif de traitement' (code Sandre 38) et la fraction
                '157' (Réactifs bruts) doivent être mentionnés lors de toute mesure de quantité de
                réactifs utilisés sur le point logique 'S15'. ouvrage:'<xsl:value-of select="../xx:CdOuvrageDepollution"/>'; point:'<xsl:value-of select="./xx:NumeroPointMesure"/>'.# </axsl:when>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="((./xx:LocGlobalePointMesure/text() = 'S14') and count(./xx:Prlvt) != 0 and (count(./xx:Prlvt[./xx:Support/xx:CdSupport != '38']) != 0 or count(./xx:Prlvt/xx:Analyse[./xx:FractionAnalysee/xx:CdFractionAnalysee != '157']) != 0))">E4.38/Seul le support 'Réactif de traitement' (code Sandre 38) et la fraction
                '157' (Réactifs bruts) doivent être mentionnés lors de toute mesure de quantité de
                réactifs utilisés sur le point logique 'S14'. ouvrage:'<xsl:value-of select="../xx:CdOuvrageDepollution"/>'; point:'<xsl:value-of select="./xx:NumeroPointMesure"/>'.# </axsl:when>
        </xsl:choose>
        
        <!--5-->
        <xsl:choose>
            <axsl:when test="(count(./xx:Prlvt[./xx:DatePrlvt/text() = preceding-sibling::xx:Prlvt/xx:DatePrlvt/text()]) = 0) and ($Localisation != 'M1' or $Localisation != 'M2' or $Localisation != 'M3')"/>
            <axsl:otherwise>E4.5/Plusieurs prélèvements ont été réalisés à la même date
                    <xsl:value-of select="./xx:Prlvt[./xx:DatePrlvt/text() = preceding-sibling::xx:Prlvt/xx:DatePrlvt/text()]/xx:DatePrlvt"/> sur le même point de mesure codé '<xsl:value-of select="./xx:NumeroPointMesure"/>'.#</axsl:otherwise>
        </xsl:choose>
        
        <!--30-->
        <xsl:choose>
            <axsl:when test="(($Localisation = 'S14') or ($Localisation = 'S15')) and (count(./xx:Prlvt/xx:Analyse[(./xx:Parametre/xx:CdParametre != '1821') and (./xx:Parametre/xx:CdParametre != '1822') and (./xx:Parametre/xx:CdParametre != '1823') and (./xx:Parametre/xx:CdParametre != '1824')]) != 0)">E4.30/Seuls les réactifs correspondant aux codes Sandre 1821, 1822, 1823, 1824
                doivent faire l'objet d'un suivi quantitatif de leur consommation au niveau des
                points logiques 'S14' et 'S15'.ouvrage:'<xsl:value-of select="../xx:CdOuvrageDepollution"/>'; point:'<xsl:value-of select="./xx:NumeroPointMesure"/>'.# </axsl:when>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/xx:Prlvt" priority="1" mode="M1">
        <axsl:variable name="SupLoc" select="concat(./xx:Support/xx:CdSupport, '-', ../xx:LocGlobalePointMesure/text())"/>
        <axsl:variable name="DatePrlvt" select="./xx:DatePrlvt"/>
        <axsl:variable name="DatePrel" select="number(translate(./xx:DatePrlvt/text(), '-', ''))"/>
        <axsl:variable name="CdPoint" select="../xx:NumeroPointMesure/text()"/>
        <axsl:variable name="Localisation" select="../xx:LocGlobalePointMesure/text()"/>
        <axsl:variable name="Support" select="./xx:Support/xx:CdSupport/text()"/>
        <axsl:variable name="CdOuvrage" select="ancestor::xx:OuvrageDepollution[1]/child::xx:CdOuvrageDepollution/text()"/>
        
        <!--34-->
        <xsl:choose>
            <axsl:when test="($Localisation = 'S4' or $Localisation = 'S5' or $Localisation = 'S6' or $Localisation = 'S17') and (count((./xx:Analyse[(./xx:Parametre/xx:CdParametre = '1098') or (./xx:Parametre/xx:CdParametre = '1099')])) != 0 and not(./xx:Analyse/xx:Parametre/xx:CdParametre = '1799'))">E4.34/Pour les points S4, S5, S6 et S17, lorsqu’il existe une donnée de quantité
                de boue évacuée (en masse ou en volume), il faut obligatoirement qu’une donnée de
                quantité de matière sèche évacuée (paramètre 1799) y soit associée au même jour que
                la mesure de quantité, même si la siccité n’a pas réellement été mesurée le même
                jour. Code ouvrage: '<xsl:value-of select="$CdOuvrage"/>' ; Code
                    point:'<xsl:value-of select="../xx:NumeroPointMesure"/>': Date de prélèvement:
                    '<xsl:value-of select="./xx:DatePrlvt"/>'.# </axsl:when>
        </xsl:choose>
        <!--<axsl:choose>
            <axsl:when test="($Localisation='S4' or $Localisation='S5' or $Localisation='S6' or $Localisation='S17') and count(./xx:Analyse[./xx:Parametre/xx:CdParametre='1307'])!=0 "> 
                E4.45/Pour les points S4, S5, S6 et S17, la siccité ne doit pas être transmise.
                    Code ouvrage: '<axsl:value-of select="$CdOuvrage"/>' ; Code du point:'<axsl:value-of select="../xx:NumeroPointMesure"/>': Date de prélèvement: '<axsl:value-of select="./xx:DatePrlvt"/>'.# </axsl:when>
        </axsl:choose>-->
        
        
        <!--4-->
        <xsl:choose>
            <axsl:when test="($Localisation = 'M1') or ($Localisation = 'M2') or ($Localisation = 'M3') or ($SupLoc = '3-A1') or ($SupLoc = '3-A2') or ($SupLoc = '3-A3') or ($SupLoc = '3-A4') or ($SupLoc = '3-A5') or ($SupLoc = '3-A7') or ($SupLoc = '31-A6') or ($SupLoc = '3-A8') or ($SupLoc = '3-R1') or ($SupLoc = '3-R2') or ($SupLoc = '3-R3') or ($SupLoc = '3-S1') or ($SupLoc = '3-S2') or ($SupLoc = '3-S3') or ($SupLoc = '31-S4') or ($SupLoc = '31-S5') or ($SupLoc = '31-S6') or ($SupLoc = '33-S7') or ($SupLoc = '33-S8') or ($SupLoc = '33-S9') or ($SupLoc = '32-S10') or ($SupLoc = '35-S11') or ($SupLoc = '34-S12') or ($SupLoc = '36-S13') or ($SupLoc = '38-S14') or ($SupLoc = '38-S15') or ($SupLoc = '3-S16') or ($SupLoc = '31-S17') or ($SupLoc = '3-S18') or ($SupLoc = '3-S19')"/>
            <axsl:otherwise>E4.4/Le support dont le code est '<xsl:value-of select="./xx:Support/xx:CdSupport"/>' prélevé au niveau du point de mesure
                    <xsl:value-of select="../xx:LocGlobalePointMesure/text()"/> est incohérent au
                regard de la localisation globale de ce point de mesure.#</axsl:otherwise>
        </xsl:choose>
        <!--6-->
        <xsl:choose>
            <axsl:when test="($DatePrel &gt;= $DateDebut) and ($DatePrel &lt;= $DateFin)"/>
            <axsl:otherwise>E4.6/Le prélèvement effectué à la date '<xsl:value-of select="./xx:DatePrlvt"/>' sur le point de mesure codé '<xsl:value-of select="../xx:NumeroPointMesure/text()"/>' a été réalisé en dehors de la période
                de référence du fichier comprise entre le '<xsl:value-of select="//xx:FctAssain/xx:Scenario/xx:DateDebutReference/text()"/>' et le
                    '<xsl:value-of select="//xx:FctAssain/xx:Scenario/xx:DateFinReference/text()"/>'.#</axsl:otherwise>
        </xsl:choose>
        <axsl:for-each select="./xx:Analyse">
            <axsl:variable name="DateReceptionEchantillon" select="number(translate(./xx:DateReceptionEchantillon/text(), '-', ''))"/>
            <axsl:variable name="Par" select="./xx:Parametre/xx:CdParametre/text()"/>
            <axsl:variable name="Unit" select="./xx:UniteMesure/xx:CdUniteMesure/text()"/>
            <axsl:variable name="ParUnit" select="concat($Par, '-', $Unit)"/>
            <axsl:variable name="ParUnitSup" select="concat(./xx:Parametre/xx:CdParametre, '-', ./xx:UniteMesure/xx:CdUniteMesure, '-', $Support)"/>
            <axsl:variable name="ParSitu" select="concat(./xx:Parametre/xx:CdParametre, '-', ./xx:InSituAnalyse/text())"/>
            <axsl:variable name="valueTestFanSup">
                <axsl:text>'</axsl:text>
                <xsl:value-of select="current()/xx:FractionAnalysee/xx:CdFractionAnalysee/text()"/>
                <axsl:text>-</axsl:text>
                <xsl:value-of select="$Support"/>
                <axsl:text>'</axsl:text>
            </axsl:variable>
            <axsl:if test="./xx:DateAnalyse != '' and ./xx:DateReceptionEchantillon!=''">
                <axsl:variable name="DateAna" select="number(translate(./xx:DateAnalyse/text(), '-', ''))"/>
               
                <!--73-->
                
                <xsl:choose>
                    <xsl:when test="($DateAna - $DateReceptionEchantillon) &lt;= '2'"/>
                    <axsl:otherwise>A4.73/L'écart entre la date d’analyse et la date de réception de
                        l'échantillon DOIT être inférieure ou égale à 2 jours. L'analyse réalisée le
                            '<xsl:value-of select="./xx:DateAnalyse"/>' ayant porté sur le paramètre
                            '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' a été réalisée
                        à une date supérieure de 2 jours à la date de réception de l'échantillon du
                            '<xsl:value-of select="./xx:DateReceptionEchantillon"/>', sur le point codé
                            '<xsl:value-of select="$CdPoint"/>'.#</axsl:otherwise>
                </xsl:choose>
            </axsl:if>
            <axsl:if test="./xx:DateAnalyse != ''">
                <axsl:variable name="DateAna" select="number(translate(./xx:DateAnalyse/text(), '-', ''))"/>
                
                <!--8-->
                
                <xsl:choose>
                    <xsl:when test="$DateAna &gt;= $DatePrel"/>
                    <axsl:otherwise>E4.8/Toute date d’analyse faisant suite à un prélèvement donné
                        DOIT être supérieure ou égale à la date de ce même prélèvement. L'analyse
                        réalisée le '<xsl:value-of select="./xx:DateAnalyse"/>' ayant porté sur le
                        paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' a été
                        réalisée à une date antérieure au prélèvement du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>', sur le point codé
                            '<xsl:value-of select="$CdPoint"/>'.#</axsl:otherwise>
                </xsl:choose>
            </axsl:if>
            <axsl:if test="./xx:DateReceptionEchantillon != ''">
                
                <!--76-->
                <xsl:choose>
                    <xsl:when test="($DateReceptionEchantillon - $DatePrel) &lt;= '1'"/>
                    <axsl:otherwise>A4.76/La date de réception de l'échantillon est supérieure de 1
                        jour à celle du prélèvement. Les références de l'analyse sont: code du point
                        de mesure '<xsl:value-of select="$CdPoint"/>' ; date du prélèvement:
                            <xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>; paramètre analysé: '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
                </xsl:choose>
            </axsl:if>
            
            
            <!--22-->
            
            <xsl:choose>
                <xsl:when test="contains($testFanSup, $valueTestFanSup)"/>
                <axsl:otherwise>E4.22/La fraction analysée '<xsl:value-of select="./xx:FractionAnalysee/xx:CdFractionAnalysee"/>' (<xsl:value-of select="document($cheminFAN)/sa_ref:REFERENTIELS/sa_ref:Referentiel/sa_ref:FractionAnalysee[./sa_ref:CdFractionAnalysee/text() = current()/xx:FractionAnalysee/xx:CdFractionAnalysee/text()]/sa_ref:LbFractionAnalysee"/>) associée à une analyse est incohérente par rapport au support prélevé
                        '<xsl:value-of select="$Support"/>' (<xsl:value-of select="document($cheminSUP)/sa_ref:REFERENTIELS/sa_ref:Referentiel/sa_ref:Support[./sa_ref:CdSupport/text() = $Support]/sa_ref:LbSupport"/>) .Erreur sur une analyse portant sur le code de point '<xsl:value-of select="$CdPoint"/>' de localisation '<xsl:value-of select="$Localisation"/>'.# </axsl:otherwise>
            </xsl:choose>


            <!--25-->
            <xsl:choose>
                <axsl:when test="(($Par != '1098') and ($Par != '1099') and ($Par != '1799') and ($Par != '1552') and ($Par != '1553') and ($Par != '2521')) or (./xx:InSituAnalyse/text() = '1')"/>
                <axsl:otherwise>E4.25/Le type d'analyse associé aux mesures de volumes moyens
                    journaliers (1552), à la hauteur des précipitations (1553), de consommation
                    d'énergie (2521) et de quantité de sous-produits (1098, 1099, 1799) DOIT
                    correspondre à '1' (In situ). Les références de l'analyse incorrecte sont: Code
                    du point de mesure: '<xsl:value-of select="$CdPoint"/>'; Date du prélèvement:
                        '<xsl:value-of select="$DatePrlvt"/>'; Code du paramètre: '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
            </xsl:choose>
        </axsl:for-each>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/xx:Prlvt/xx:Analyse/xx:LQAna" mode="M1">
        
        
        <!--9--> 
        <xsl:choose>
            <axsl:when test="not(./text()) or not(preceding-sibling::xx:LDAna/text()) or ((preceding-sibling::xx:LDAna/text()) and (./text() &gt;= preceding-sibling::xx:LDAna))"/>
            <axsl:otherwise>E4.9/Toute mention de valeurs seuils DOIT respecter l'ordre de grandeur
                suivant: LD &lt; LQ &lt; LS. Les références de l'analyse, dont les valeurs seuils
                sont incorrectes, sont: code du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>' ;
                code Sandre du paramètre '<xsl:value-of select="ancestor::xx:Analyse/xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        
        
        
        <xsl:choose>
            <axsl:when test="not(./text()) or not(following-sibling::xx:LSAna/text()) or ((following-sibling::xx:LSAna/text()) and (./text() &lt;= following-sibling::xx:LSAna))"/>
            <axsl:otherwise>E4.9/Toute mention de valeurs seuils DOIT respecter l'ordre de grandeur
                suivant: LD &lt; LQ &lt; LS. Les références de l'analyse, dont les valeurs seuils
                sont incorrectes, sont: code du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>' ;
                code Sandre du paramètre '<xsl:value-of select="ancestor::xx:Analyse/xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/xx:Prlvt/xx:Analyse" priority="1" mode="M1">
        <axsl:variable name="Loc" select="../../xx:LocGlobalePointMesure/text()"/>
        <axsl:variable name="Fraction" select="./xx:FractionAnalysee/xx:CdFractionAnalysee/text()"/>
        <axsl:variable name="Finalite" select="./xx:FinaliteAnalyse/text()"/>
        <axsl:variable name="Insitu" select="./xx:InSituAnalyse/text()"/>
        <axsl:variable name="Par" select="./xx:Parametre/xx:CdParametre/text()"/>
        <axsl:variable name="CdOuvrage" select="ancestor::xx:OuvrageDepollution/xx:CdOuvrageDepollution"/>
        <axsl:variable name="CdPoint" select="ancestor::xx:PointMesure/xx:NumeroPointMesure"/>
        <axsl:variable name="DatePrlvt" select="ancestor::xx:Prlvt/xx:DatePrlvt"/>
        <axsl:variable name="Met" select="./xx:MethodeAna/xx:CdMethode/text()"/>
        <axsl:variable name="Sup" select="ancestor::xx:Prlvt/xx:Support/xx:CdSupport/text()"/>
        <axsl:variable name="ParUnitSup" select="concat(./xx:Parametre/xx:CdParametre, '-', ./xx:UniteMesure/xx:CdUniteMesure, '-', ancestor::xx:Prlvt/xx:Support/xx:CdSupport/text())"/>
        <axsl:variable name="UnitParLoc" select="concat(./xx:UniteMesure/xx:CdUniteMesure, '-', $Par, '-', $Loc)"/>       
            <axsl:variable name="Unit" select="./xx:UniteMesure/xx:CdUniteMesure/text()"/>
            <axsl:variable name="ParUnit" select="concat($Par, '-', $Unit)"/>
        <axsl:variable name="valueTestPar">
            <axsl:text>'</axsl:text>
            <xsl:value-of select="current()/xx:Parametre/xx:CdParametre/text()"/>
            <axsl:text>'</axsl:text>
        </axsl:variable>
        <axsl:variable name="StatutQual" select="concat(./xx:StatutRsAnalyse/text(), '-', ./xx:QualRsAnalyse/text())"/>
        <axsl:variable name="NomParametre" select="document($cheminPAR)/sa_ref:REFERENTIELS/sa_ref:Referentiel/sa_ref:Parametre[./sa_ref:CdParametre/text() = current()/xx:Parametre/xx:CdParametre/text()]/sa_ref:NomParametre"/>
        <!-- pour E4.83
        <axsl:variable name="ResA4Par1305" select="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/[xx:LocGlobalePointMesure/text()='A4' and xx:NumeroPointMesure = ancestor::xx:PointMesure/xx:NumeroPointMesure and xx:Prlvt/xx:DatePrlvt = ancestor::xx:Prlvt/xx:DatePrlvt and xx:Prlvt/xx:Analyse/xx:Parametre/xx:CdParametre/text()='1305']/xx:Prlvt/xx:Analyse/xx:RsAnalyse"/>
        -->
        
        <!--60-->
        <xsl:choose>
            <axsl:when test="((./xx:CdRemAnalyse = '10') and (./xx:LQAna) and (xs:double(./xx:RsAnalyse) != xs:double(./xx:LQAna)) and (xs:date($DatePrlvt) &gt;= xs:date('2022-11-01')))">E4.60/ Lorsque le code remarque égal 10 (inférieur à la limite de quantification),
                le résultat d'analyse DOIT prendre pour valeur la limite de quantification. Erreur
                détectée sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'
                au niveau du point de localisation '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du
                prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.#
            </axsl:when>
        </xsl:choose>

        
        <!-- E4.83 Résultat du PAR 1305 doit avoir A4 < A3, methode var -->
        <!-- 
        <xsl:choose>
            <axsl:when test="./xx:Parametre/xx:CdParametre = '1305' and  ancestor::xx:PointMesure/xx:LocGlobalePointMesure/text()='A3' and ./xx:RsAnalyse <= $ResA4Par1305">E4.83/ Le résultat du paramètre 1305 (MES) en sortie (A4) doit être inférieur au résultat en entrée (A3), au même jour '<xsl:value-of select="$DatePrlvt"/>' et pour le même point '<xsl:value-of select="$CdPoint"/>'.#
            </axsl:when>
        </xsl:choose>
        -->
        
        <!--23-->
        <xsl:choose>
                    <axsl:when test="$UnitParLoc = '168-1339-M2' or $UnitParLoc = '168-1339-M1' or $Sup='31' or (($Par != '1782') and ($Par != '1552') and ($Par != '1553') and ($Par != '2521') and ($Par != '1305') and ($Par != '1313') and ($Par != '1314') and ($Par != '1319') and ($Par != '1335') and ($Par != '1339') and ($Par != '1340') and ($Par != '1551') and ($Par != '1350') and ($Par != '1433') and ($Par != '1307') and ($Par != '1799') and ($Par != '1098') and ($Par != '1099')) or ($ParUnit = '1782-203') or ($ParUnit = '1552-120') or ($ParUnit = '1553-184') or ($ParUnit = '2521-93') or ($ParUnit = '1305-162') or ($ParUnit = '1313-175') or ($ParUnit = '1314-175') or ($ParUnitSup = '1319-168-3') or ($ParUnitSup = '1319-168-33') or ($ParUnitSup = '1319-168-36') or ($ParUnitSup = '1335-169-33') or ($ParUnitSup = '1319-168-34') or ($ParUnitSup = '1335-169-3') or ($ParUnitSup = '1335-169-34') or ($ParUnitSup = '1335-169-36') or ($ParUnit = '1339-171') or ($ParUnit = '1340-173') or ($ParUnit = '1551-168') or ($ParUnitSup = '1350-177-3') or ($ParUnitSup = '1350-177-33') or ($ParUnitSup = '1350-177-36') or ($ParUnitSup = '1350-177-34') or ($ParUnit = '1433-176') or ($ParUnit = '1307-243') or ($ParUnit = '1307-46') or ($ParUnit = '1799-67') or ($ParUnit = '1098-115') or ($ParUnit = '1099-67')"/>
            <axsl:otherwise>E4.23/Les résultats des paramètres les plus couramment mesurés
                doivent impérativement être exprimés avec les unités de mesure indiquées dans le
                scénario, lors des échanges de données. Les références de l'analyse ayant une
                unité de mesure incorrecte sont: Code ouvrage: '<xsl:value-of select="$CdOuvrage"/>'; Code du point de mesure: '<xsl:value-of select="$CdPoint"/>'; Date du prélèvement: '<xsl:value-of select="$DatePrlvt"/>'; Code du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        
        <!--55-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and ancestor::xx:Prlvt/xx:Preleveur)"/>
            <axsl:otherwise>E4.55/ Le code SIRET et le nom de l'organisme préleveur, pour les
                analyses ayant pour finalité '11' (RSDE) DOIVENT être renseignés. Erreur détectée au
                niveau du point de localisation '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du
                prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.#
            </axsl:otherwise>
        </xsl:choose>
        <axsl:variable name="testPar">
            <xsl:for-each select="ancestor::xx:Prlvt/xx:Analyse/xx:Parametre/xx:CdParametre">
                <xsl:text>'</xsl:text>
                <xsl:value-of select="./text()"/>
                <xsl:if test="position() != last()">
                    <xsl:text>, </xsl:text>
                </xsl:if>
            </xsl:for-each>
        </axsl:variable>
        
        <!--72-->
        <xsl:choose>
            <xsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and contains($testPar, '1552'))"/>
            <xsl:otherwise>A4.72/ Pour les prélèvements sur lesquels des analyses ayant pour
                finalité '11' (RSDE) sont réalisées, le débit moyen journalier DOIT être mesuré.
                Erreur détectée au niveau du point de localisation '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du
                prélèvement en date du '<xsl:value-of select="./xx:DatePrlvt"/>'.#</xsl:otherwise>
        </xsl:choose>
        
        <!--75-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and ./xx:Parametre/xx:CdParametre != '1305' and ./xx:Parametre/xx:CdParametre != '1313' and ./xx:Parametre/xx:CdParametre != '1314' and ./xx:Parametre/xx:CdParametre != '6396' and ./xx:Parametre/xx:CdParametre != '1841') or (./xx:AgreAna = '1' and ./xx:FinaliteAnalyse = '11' and (./xx:Parametre/xx:CdParametre = '1305' or ./xx:Parametre/xx:CdParametre = '1313' or ./xx:Parametre/xx:CdParametre = '1314' or ./xx:Parametre/xx:CdParametre = '6396' or ./xx:Parametre/xx:CdParametre = '1841'))"/>
            <axsl:otherwise>A4.75/ Les analyses ayant pour finalité '11' (RSDE) et portant sur les
                paramètres 1305, 1313, 1314, 6396, 1841 DOIVENT être réalisées sous agrément. Avertissement
                détecté au niveau du point de localisation '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du
                prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>',
                l'analyse portant sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'.# </axsl:otherwise>
        </xsl:choose>
        
        <!--79-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and ./xx:Parametre/xx:CdParametre != '1369' and ./xx:Parametre/xx:CdParametre != '1388' and ./xx:Parametre/xx:CdParametre != '1389' and ./xx:Parametre/xx:CdParametre != '1379' and ./xx:Parametre/xx:CdParametre != '1392' and ./xx:Parametre/xx:CdParametre != '1386' and ./xx:Parametre/xx:CdParametre != '1382' and ./xx:Parametre/xx:CdParametre != '1373' and ./xx:Parametre/xx:CdParametre != '1383' and ./xx:Parametre/xx:CdParametre != '1368' and ./xx:Parametre/xx:CdParametre != '2555') or (./xx:FinaliteAnalyse = '11' and (concat($Par, '-', $Met) = '1369-715' or concat($Par, '-', $Met) = '1388-715' or concat($Par, '-', $Met) = '1389-715' or concat($Par, '-', $Met) = '1379-715' or concat($Par, '-', $Met) = '1392-715' or concat($Par, '-', $Met) = '1386-715' or concat($Par, '-', $Met) = '1382-715' or concat($Par, '-', $Met) = '1373-715' or concat($Par, '-', $Met) = '1383-715' or concat($Par, '-', $Met) = '1368-715' or concat($Par, '-', $Met) = '2555-715'))"/>
            <axsl:otherwise>A4.79/ Pour les analyses ayant pour finalité 11 (RSDE), la méthode
                d'analyse dont le code Sandre est 715 DOIT être utilisée pour l’analyse des métaux
                suivants : Cadmium, Plomb, Nickel, Arsenic, Zinc, Cuivre, Chrome, Cobalt, Titane, Argent et Thallium.
                Erreur détectée au niveau du point de localisation '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du
                prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>',
                l'analyse portant sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'.# </axsl:otherwise>
        </xsl:choose>
        
        <!--77-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and ./xx:Parametre/xx:CdParametre != '1955') or (./xx:FinaliteAnalyse = '11' and (./xx:Parametre/xx:CdParametre = '1955' and (./xx:MethodeAna/xx:CdMethode = '1066' or ./xx:MethodeAna/xx:CdMethode = '1479')))"/>
            <axsl:otherwise>A4.77/ Les analyses ayant pour finalité '11' (RSDE) et portant sur le
                paramètre 1955 DOIVENT être réalisées selon la méthode d'analyse dont le code
                sandre est '1066' ou '1479'. Erreur détectée au niveau du point de localisation '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du
                prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>',
                l'analyse portant sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'.# </axsl:otherwise>
        </xsl:choose>
        <!--<xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and ancestor::xx:Prlvt/xx:DureePrlvt) and (ancestor::xx:Prlvt/xx:DureePrlvt != '00:00:00')"/>
            <axsl:otherwise>E4.57/ La durée du prélèvement, pour les analyses ayant pour finalité
                '11' (RSDE) DOIT être renseignée et être différente de '00:00:00'. Erreur détectée
                au niveau du point de localisation '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du
                prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.#
            </axsl:otherwise>
        </xsl:choose>-->
        
        <!--74-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and $Par != '1305' and $Par != '1313' and $Par != '1314' and $Par != '6396' and $Par != '1841') or (./xx:FinaliteAnalyse = '11' and (concat($Par, '-', $Met) = '1305-610' or concat($Par, '-', $Met) = '1305-317' or concat($Par, '-', $Met) = '1313-316' or concat($Par, '-', $Met) = '1313-315' or concat($Par, '-', $Met) = '1314-381' or concat($Par, '-', $Met) = '1314-368' or concat($Par, '-', $Met) = '6396-368' or concat($Par, '-', $Met) = '1841-274'))"/>
            <axsl:otherwise>A4.74/ Pour les analyses ayant pour finalité 11 (RSDE) et portant sur
                les paramètres 1305 1313 1314 6396 1841, les méthodes d'analyses DOIVENT
                correspondre à des méthodes spécifiées dans l'arrêté et correspondant aux couples
                possibles suivants:1305-610, 1305-317, 1313-316, 1313-315, 1314-381, 1314-368, 6396-368,
                1841-274. Erreur détectée sur la méthode d'analyse du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation
                    '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>'
                lors du prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.# </axsl:otherwise>
        </xsl:choose>
        
        <!--76-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and $Par != '1305' and $Par != '1313' and $Par != '1314' and $Par != '6396' and $Par != '1841') or (./xx:FinaliteAnalyse = '11' and (concat($Par, '-', $Met) = '1305-610' or concat($Par, '-', $Met) = '1305-317' or concat($Par, '-', $Met) = '1313-316' or concat($Par, '-', $Met) = '1313-315' or concat($Par, '-', $Met) = '1314-381' or concat($Par, '-', $Met) = '1314-368' or concat($Par, '-', $Met) = '6396-368' or concat($Par, '-', $Met) = '1841-274'))"/>
            <axsl:otherwise>A4.76/ Pour les analyses ayant pour finalité 11 (RSDE) et portant sur
                les paramètres 1305 1313 1314 6396 1841, les méthodes d'analyses DOIVENT
                correspondre à des méthodes spécifiées dans l'arrêté et correspondant aux couples
                possibles suivants:1305-610, 1305-317, 1313-316, 1313-315, 1314-381, 1314-368, 6396-368,
                1841-274. Erreur détectée sur la méthode d'analyse du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation
                    '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>'
                lors du prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.# </axsl:otherwise>
        </xsl:choose>
        
        <!--47-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and ./xx:DateAnalyse != '')"/>
            <axsl:otherwise>E4.47/ Les analyses ayant pour finalité '11' (RSDE) DOIVENT être
                accompagnées d'une date d'analyse. Erreur détectée sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation
                    '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>'
                lors du prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.# </axsl:otherwise>
        </xsl:choose>
        
        <!--48-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and (./xx:CdRemAnalyse = '1' or ./xx:CdRemAnalyse = '0' or ./xx:CdRemAnalyse = '10'))"/>
            <axsl:otherwise>E4.48/ Le code remarque des analyses ayant pour finalité '11' (RSDE)
                DOIT être égal à '0', '1' ou '10'. Erreur détectée sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation
                    '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>'
                lors du prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.# </axsl:otherwise>
        </xsl:choose>
<axsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or ./xx:Parametre/xx:CdParametre/text() = '1552' or (./xx:FinaliteAnalyse = '11' and ./xx:Parametre/xx:CdParametre != '1552' and ./xx:InSituAnalyse != '1')"/>
            <axsl:otherwise>A4.49/ Les analyses ayant pour finalité '11' (RSDE) DOIVENT être effectuée en laboratoire. Erreur détectée sur le paramètre '<axsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation '<axsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du prélèvement en date du '<axsl:value-of select="ancestor::xx:PointMesure/xx:Prlvt/xx:DatePrlvt"/>'.#
         </axsl:otherwise>
        </axsl:choose>
        <axsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or ./xx:Parametre/xx:CdParametre/text() != '1552' or (./xx:FinaliteAnalyse = '11' and ./xx:InSituAnalyse/text()='1' and ./xx:Parametre/xx:CdParametre/text() = '1552')"/>
            <axsl:otherwise>A4.82/ Les analyses ayant pour finalité '11' (RSDE) pour les mesures de débit moyen journalier (paramètre 1552) DOIVENT être effectuées en 'in situ'. Erreur détectée sur le paramètre '<axsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation '<axsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du prélèvement en date du '<axsl:value-of select="ancestor::xx:PointMesure/xx:Prlvt/xx:DatePrlvt"/>'.#
         </axsl:otherwise>
        </axsl:choose>
        <!--<axsl:choose>
            <axsl:when test="./xx:StatutRsAnalyse='A' and ./xx:QualRsAnalyse='4'"/>
            <axsl:otherwise>A4.50/ Le statut des analyses ayant pour finalité '11' (RSDE) DOIT être égal à 'A' et la qualification à '4'. Erreur détectée sur le paramètre '<axsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation '<axsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du prélèvement en date du '<axsl:value-of select="ancestor::xx:PointMesure/xx:Prlvt/xx:DatePrlvt"/>'.#
         </axsl:otherwise>
        </axsl:choose>-->
        
        <!--56-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and (ancestor::xx:Prlvt/xx:HeurePrlvt and ./xx:Parametre/xx:CdParametre != '1552' or ./xx:Parametre/xx:CdParametre = '1552' or ./xx:InSituAnalyse = '1'))"/>
            <axsl:otherwise>E4.56/ L'heure du prélèvement, pour les analyses ayant pour finalité
                '11' (RSDE) DOIT être renseigné. Erreur détectée au niveau du point de localisation
                    '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>'
                lors du prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.# </axsl:otherwise>
        </xsl:choose>
        
        <!--58-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and ancestor::xx:Prlvt/xx:ConformitePrlvt)"/>
            <axsl:otherwise>E4.58/ La conformité du prélèvement, pour les analyses ayant pour
                finalité '11' (RSDE) DOIT être renseigné. Erreur détectée au niveau du point de
                localisation '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du
                prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.#
            </axsl:otherwise>
        </xsl:choose>
        
        <!--59-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or  (./xx:FinaliteAnalyse = '11' and (ancestor::xx:Prlvt/xx:AccrePrlvt and (ancestor::xx:Prlvt/xx:AccrePrlvt = '1' or ancestor::xx:Prlvt/xx:AccrePrlvt = '2') and ./xx:Parametre/xx:CdParametre != '1552' or ./xx:Parametre/xx:CdParametre = '1552' or ./xx:InSituAnalyse = '1'))"/>
            <axsl:otherwise>E4.59/ L'accréditation du prélèvement, pour les analyses ayant pour
                finalité '11' (RSDE) DOIT être renseignée et prendre pour valeur '1' (accrédité) ou
                '2' (non accrédité). Erreur détectée au niveau du point de localisation
                    '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>'
                lors du prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.# </axsl:otherwise>
        </xsl:choose>
        
        <!--80-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and ./xx:DateReceptionEchantillon != '' and ./xx:Parametre/xx:CdParametre != '1552' or ./xx:Parametre/xx:CdParametre = '1552' or ./xx:InSituAnalyse = '1')"/>
            <axsl:otherwise>E4.80/ La date de réception de l'échantillon pour une analyse ayant pour
                finalité '11' (RSDE) DOIT être renseignée. Erreur détectée sur le paramètre
                    '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de
                localisation '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du
                prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.#
            </axsl:otherwise>
        </xsl:choose>
        
        <!--61-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and (./xx:HeureReceptionEchantillon and ./xx:Parametre/xx:CdParametre != '1552' or ./xx:Parametre/xx:CdParametre = '1552' or ./xx:InSituAnalyse ='1'))"/>
            <axsl:otherwise>E4.61/ L'heure de réception de l'échantillon pour une analyse ayant pour
                finalité '11' (RSDE) DOIT être renseignée. Erreur détectée sur le paramètre
                    '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de
                localisation '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du
                prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.#
            </axsl:otherwise>
        </xsl:choose>
        
        <!--47-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and ./xx:DateAnalyse and ./xx:Parametre/xx:CdParametre != '1552' or ./xx:Parametre/xx:CdParametre = '1552' or ./xx:InSituAnalyse = '1')"/>
            <axsl:otherwise>E4.47/ La date d'une analyse ayant pour finalité '11' (RSDE) DOIT être
                renseignée. Erreur détectée sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation
                    '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>'
                lors du prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.# </axsl:otherwise>
        </xsl:choose>
        <!--51-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and ./xx:MethodeAna)"/>
            <axsl:otherwise>E4.51/ La méthode d'analyse pour une analyse ayant pour finalité '11'
                (RSDE) DOIT être renseignée. Erreur détectée sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation
                    '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>'
                lors du prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.# </axsl:otherwise>
        </xsl:choose>
        
        <!--52-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and ./xx:Laboratoire)"/>
            <axsl:otherwise>E4.52/ Le code SIRET du laboratoire ayant effectué les analyses ayant
                pour finalité '11' (RSDE) DOIVENT être renseignés. Erreur détectée sur le paramètre
                    '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de
                localisation '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du
                prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.#
            </axsl:otherwise>
        </xsl:choose>
        
        <!--53-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and (./xx:LQAna != '0' and ./xx:LQAna != '' and ./xx:Parametre/xx:CdParametre != '1552' or ./xx:Parametre/xx:CdParametre = '1552' or ./xx:InSituAnalyse = '1'))"/>
            <axsl:otherwise>E4.53/ La limite de quantification pour les analyses ayant pour finalité
                '11' (RSDE) DOIT être renseignée et supèrieure à 0. Erreur détectée sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation
                    '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>'
                lors du prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.# </axsl:otherwise>
        </xsl:choose>
        
        <!--54-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and (./xx:AccreAna != '' and ./xx:AccreAna != '0' and ./xx:Parametre/xx:CdParametre != '1552' or ./xx:Parametre/xx:CdParametre = '1552' or ./xx:InSituAnalyse = '1'))"/>
            <axsl:otherwise>E4.54/ L'accréditation des analyses ayant pour finalité '11' (RSDE) DOIT
                être renseignée et prendre pour valeur '1' (accrédité) ou '2' (non accrédité) .
                Erreur détectée sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation
                    '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>'
                lors du prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.# </axsl:otherwise>
        </xsl:choose>
        
        <!--62-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and (./xx:AgreAna != '' and ./xx:Parametre/xx:CdParametre != '1552' or ./xx:Parametre/xx:CdParametre = '1552' or ./xx:InSituAnalyse = '1'))"/>
            <axsl:otherwise>E4.62/ L'agrément des analyses ayant pour finalité '11' (RSDE) DOIT être
                renseignée. Erreur détectée sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation
                    '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>'
                lors du prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.# </axsl:otherwise>
        </xsl:choose>
        
        <!--63-->
        <xsl:choose>
            <axsl:when test="./xx:FinaliteAnalyse != '11' or (./xx:FinaliteAnalyse = '11' and (./xx:IncertAna != '' and ./xx:IncertAna &gt;= 1 and ./xx:IncertAna &lt;= 100 and ./xx:Parametre/xx:CdParametre != '1552' or ./xx:Parametre/xx:CdParametre = '1552' or ./xx:InSituAnalyse = '1'))"/>
            <axsl:otherwise>E4.63/ L'incertitude des analyses ayant pour finalité '11' (RSDE) DOIT
                être renseignée et être comprise entre 1 et 100. Erreur détectée sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de localisation
                    '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>'
                lors du prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.# </axsl:otherwise>
        </xsl:choose>
        
        <!--81-->
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse = '1') and (./xx:LQAna) and (./xx:RsAnalyse &lt; ./xx:LQAna)">A4.81/ Lorsque le code remarque est égal à 1, le résultat doit être strictement supérieur ou égal à la limite de quantification. Erreur au niveau du résultat du paramètre
                    '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' au niveau du point de
                localisation '<xsl:value-of select="ancestor::xx:PointMesure/xx:LocGlobalePointMesure"/>' lors du
                prélèvement en date du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt"/>'.#
            </axsl:when>
        </xsl:choose>
        
        <!--43-->
        <xsl:choose>
            <axsl:when test="preceding-sibling::xx:Analyse[(./xx:InSituAnalyse/text() = $Insitu) and (./xx:Parametre/xx:CdParametre/text() = $Par) and (./xx:FinaliteAnalyse = $Finalite) and (./xx:FractionAnalysee/xx:CdFractionAnalysee = $Fraction)]">E4.43/Doublon de résultats d'analyses. Il ne peut y avoir au sein d'un même fichier deux résultats d'analyses avec les mêmes caractéristiques suivantes : Code
                point: <xsl:value-of select="../../xx:NumeroPointMesure"/>, Date du prélèvement:
                    <xsl:value-of select="../xx:DatePrlvt"/>, paramètre: <xsl:value-of select="$Par"/> , Code fraction analysée: <xsl:value-of select="./xx:FractionAnalysee/xx:CdFractionAnalysee"/> , Code finalité:
                    <xsl:value-of select="./xx:FinaliteAnalyse"/>, Analyse in situ ou en labo:
                    <xsl:value-of select="./xx:InSituAnalyse"/> # </axsl:when>
        </xsl:choose>
        <!-- <axsl:choose>
            <axsl:when test="($Loc='A2' or $Loc='S16' or $Loc='A5' or $Loc='S3') and (./xx:Parametre/xx:CdParametre='1552') and  (./xx:CdRemAnalyse/text()='1') and ((./xx:RsAnalyse/text()='0') or (./xx:RsAnalyse=''))">E4.10/Les mesures de débit moyen journalier (paramètre 1552) ayant été réalisées sur les déversoirs en-tête de station (localisations A2, S16) ou sur les by-pass (localisations A5 et S3) et dont le résultat est
                nul ne DOIVENT pas être transmises dans le fichier d'échange.# </axsl:when>
        </axsl:choose>-->
        <!--12-->
        <xsl:choose>
            <axsl:when test="(./xx:Parametre/xx:CdParametre = '2521') and (ancestor::xx:PointMesure[1]/child::xx:LocGlobalePointMesure/text() != 'A3')">E4.12/Les mesures de consommation d'énergie de la station (paramètre 2521) doivent être raccordées au point réglementaire de type 'A3' (entrée station) pour le système de traitement d'eaux usées.# </axsl:when>
        </xsl:choose>
        <!--<axsl:choose>
            <axsl:when test="(./xx:Parametre/xx:CdParametre='1553') and  (./xx:CdRemAnalyse/text()='1') and ((./xx:RsAnalyse/text()='0') or (./xx:RsAnalyse=''))"> E4.44/Les mesures de hauteur de précipitations (paramètre 1553) dont le résultat
                est nul ne DOIVENT pas être transmises dans le fichier d'échange.# </axsl:when>
        </axsl:choose>-->
        <!--11-->
        
        <xsl:choose>
            <axsl:when test="(./xx:Parametre/xx:CdParametre/text() = '1553') and ancestor::xx:PointMesure[1]/child::xx:LocGlobalePointMesure/text() != 'A3'"> E4.11/Les résultats de hauteur des précipitations (paramètre 1553) doivent être
                raccordés au point réglementaire de type 'A3' (entrée station) pour le système de
                traitement d'eaux usées.# </axsl:when>
        </xsl:choose>
        
        <!--13-->
        <xsl:choose>
            <axsl:when test="(string-length(./xx:RsAnalyse/text()) = 0) and ((./xx:CdRemAnalyse/text() != '5') and (./xx:CdRemAnalyse/text() != '0'))">E4.13/Le résultat d'analyse du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ne peut pas etre vide, à condition
                d'être accompagné d'un code remarque égal à 0 (pour analyse non réalisée) ou 5 (pour
                incomptable).#</axsl:when>
        </xsl:choose>
        
        <!--14-->
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse/text() = 0) and string-length(./xx:RsAnalyse/text()) != 0">E4.14/Erreur au niveau de l'analyse portant sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'. Celle-ci n'a pas été réalisée (code
                remarque associé égal à 0), et le résultat d'analyse est pourtant différent d'une
                valeur nulle. Les références de l'analyse sont: code du point de mesure
                    '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="preceding-sibling::xx:DatePrlvt/text()"/>' ;
                code Sandre du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'.#
            </axsl:when>
        </xsl:choose>
        
        <!--15-->
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse/text() = '5') and string-length(./xx:RsAnalyse/text()) != 0">E4.15/Erreur au niveau de l'analyse portant sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="$NomParametre"/>'). Le résultat est incomptable (code remarque associé égal à 5), et celui-ci
                    ('<xsl:value-of select="./xx:RsAnalyse"/>') est pourtant différent d'une valeur
                nulle.# </axsl:when>
        </xsl:choose>
        
        <!--16-->
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse/text() = '4') and not(contains($testParMicrobiologique, $valueTestPar))">E4.16/Erreur au niveau du résultat du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="$NomParametre"/>'). Le code remarque 4 est réservé aux résultats de paramètre microbiologique
                qualitatif de type Présence ou Absence.# </axsl:when>
        </xsl:choose>
        
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse/text() = '4') and (./xx:UniteMesure/xx:CdUniteMesure != 'X')">E4.16/Erreur au niveau du résultat du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="$NomParametre"/>'). Le code de l'unité de mesure associé au résultat du paramètre qualitatif DOIT
                prendre pour valeur 'X' (sans objet).# </axsl:when>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse/text() = '4') and (./xx:RsAnalyse/text() != '1') and (./xx:RsAnalyse/text() != '2')">E4.16/Erreur au niveau du résultat du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="$NomParametre"/>'). Le code remarque 4 est réservé aux résultats de paramètre microbiologique
                qualitatif de type Présence ou Absence. Le résultat prend alors deux valeurs
                possibles '1' (Absence) ou '2' (présence).# </axsl:when>
        </xsl:choose>
        
        <!--17-->
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse/text() = 5) and not(contains($testParMicrobiologique, $valueTestPar))">E4.17/Erreur au niveau du résultat du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="$NomParametre"/>'). Le code remarque 5 (Incomptable) est réservé aux résultats de paramètre
                microbiologique.# </axsl:when>
        </xsl:choose>
        
        <!--18-->
        <xsl:choose>
            <axsl:when test="./xx:CdRemAnalyse/text() != 6"/>
            <axsl:otherwise>E4.18/Le code remarque 6 (taxons non individualisables) n'est pas toléré
                pour ce scénario.#</axsl:otherwise>
        </xsl:choose>
        
        <!--20-->
        <xsl:choose>
            <axsl:when test="((./xx:CdRemAnalyse/text() = 8) or (./xx:CdRemAnalyse/text() = 9)) and not(contains($testParMicrobiologique, $valueTestPar))">E4.20/Erreur au niveau du résultat du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="document($cheminPAR)/sa_ref:REFERENTIELS/sa_ref:Referentiel/sa_ref:Parametre[./sa_ref:CdParametre/text() = current()/xx:Parametre/xx:CdParametre/text()]/sa_ref:NomParametre"/>'). Les codes remarque 8 (Dénombrement sup. valeur) et 9 (Dénombrement inf.
                valeur) sont réservés au résultat de paramètre microbiologique ou hydrobiologique.#
            </axsl:when>
        </xsl:choose>
        
        <!--21-->
        <xsl:choose>
            <axsl:when test="((./xx:CdRemAnalyse/text() = 2) or (./xx:CdRemAnalyse/text() = 3) or (./xx:CdRemAnalyse/text() = 7) or (./xx:CdRemAnalyse/text() = 10)) and not(contains($testParChimiquePhysique, $valueTestPar))">E4.21/Erreur au niveau du résultat du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="document($cheminPAR)/sa_ref:REFERENTIELS/sa_ref:Referentiel/sa_ref:Parametre[./sa_ref:CdParametre/text() = current()/xx:Parametre/xx:CdParametre/text()]/sa_ref:NomParametre"/>'). Les codes remarque '2' (&lt;seuil de détection), '3' (&lt;seuil de
                saturation), '7' (traces, LD&lt;resultat&lt;LQ) et '10' (&lt; seuil de
                quantification) sont réservés aux résultats de paramètre chimique ou physique. #
            </axsl:when>
        </xsl:choose>
        
        <!--35-->
        <xsl:choose>
            <axsl:when test="($StatutQual = 'A-4') or ($StatutQual = 'B-0') or ($StatutQual = 'B-4') or ($StatutQual = 'C-1') or ($StatutQual = 'C-2') or ($StatutQual = 'C-3') or ($StatutQual = 'D-1') or ($StatutQual = 'D-2')"/>
            <axsl:otherwise>E4.35/Les valeurs relatives au statut et à la qualification de l'analyse
                ne sont pas cohérentes pour l'analyse portant sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        
        <!--24-->
        <xsl:choose>
            <axsl:when test="not(contains($testParPos, $valueTestPar)) or contains($testParMicrobiologique, $valueTestPar) or (document($cheminPAR)/sa_ref:REFERENTIELS/sa_ref:Referentiel/sa_ref:Parametre[./sa_ref:CdParametre/text() = current()/xx:Parametre/xx:CdParametre/text()][descendant::sa_ref:CdValeursPossiblesParametre/text() = current()/xx:RsAnalyse/text()])"/>
            <axsl:otherwise>E4.24/La valeur '<xsl:value-of select="./xx:RsAnalyse/text()"/>' du
                résultat du paramètre qualitatif paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>') est inconnue au regard de la liste
                des valeurs possibles définies au sein du référentiel des paramètres administré par
                le Sandre. .#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>

    <!-- E4.84 Doublons EvenPointMesure -->
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/xx:EvenPointMesure" priority="1" mode="M1">
        <axsl:variable name="CdOuvrage" select="ancestor::xx:OuvrageDepollution/xx:CdOuvrageDepollution"/>
        <axsl:variable name="DateEvenPointMesure" select="./xx:DateEvenPointMesure/text()"/>
        <axsl:variable name="FinaliteEvenPointMesure" select="./xx:Finalite/text()"/>
        <axsl:variable name="TypeEvenPointMesure" select="./xx:TypeEvenPointMesure/text()"/>
    
        <xsl:choose>
            <axsl:when test="preceding-sibling::xx:EvenPointMesure[./xx:DateEvenPointMesure/text() = $DateEvenPointMesure and ./xx:TypeEvenPointMesure/text() = $TypeEvenPointMesure and ./xx:Finalite/text() = $FinaliteEvenPointMesure]">E4.84/Doublon d'évenement EvenPointMesure sur l'ouvrage. Il ne peut y avoir au sein d'un même fichier deux évenements avec les mêmes caractéristiques suivantes : Code ouvrage: <xsl:value-of select="$CdOuvrage"/>, Date de l'evenement: <xsl:value-of select="./xx:DateEvenPointMesure"/>, Type événement: <xsl:value-of select="./xx:TypeEvenPointMesure"/> et Finalité: <xsl:value-of select="./xx:Finalite"/>.# </axsl:when>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
	
	<!-- E4.85 Doublons EvenOuvrageAssainissement -->
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:EvenOuvrageAssainissement" priority="1" mode="M1">
        <axsl:variable name="DateEvenOuvrageAssainissement" select="./xx:DateEvenOuvrageAssainissement/text()"/>
        <axsl:variable name="Finalite" select="./xx:Finalite/text()"/>
        <axsl:variable name="TypeEvenOuvrageAssainissement" select="./xx:TypeEvenOuvrageAssainissement/text()"/>
    
        <xsl:choose>
            <axsl:when test="preceding-sibling::xx:EvenOuvrageAssainissement[./xx:DateEvenOuvrageAssainissement/text() = $DateEvenOuvrageAssainissement and ./xx:TypeEvenOuvrageAssainissement/text() = $TypeEvenOuvrageAssainissement and ./xx:Finalite/text() = $Finalite]">E4.85/Doublon d'évenement EvenOuvrageAssainissement sur l'ouvrage. Il ne peut y avoir au sein d'un même fichier deux évenements avec les mêmes caractéristiques suivantes : Date de l'evenement: <xsl:value-of select="./xx:DateEvenOuvrageAssainissement"/>, Type événement: <xsl:value-of select="./xx:TypeEvenOuvrageAssainissement"/> et Finalité: <xsl:value-of select="./xx:Finalite"/>.# </axsl:when>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>

    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/xx:Prlvt/xx:Analyse/xx:LDAna" mode="M1">
        
        <!--9-->
        <xsl:choose>
            <axsl:when test="not(./text()) or not(following-sibling::xx:LQAna/text()) or ((following-sibling::xx:LQAna/text()) and (./text() &lt;= following-sibling::xx:LQAna))"/>
            <axsl:otherwise>E4.9/Toute mention de valeurs seuils DOIT respecter l'ordre de grandeur
                suivant: LD &lt; LQ &lt; LS. Les références de l'analyse, dont les valeurs seuils
                sont incorrectes, sont: code du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>' ;
                code Sandre du paramètre '<xsl:value-of select="ancestor::xx:Analyse/xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="not(./text()) or not(following-sibling::xx:LSAna/text()) or ((following-sibling::xx:LSAna/text()) and (./text() &lt;= following-sibling::xx:LSAna))"/>
            <axsl:otherwise>E4.9/Toute mention de valeurs seuils DOIT respecter l'ordre de grandeur
                suivant: LD &lt; LQ &lt; LS. Les références de l'analyse, dont les valeurs seuils
                sont incorrectes, sont: code du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>' ;
                code Sandre du paramètre '<xsl:value-of select="ancestor::xx:Analyse/xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:PointMesure/xx:Prlvt/xx:Analyse/xx:IncertAna" mode="M1">
        
        <!--78-->
        <xsl:choose>
            <axsl:when test="./text() &lt; 100"/>
            <axsl:otherwise>A4.78/Pour les analyses ayant pour finalité 11 (RSDE), l'incertitude
                DOIT être exprimée en pourcentage. Les références de l'analyse, dont l'incertitude
                est incorrecte sont: code du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>' ;
                code Sandre du paramètre '<xsl:value-of select="ancestor::xx:Analyse/xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:OuvrageDepollution/xx:ValeurCaracteristiqueRejet" mode="M1">
        <axsl:variable name="Sup1" select="./xx:Support/xx:CdSupport/text()"/>
        <axsl:variable name="Par1" select="./xx:Parametre/xx:CdParametre/text()"/>
        <axsl:variable name="Des" select="./xx:Destination/xx:TypeOuvrageAval/text()"/>
        <axsl:variable name="DateFin" select="number(translate(./xx:DateFinPeriodeReference/text(), '-', ''))"/>
        <axsl:variable name="DateDebRef" select="number(translate(/xx:FctAssain/xx:Scenario/xx:DateDebutReference/text(), '-', ''))"/>
        <axsl:variable name="DateFinRef" select="number(translate(/xx:FctAssain/xx:Scenario/xx:DateFinReference/text(), '-', ''))"/>
       
        <!--37-->
        <xsl:choose>
            <axsl:when test="($DateFin &gt;= $DateDebRef) and ($DateFin &lt;= $DateFinRef)"/>
            <axsl:otherwise>E4.37/La date de fin de période de mesures des quantités de
                sous-produits évacuées par destination '<xsl:value-of select="./xx:DateFinPeriodeReference/text()"/>' n'est pas comprise dans la
                période de référence du fichier (du '<xsl:value-of select="/xx:FctAssain/xx:Scenario/xx:DateDebutReference/text()"/>' au
                    '<xsl:value-of select="/xx:FctAssain/xx:Scenario/xx:DateFinReference/text()"/>').#</axsl:otherwise>
        </xsl:choose>
        
        <!--36-->
        <xsl:choose>
            <axsl:when test="($Sup1 = '31') or ($Sup1 = '32') or ($Sup1 = '33') or ($Sup1 = '35') or ($Sup1 = '3')"/>
            <axsl:otherwise>E4.36/Seuls les sous-produits listés dans le scénario peuvent faire
                l'objet de mesures de quantité évacuée par destination. Le support '<xsl:value-of select="$Sup1"/>' n'est pas un sous-produit.#</axsl:otherwise>
        </xsl:choose>
        
        <!--29-->
        <xsl:choose>
            <axsl:when test="(./xx:PeriodeCalcul = '1') or (./xx:PeriodeCalcul = '365')"/>
            <axsl:otherwise>E4.29/La période de calcul des quantités de sous-produits évacués par
                destination doit prendre pour valeur '1 (cumul périodique) ou '365' (cumul
                annuel).#</axsl:otherwise>
        </xsl:choose>
        
        <!--26-->
        <xsl:choose>
            <axsl:when test="($Par1 = '1098') or ($Par1 = '1099') or ($Par1 = '1799')"/>
            <axsl:otherwise>E4.26/Seuls les paramètres 'Volume','Masse', 'Quantité de matières
                sèches' doivent être utilisés pour les mesures quantitatives de sous-produits
                évacués par destination. Le paramètre erroné est '<xsl:value-of select="$Par1"/>'#.</axsl:otherwise>
        </xsl:choose>
        
        <!--42-->
        <xsl:choose>
            <axsl:when test="($Des != '4') or ($Des = '4' and ./xx:Destination/xx:CdOuvrageAval != '')"/>
            <axsl:otherwise>E4.42/Le code de la station d'épuration de destination de sous-produits
                doit être renseigné.#</axsl:otherwise>
        </xsl:choose>
        
        <!--28-->
        <xsl:choose>
            <axsl:when test="(./xx:PeriodeCalcul = '365') and ($Sup1 = '31') and (($Des != '4') and ($Des != 'U') and ($Des != 'EF') and ($Des != 'C1') and ($Des != 'I') and ($Des != 'S') and ($Des != '2'))">E4.28/La destination '<xsl:value-of select="$Des"/>' n'est pas acceptée en tant
                que destination définitive de boue.#</axsl:when>
        </xsl:choose>
        
        <!--39-->
        <xsl:choose>
            <axsl:when test="(./xx:PeriodeCalcul = '365') or ((./xx:PeriodeCalcul = '1') and (($Des = '4') or ($Des = 'U') or ($Des = '5') or ($Des = 'C1') or ($Des = 'C2') or ($Des = 'I') or ($Des = 'S') or ($Des = 'T') or ($Des = '2') or ($Des = 'SH') or ($Des = 'MH') or ($Des = 'EF'))) or ((./xx:PeriodeCalcul = '365') and (($Des = 'AGRI') or ($Des = 'ARRO') or ($Des = 'GOLF') or ($Des = 'INDU') or ($Des = 'NATU') or ($Des = 'AUTR')))"/>
            <axsl:otherwise>E4.39/La destination '<xsl:value-of select="$Des"/>' n'est pas acceptée
                en tant que destination première de sous-produits évacués.#</axsl:otherwise>
        </xsl:choose>
        
        <!--41-->
        <xsl:choose>
            <axsl:when test="(./xx:PeriodeCalcul != '365') or ((./xx:PeriodeCalcul = '365') and (substring(./xx:DateFinPeriodeReference, 6, 2) = '12') and (substring(./xx:DateFinPeriodeReference, 9, 2) = '31'))"/>
            <axsl:otherwise>E4.41/La date à indiquer pour chaque transmission de quantités annuelles
                de sous-produits évacués par destination définitive est le 31 décembre de l'année
                considérée.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:SystemeCollecte/xx:PointMesure/xx:Prlvt" mode="M1">
        <axsl:variable name="SupLoc" select="concat(./xx:Support/xx:CdSupport, '-', preceding-sibling::xx:LocGlobalePointMesure/text())"/>
        <axsl:variable name="DatePrel" select="number(translate(./xx:DatePrlvt/text(), '-', ''))"/>
        <axsl:variable name="DatePrlvt" select="./xx:DatePrlvt"/>
        <axsl:variable name="CdPoint" select="preceding-sibling::xx:NumeroPointMesure/text()"/>
        <axsl:variable name="Localisation" select="preceding-sibling::xx:LocGlobalePointMesure/text()"/>
        <axsl:variable name="Support" select="./xx:Support/xx:CdSupport/text()"/>
        
        <!--4-->
        <xsl:choose>
            <axsl:when test="($Localisation = 'M1') or ($Localisation = 'M2') or ($Localisation = 'M3') or ($SupLoc = '3-A1') or ($SupLoc = '3-R1') or ($SupLoc = '3-R2') or ($SupLoc = '3-R3')"/>
            <axsl:otherwise>E4.4/Le support dont le code est '<xsl:value-of select="./xx:Support/xx:CdSupport"/>' prélevé au niveau d'un point de mesure est
                incohérent au regard de la localisation globale de ce point de mesure <xsl:value-of select="preceding-sibling::xx:LocGlobalePointMesure/text()"/>.#</axsl:otherwise>
        </xsl:choose>
        
        <!--6-->
        <xsl:choose>
            <axsl:when test="($DatePrel &gt;= $DateDebut) and ($DatePrel &lt;= $DateFin)"/>
            <axsl:otherwise>E4.6/Le prélèvement effectué à la date '<xsl:value-of select="./xx:DatePrlvt"/>' sur le point de mesure codé '<xsl:value-of select="preceding-sibling::xx:NumeroPointMesure/text()"/>' a été réalisé en
                dehors de la période de référence du fichier comprise entre le '<xsl:value-of select="//xx:FctAssain/xx:Scenario/xx:DateDebutReference/text()"/>' et le
                    '<xsl:value-of select="//xx:FctAssain/xx:Scenario/xx:DateDebutReference/text()"/>'.#</axsl:otherwise>
        </xsl:choose>
        <axsl:for-each select="./xx:Analyse">
            <axsl:variable name="Par" select="./xx:Parametre/xx:CdParametre/text()"/>
            <axsl:variable name="ParUnit" select="concat(./xx:Parametre/xx:CdParametre, '-', ./xx:UniteMesure/xx:CdUniteMesure)"/>
            <axsl:variable name="valueTestFanSup">
                <axsl:text>'</axsl:text>
                <xsl:value-of select="current()/xx:FractionAnalysee/xx:CdFractionAnalysee/text()"/>
                <axsl:text>-</axsl:text>
                <xsl:value-of select="$Support"/>
                <axsl:text>'</axsl:text>
            </axsl:variable>
            <axsl:if test="./xx:DateAnalyse != ''">
                <axsl:variable name="DateAna" select="number(translate(./xx:DateAnalyse/text(), '-', ''))"/>
                
                <!--8-->
                <xsl:choose>
                    <xsl:when test="$DateAna &gt;= $DatePrel"/>
                    <axsl:otherwise>E4.8/Toute date d’analyse faisant suite à un prélèvement donné
                        DOIT être supérieure ou égale à la date de ce même prélèvement. L'analyse
                        réalisée le '<xsl:value-of select="$DateAna"/>' ayant porté sur le paramètre
                            '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' a été réalisée
                        à une date antérieure au prélèvement du '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>', sur le point codé
                            '<xsl:value-of select="$CdPoint"/>'.#</axsl:otherwise>
                </xsl:choose>
            </axsl:if>
            
            <!--22-->
            <xsl:choose>
                <xsl:when test="contains($testFanSup, $valueTestFanSup)"/>
                <axsl:otherwise>E4.22/La fraction analysée '<xsl:value-of select="./xx:FractionAnalysee/xx:CdFractionAnalysee"/>' (<xsl:value-of select="document($cheminFAN)/sa_ref:REFERENTIELS/sa_ref:Referentiel/sa_ref:FractionAnalysee[./sa_ref:CdFractionAnalysee/text() = current()/xx:FractionAnalysee/xx:CdFractionAnalysee/text()]/sa_ref:LbFractionAnalysee"/>) associée à une analyse est incohérente par rapport au support prélevé
                        '<xsl:value-of select="$Support"/>' (<xsl:value-of select="document($cheminSUP)/sa_ref:REFERENTIELS/sa_ref:Referentiel/sa_ref:Support[./sa_ref:CdSupport/text() = $Support]/sa_ref:LbSupport"/>) .Erreur sur une analyse portant sur le code de point '<xsl:value-of select="$CdPoint"/>' de localisation '<xsl:value-of select="$Localisation"/>'.#</axsl:otherwise>
            </xsl:choose>
            <!--23-->
            <xsl:choose>
                <axsl:when test="(($Par != '1782') and ($Par != '1552') and ($Par != '1553') and ($Par != '2521') and ($Par != '1305') and ($Par != '1313') and ($Par != '1314') and ($Par != '1319') and ($Par != '1335') and ($Par != '1339') and ($Par != '1340') and ($Par != '1551') and ($Par != '1350') and ($Par != '1433') and ($Par != '1307') and ($Par != '1799') and ($Par != '1098') and ($Par != '1099')) or ($ParUnit = '1782-203') or ($ParUnit = '1552-120') or ($ParUnit = '1553-184') or ($ParUnit = '2521-93') or ($ParUnit = '1305-162') or ($ParUnit = '1313-175') or ($ParUnit = '1314-175') or ($ParUnit = '1319-168') or ($ParUnit = '1335-169') or ($ParUnit = '1339-171') or ($ParUnit = '1340-173') or ($ParUnit = '1551-168') or ($ParUnit = '1350-177') or ($ParUnit = '1433-176') or ($ParUnit = '1307-243') or ($ParUnit = '1307-46') or ($ParUnit = '1799-67') or ($ParUnit = '1098-115') or ($ParUnit = '1099-67')"/>
                <axsl:otherwise>E4.23/Les résultats des paramètres les plus couramment mesurés
                    doivent impérativement être exprimés avec les unités de mesure indiquées dans le
                    scénario, lors des échanges de données. Les références de l'analyse ayant une
                    unité de mesure incorrecte sont: Code du point de mesure: '<xsl:value-of select="$CdPoint"/>'; Date du prélèvement: '<xsl:value-of select="$DatePrlvt"/>'; Code du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
            </xsl:choose>
            
            <!--25-->
            <xsl:choose>
                <axsl:when test="(($Par != '1098') and ($Par != '1099') and ($Par != '1799') and ($Par != '1552') and ($Par != '1553') and ($Par != '2521')) or (./xx:InSituAnalyse/text() = '1')"/>
                <axsl:otherwise>E4.25/Le type d'analyse associé aux mesures de volumes moyens
                    journaliers (1552), à la hauteur des précipitations (1553), de consommation
                    d'énergie (2521) et de quantité de sous-produits (1098, 1099, 1799) DOIT
                    correspondre à '1' (In situ). Les références de l'analyse incorrecte sont: Code
                    du point de mesure: '<xsl:value-of select="$CdPoint"/>'; Date du prélèvement:
                        '<xsl:value-of select="$DatePrlvt"/>'; Code du paramètre: '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
            </xsl:choose>
        </axsl:for-each>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:SystemeCollecte" mode="M1">
       
        <!--46-->
        <xsl:choose>
            <axsl:when test="(count(./xx:PointMesure/xx:LocGlobalePointMesure[./text() = 'M1']) &lt;= '1')"/>
            <axsl:otherwise>E4.46/Plusieurs points 'M1' ont été définis au sein du même
                ouvrage.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="(count(./xx:PointMesure/xx:LocGlobalePointMesure[./text() = 'M2']) &lt;= '1')"/>
            <axsl:otherwise>E4.46/Plusieurs points 'M2' ont été définis au sein du même
                ouvrage.#</axsl:otherwise>
        </xsl:choose>
        
        <!--3-->
        <xsl:choose>
            <axsl:when test="count(./xx:PointMesure[./xx:NumeroPointMesure/text() = preceding-sibling::xx:PointMesure/xx:NumeroPointMesure/text()]) = 0"/>
            <axsl:otherwise>E4.3/Plusieurs points ont le même code au sein du système de collecte
                    '<xsl:value-of select="./xx:CdSystemeCollecte/text()"/>'.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:SystemeCollecte/xx:PointMesure" mode="M1">
        <axsl:variable name="Localisation" select="./xx:LocGlobalePointMesure/text()"/>
        
        <!--31-->
        <xsl:choose>
            <axsl:when test="($Localisation = 'A1') or (substring($Localisation, 1, 1) = 'R') or (substring($Localisation, 1, 1) = 'M')"/>
            <axsl:otherwise>E4.31/La localisation globale de point de mesure <xsl:value-of select="./xx:LocGlobalePointMesure/text()"/> n'est pas tolérée pour un système
                de collecte.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:SystemeCollecte/xx:PointMesure/xx:Prlvt/xx:Analyse" priority="1" mode="M1">
        <axsl:variable name="Fraction" select="./xx:FractionAnalysee/xx:CdFractionAnalysee/text()"/>
        <axsl:variable name="Finalite" select="./xx:FinaliteAnalyse/text()"/>
        <axsl:variable name="Par" select="./xx:Parametre/xx:CdParametre/text()"/>
        <axsl:variable name="Insitu" select="./xx:InSituAnalyse/text()"/>
        <axsl:variable name="valueTestPar">
            <axsl:text>'</axsl:text>
            <xsl:value-of select="current()/xx:Parametre/xx:CdParametre/text()"/>
            <axsl:text>'</axsl:text>
        </axsl:variable>
        <axsl:variable name="StatutQual" select="concat(./xx:StatutRsAnalyse/text(), '-', ./xx:QualRsAnalyse/text())"/>
        <axsl:variable name="NomParametre" select="document($cheminPAR)/sa_ref:REFERENTIELS/sa_ref:Referentiel/sa_ref:Parametre[./sa_ref:CdParametre/text() = current()/xx:Parametre/xx:CdParametre/text()]/sa_ref:NomParametre"/>
        <!--<axsl:choose>
            <axsl:when test="(./xx:Parametre/xx:CdParametre='1552') and  (./xx:CdRemAnalyse/text()='1') and ((./xx:RsAnalyse/text()='0') or (./xx:RsAnalyse=''))">E4.10/Les mesures de débit moyen journalier (paramètre 1552) ayant été réalisées et dont le résultat est
                nul ne DOIVENT pas être transmises dans le fichier d'échange.# </axsl:when>
        </axsl:choose>-->
        <!--43-->
        <xsl:choose>
            <axsl:when test="preceding-sibling::xx:Analyse[(./xx:InSituAnalyse/text() = $Insitu) and (./xx:Parametre/xx:CdParametre/text() = $Par) and (./xx:FinaliteAnalyse = $Finalite) and (./xx:FractionAnalysee/xx:CdFractionAnalysee = $Fraction)]">E4.43/Doublon de résultats d'analyses. Il ne peut y avoir au sein d'un même fichier deux résultats d'analyses avec les mêmes caractéristiques suivantes : Code
                point: <xsl:value-of select="../../xx:NumeroPointMesure"/>, Date du prélèvement:
                    <xsl:value-of select="../xx:DatePrlvt"/>, paramètre: <xsl:value-of select="$Par"/> , Code fraction analysée: <xsl:value-of select="./xx:FractionAnalysee/xx:CdFractionAnalysee"/> , Code finalité:
                    <xsl:value-of select="./xx:FinaliteAnalyse"/> # </axsl:when>
        </xsl:choose>
        <!--12-->
        <xsl:choose>
            <axsl:when test="(./xx:Parametre/xx:CdParametre = '2521') and (ancestor::xx:PointMesure[1]/child::xx:LocGlobalePointMesure/text() != 'A3')"> E4.12/Les mesures de consommation d'énergie de la station (paramètre 2521) doivent
                être raccordées au point réglementaire de type 'A3' (entrée station) pour le système
                de traitement d'eaux usées.# </axsl:when>
        </xsl:choose>
        <!--<axsl:choose>
            <axsl:when test="(./xx:Parametre/xx:CdParametre='1553') and  (./xx:CdRemAnalyse/text()='1') and ((./xx:RsAnalyse/text()='0') or (./xx:RsAnalyse=''))"> E4.44/Les mesures de hauteur de précipitations (paramètre 1553) dont le résultat
                est nul ne DOIVENT pas être transmises dans le fichier d'échange.# </axsl:when>
        </axsl:choose>-->
        
        <!--11-->
        <xsl:choose>
            <axsl:when test="(./xx:Parametre/xx:CdParametre/text() = '1553') and ancestor::xx:PointMesure[1]/child::xx:LocGlobalePointMesure/text() != 'A1' and ancestor::xx:PointMesure[1]/child::xx:LocGlobalePointMesure/text() != 'R1' and ancestor::xx:PointMesure[1]/child::xx:LocGlobalePointMesure/text() != 'R2' and ancestor::xx:PointMesure[1]/child::xx:LocGlobalePointMesure/text() != 'R3'">E4.11/Les résultats de hauteur des précipitations (paramètre 1553) doivent être
                raccordés aux points de type 'A1' ou 'R1' ou 'R2' ou 'R3' pour un système de collecte.# </axsl:when>
        </xsl:choose>
        <!--13-->
        <xsl:choose>
            <axsl:when test="(string-length(./xx:RsAnalyse/text()) = 0) and ((./xx:CdRemAnalyse/text() != '5') and (./xx:CdRemAnalyse/text() != '0'))">E4.13/Le résultat d'analyse du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ne peut pas etre nul, à condition
                d'être accompagné d'un code remarque égal à 0 (pour analyse non réalisée) ou 5 (pour
                incomptable).#</axsl:when>
        </xsl:choose>
        
        <!--14-->
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse/text() = 0) and string-length(./xx:RsAnalyse/text()) != 0">E4.14/Erreur au niveau de l'analyse portant sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'. Celle-ci n'a pas été réalisée (code
                remarque associé égal à 0), et le résultat d'analyse est pourtant différent d'une
                valeur nulle. Les références de l'analyse sont: code point '<xsl:value-of select="../../xx:NumeroPointMesure/text()"/>'; Date du prélèvement:
                    '<xsl:value-of select="preceding-sibling::xx:DatePrlvt/text()"/>' ; code Sandre
                du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'.# </axsl:when>
        </xsl:choose>
        
        <!--15-->
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse/text() = '5') and string-length(./xx:RsAnalyse/text()) != 0">E4.15/Erreur au niveau de l'analyse portant sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="$NomParametre"/>'). Le résultat est incomptable (code remarque associé égal à 5), et celui-ci
                    ('<xsl:value-of select="./xx:RsAnalyse"/>') est pourtant différent d'une valeur
                nulle.# </axsl:when>
        </xsl:choose>
        
        <!--16-->
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse/text() = '4') and not(contains($testParMicrobiologique, $valueTestPar))">E4.16/Erreur au niveau du résultat du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="$NomParametre"/>'). Le code remarque 4 est réservé aux résultats de paramètre microbiologique
                qualitatif de type Présence ou Absence.# </axsl:when>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse/text() = '4') and (./xx:UniteMesure/xx:CdUniteMesure != 'X')">E4.16/Erreur au niveau du résultat du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="$NomParametre"/>'). Le code de l'unité de mesure associé au résultat du paramètre DOIT prendre
                pour valeur 'X' (sans objet).# </axsl:when>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse/text() = '4') and (./xx:RsAnalyse/text() != '1') and (./xx:RsAnalyse/text() != '2')">E4.16/Erreur au niveau du résultat du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="$NomParametre"/>'). Le code remarque 4 est réservé aux résultats de paramètre microbiologique
                qualitatif de type Présence ou Absence. Le résultat prend alors deux valeurs
                possibles '1' (Absence) ou '2' (présence).# </axsl:when>
        </xsl:choose>
        
        <!--17-->
        <xsl:choose>
            <axsl:when test="(./xx:CdRemAnalyse/text() = 5) and not(contains($testParMicrobiologique, $valueTestPar))">E4.17/Erreur au niveau du résultat du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="$NomParametre"/>'). Le code remarque 5 (Incomptable) est réservé aux résultats de paramètre
                microbiologique.# </axsl:when>
        </xsl:choose>
        <!--18-->
        <xsl:choose>
            <axsl:when test="./xx:CdRemAnalyse/text() != 6"/>
            <axsl:otherwise>E4.18/Le code remarque 6 (taxons non individualisables) n'est pas toléré
                pour ce scénario.#</axsl:otherwise>
        </xsl:choose>
        
        <!--20-->
        <xsl:choose>
            <axsl:when test="((./xx:CdRemAnalyse/text() = 8) or (./xx:CdRemAnalyse/text() = 9)) and not(contains($testParMicrobiologique, $valueTestPar))">E4.20/Erreur au niveau du résultat du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="document($cheminPAR)/sa_ref:REFERENTIELS/sa_ref:Referentiel/sa_ref:Parametre[./sa_ref:CdParametre/text() = current()/xx:Parametre/xx:CdParametre/text()]/sa_ref:NomParametre"/>'). Les codes remarque 8 (Dénombrement sup. valeur) et 9 (Dénombrement inf.
                valeur) sont réservés au résultat de paramètre microbiologique ou hydrobiologique.#
            </axsl:when>
        </xsl:choose>
        
        <!--21-->
        <xsl:choose>
            <axsl:when test="((./xx:CdRemAnalyse/text() = 2) or (./xx:CdRemAnalyse/text() = 3) or (./xx:CdRemAnalyse/text() = 7) or (./xx:CdRemAnalyse/text() = 10)) and not(contains($testParChimiquePhysique, $valueTestPar))">E4.21/Erreur au niveau du résultat du paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="document($cheminPAR)/sa_ref:REFERENTIELS/sa_ref:Referentiel/sa_ref:Parametre[./sa_ref:CdParametre/text() = current()/xx:Parametre/xx:CdParametre/text()]/sa_ref:NomParametre"/>'). Les codes remarque '2' (&lt;seuil de détection), '3' (&lt;seuil de
                saturation), '7' (traces, LD&lt;resultat&lt;LQ) et '10' (&lt; seuil de
                quantification) sont réservés aux résultats de paramètre chimique ou physique. #
            </axsl:when>
        </xsl:choose>
        
        <!--35-->
        <xsl:choose>
            <axsl:when test="($StatutQual = 'A-4') or ($StatutQual = 'B-0') or ($StatutQual = 'B-4') or ($StatutQual = 'C-1') or ($StatutQual = 'C-2') or ($StatutQual = 'C-3') or ($StatutQual = 'D-1') or ($StatutQual = 'D-2')"/>
            <axsl:otherwise>E4.35/Les valeurs relatives au statut et à la qualification de l'analyse
                ne sont pas cohérentes pour l'analyse portant sur le paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        
        <!--24-->
        <xsl:choose>
            <axsl:when test="not(contains($testParPos, $valueTestPar)) or contains($testParMicrobiologique, $valueTestPar) or (document($cheminPAR)/sa_ref:REFERENTIELS/sa_ref:Referentiel/sa_ref:Parametre[./sa_ref:CdParametre/text() = current()/xx:Parametre/xx:CdParametre/text()][descendant::sa_ref:CdValeursPossiblesParametre/text() = current()/xx:RsAnalyse/text()])"/>
            <axsl:otherwise>E4.24/La valeur '<xsl:value-of select="./xx:RsAnalyse/text()"/>' du
                résultat du paramètre qualitatif paramètre '<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>' ('<xsl:value-of select="./xx:Parametre/xx:CdParametre"/>') est inconnue au regard de la liste
                des valeurs possibles définis au sein du référentiel des paramètres administré par
                le Sandre. .#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:SystemeCollecte/xx:PointMesure/xx:Prlvt/xx:Analyse/xx:LDAna" mode="M1">
        
        <!--9-->
        <xsl:choose>
            <axsl:when test="not(./text()) or not(following-sibling::xx:LQAna/text()) or ((following-sibling::xx:LQAna/text()) and (./text() &lt;= following-sibling::xx:LQAna))"/>
            <axsl:otherwise>E4.9/Toute mention de valeurs seuils DOIT respecter l'ordre de grandeur
                suivant: LD &lt; LQ &lt; LS. Les références de l'analyse, dont les valeurs seuils
                sont incorrectes, sont: code du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>' ;
                code Sandre du paramètre '<xsl:value-of select="ancestor::xx:Analyse/xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="not(./text()) or not(following-sibling::xx:LSAna/text()) or ((following-sibling::xx:LSAna/text()) and (./text() &lt;= following-sibling::xx:LSAna))"/>
            <axsl:otherwise>E4.9/Toute mention de valeurs seuils DOIT respecter l'ordre de grandeur
                suivant: LD &lt; LQ &lt; LS. Les références de l'analyse, dont les valeurs seuils
                sont incorrectes, sont: code du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>' ;
                code Sandre du paramètre '<xsl:value-of select="ancestor::xx:Analyse/xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:SystemeCollecte/xx:PointMesure/xx:Prlvt/xx:Analyse/xx:LQAna" mode="M1">
        <xsl:choose>
            <axsl:when test="not(./text()) or not(preceding-sibling::xx:LDAna/text()) or ((preceding-sibling::xx:LDAna/text()) and (./text() &gt;= preceding-sibling::xx:LDAna))"/>
            <axsl:otherwise>E4.9/Toute mention de valeurs seuils DOIT respecter l'ordre de grandeur
                suivant: LD &lt; LQ &lt; LS. Les références de l'analyse, dont les valeurs seuils
                sont incorrectes, sont: code du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>' ;
                code Sandre du paramètre '<xsl:value-of select="ancestor::xx:Analyse/xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="not(./text()) or not(following-sibling::xx:LSAna/text()) or ((following-sibling::xx:LSAna/text()) and (./text() &lt;= following-sibling::xx:LSAna))"/>
            <axsl:otherwise>E4.9/Toute mention de valeurs seuils DOIT respecter l'ordre de grandeur
                suivant: LD &lt; LQ &lt; LS. Les références de l'analyse, dont les valeurs seuils
                sont incorrectes, sont: code du point de mesure '<xsl:value-of select="ancestor::xx:PointMesure[1]/child::xx:NumeroPointMesure/text()"/>'; Date
                du prélèvement: '<xsl:value-of select="ancestor::xx:Prlvt/xx:DatePrlvt/text()"/>' ;
                code Sandre du paramètre '<xsl:value-of select="ancestor::xx:Analyse/xx:Parametre/xx:CdParametre"/>'.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="/xx:FctAssain/xx:SystemeCollecte/xx:ValeurCaracteristiqueRejet" mode="M1">
        <axsl:variable name="Sup1" select="./xx:Support/xx:CdSupport/text()"/>
        <axsl:variable name="Par1" select="./xx:Parametre/xx:CdParametre/text()"/>
        <axsl:variable name="Des" select="./xx:Destination/xx:TypeOuvrageAval/text()"/>
        <axsl:variable name="DateFin" select="number(translate(./xx:DateFinPeriodeReference/text(), '-', ''))"/>
        <axsl:variable name="DateDebRef" select="number(translate(/xx:FctAssain/xx:Scenario/xx:DateDebutReference/text(), '-', ''))"/>
        <axsl:variable name="DateFinRef" select="number(translate(/xx:FctAssain/xx:Scenario/xx:DateFinReference/text(), '-', ''))"/>
        <xsl:choose>
            <axsl:when test="($DateFin &gt;= $DateDebRef) and ($DateFin &lt;= $DateFinRef)"/>
            <axsl:otherwise>E4.37/La date de fin de période de mesures des quantités de
                sous-produits évacuées par destination '<xsl:value-of select="$DateFin"/>' n'est pas
                comprise dans la période de référence du fichier (du '<xsl:value-of select="$DateDebRef"/>' au '<xsl:value-of select="$DateFinRef"/>').#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="($Sup1 = '32' or $Sup1 = '33' or $Sup1 = '35' or $Sup1 = '36') or ($Sup1 = '3')"/>
            <axsl:otherwise>E4.36/Seuls les sous-produits listés dans le scénario peuvent faire
                l'objet de mesures de quantité évacuée par destination. Le support '<xsl:value-of select="$Sup1"/>' n'est pas un sous-produit évacuable pour un système de
                collecte.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="(./xx:PeriodeCalcul != '1') or ((./xx:PeriodeCalcul = '1') and (($Des = '4') or ($Des = 'U') or ($Des = '5') or ($Des = 'C1') or ($Des = 'C2') or ($Des = 'I') or ($Des = 'S') or ($Des = 'T') or ($Des = '2') or ($Des = 'SH') or ($Des = 'MH')))"/>
            <axsl:otherwise>E4.39/La destination '<xsl:value-of select="$Des"/>' n'est pas acceptée
                en tant que destination première de sous-produits évacués.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="($Des != '4') or ($Des = '4' and ./xx:Destination/xx:CdOuvrageAval != '')"/>
            <axsl:otherwise>E4.42/Le code de la station d'épuration de destination de sous-produits
                doit être renseigné.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="(./xx:PeriodeCalcul = '1') or (./xx:PeriodeCalcul = '365')"/>
            <axsl:otherwise>E4.29/La période de calcul des quantités de sous-produits évacués par
                destination doit prendre pour valeur '1 (cumul périodique) ou '365' (cumul
                annuel).#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="($Par1 = '1098') or ($Par1 = '1099') or ($Par1 = '1799')"/>
            <axsl:otherwise>E4.26/Seuls les paramètres 'Volume','Masse' et 'Quantité de matières
                sèches' doivent être utilisés pour les mesures quantitatives de sous-produits
                évacués par destination.#</axsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <axsl:when test="(./xx:PeriodeCalcul != '365') or ((./xx:PeriodeCalcul = '365') and (substring(./xx:DateFinPeriodeReference, 6, 2) = '12') and (substring(./xx:DateFinPeriodeReference, 9, 2) = '31'))"/>
            <axsl:otherwise>E4.41/La date à indiquer pour chaque transmission de quantités annuelles
                de sous-produits évacués par destination définitive est le 31 décembre de l'année
                considérée.#</axsl:otherwise>
        </xsl:choose>
        <axsl:apply-templates mode="M1"/>
    </axsl:template>
    <axsl:template match="text()" priority="-1" mode="M1"/>
    <axsl:template match="text()" priority="-1"/>
</axsl:stylesheet>