<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp "&#160;">
]><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:n="http://www.minefi.gouv.fr/cp/helios/pes_v2/facture"
    xmlns:added="http://projets.admisource.gouv.fr/xemelios/namespaces#added"
    xmlns:ano="http://projets.admisource.gouv.fr/xemelios/namespaces#anomally"
    xmlns:data="data:uri"
    xmlns:tech="http://xemelios.org"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    version="2.0">
    <xsl:param name="elementId"/> <!-- 'PESFacture' pour afficher le releve, vide sinon -->
    <xsl:param name="numeroFacture"/>  <!-- dans le cas de l'affichage d'une FactureIndiv FactureIndiv/NumeroFacture/@V -->
    <xsl:param name="browser-destination" />
    <xsl:param name="anoId"/>    <!-- id de l'anomalie a mettre en surbrillance -->
    <xsl:param name="IdLigne" select="AA"/>
    <xsl:param name="repository"/>
    <xsl:output encoding="ISO-8859-1" method="xhtml" exclude-result-prefixes="n added ano data" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" include-content-type="no" indent="yes"/>
    <xsl:decimal-format name="decformat" 
        decimal-separator="," 
        grouping-separator=" " 
        digit="#" 
        pattern-separator=";" 
        NaN="NaN" 
        minus-sign="-"/>
    <xsl:variable name="tags-ano">
        <xsl:for-each select="//ano:Anomalie[@ano:anoId = $anoId]/ano:node">
            <xsl:element name="node">
                <xsl:attribute name="id" select="./@ano:id"/>
            </xsl:element>
        </xsl:for-each>
    </xsl:variable>
    <!-- Donnees pour les equivalences des codes -->
    <xsl:variable name="data">
    <data:data>
        <data:codePaysINSEE>
            <data:p V="99125">ALBANIE</data:p>
            <data:p V="99109">ALLEMAGNE</data:p>
            <data:p V="99130">ANDORRE</data:p>
            <data:p V="99110">AUTRICHE</data:p>
            <data:p V="99131">BELGIQUE</data:p>
            <data:p V="99148">BIELORUSSIE</data:p>
            <data:p V="99118">BOSNIE-HERZEGOVINE</data:p>
            <data:p V="99103">BOUVET (ILE)</data:p>
            <data:p V="99111">BULGARIE</data:p>
            <data:p V="99119">CROATIE</data:p>
            <data:p V="99101">DANEMARK</data:p>
            <data:p V="99134">ESPAGNE</data:p>
            <data:p V="99106">ESTONIE</data:p>
            <data:p V="99156">EX-REPUBLIQUE YOUGOSLAVE DE MACEDOINE</data:p>
            <data:p V="99101">FEROE (ILES)</data:p>
            <data:p V="99105">FINLANDE</data:p>
            <data:p V="99133">GIBRALTAR</data:p>
            <data:p V="99126">GRECE</data:p>
            <data:p V="99112">HONGRIE</data:p>
            <data:p V="99136">IRLANDE, ou EIRE</data:p>
            <data:p V="99102">ISLANDE</data:p>
            <data:p V="99127">ITALIE</data:p>
            <data:p V="99107">LETTONIE</data:p>
            <data:p V="99113">LIECHTENSTEIN</data:p>
            <data:p V="99108">LITUANIE</data:p>
            <data:p V="99137">LUXEMBOURG</data:p>
            <data:p V="99144">MALTE</data:p>
            <data:p V="99151">MOLDAVIE</data:p>
            <data:p V="99138">MONACO</data:p>
            <data:p V="99120">MONTENEGRO</data:p>
            <data:p V="99103">NORVEGE</data:p>
            <data:p V="99135">PAYS-BAS</data:p>
            <data:p V="99122">POLOGNE</data:p>
            <data:p V="99139">PORTUGAL</data:p>
            <data:p V="99141">REPUBLIQUE DEMOCRATIQUE ALLEMANDE</data:p>
            <data:p V="99142">REPUBLIQUE FEDERALE D'ALLEMAGNE</data:p>
            <data:p V="99114">ROUMANIE</data:p>
            <data:p V="99132">ROYAUME-UNI</data:p>
            <data:p V="99123">RUSSIE</data:p>
            <data:p V="99128">SAINT-MARIN</data:p>
            <data:p V="99121">SERBIE-ET-MONTENEGRO</data:p>
            <data:p V="99117">SLOVAQUIE</data:p>
            <data:p V="99145">SLOVENIE</data:p>
            <data:p V="99104">SUEDE</data:p>
            <data:p V="99140">SUISSE</data:p>
            <data:p V="99103">SVALBARD et ILE JAN MAYEN</data:p>
            <data:p V="99115">TCHECOSLOVAQUIE</data:p>
            <data:p V="99116">TCHEQUE (REPUBLIQUE)</data:p>
            <data:p V="99124">TURQUIE D'EUROPE</data:p>
            <data:p V="99155">UKRAINE</data:p>
            <data:p V="99129">VATICAN, ou SAINT-SIEGE</data:p>
            <data:p V="99212">AFGHANISTAN</data:p>
            <data:p V="99201">ARABIE SAOUDITE</data:p>
            <data:p V="99252">ARMENIE</data:p>
            <data:p V="99253">AZERBAIDJAN</data:p>
            <data:p V="99249">BAHREIN</data:p>
            <data:p V="99246">BANGLADESH</data:p>
            <data:p V="99214">BHOUTAN</data:p>
            <data:p V="99224">BIRMANIE</data:p>
            <data:p V="99225">BRUNEI</data:p>
            <data:p V="99234">CAMBODGE</data:p>
            <data:p V="99216">CHINE</data:p>
            <data:p V="99254">CHYPRE</data:p>
            <data:p V="99237">COREE</data:p>
            <data:p V="99239">COREE (REPUBLIQUE DE)</data:p>
            <data:p V="99238">COREE (REPUBLIQUE POPULAIRE DEMOCRATIQUE DE)</data:p>
            <data:p V="99247">EMIRATS ARABES UNIS</data:p>
            <data:p V="99228">ETATS MALAIS NON FEDERES</data:p>
            <data:p V="99255">GEORGIE</data:p>
            <data:p V="99223">GOA</data:p>
            <data:p V="99230">HONG-KONG</data:p>
            <data:p V="99223">INDE</data:p>
            <data:p V="99231">INDONESIE</data:p>
            <data:p V="99204">IRAN</data:p>
            <data:p V="99203">IRAQ</data:p>
            <data:p V="99207">ISRAEL</data:p>
            <data:p V="99217">JAPON</data:p>
            <data:p V="99222">JORDANIE</data:p>
            <data:p V="99211">KAMTCHATKA</data:p>
            <data:p V="99256">KAZAKHSTAN</data:p>
            <data:p V="99257">KIRGHIZISTAN</data:p>
            <data:p V="99240">KOWEIT</data:p>
            <data:p V="99241">LAOS</data:p>
            <data:p V="99205">LIBAN</data:p>
            <data:p V="99232">MACAO</data:p>
            <data:p V="99227">MALAISIE</data:p>
            <data:p V="99229">MALDIVES</data:p>
            <data:p V="99218">MANDCHOURIE</data:p>
            <data:p V="99242">MONGOLIE</data:p>
            <data:p V="99215">NEPAL</data:p>
            <data:p V="99250">OMAN</data:p>
            <data:p V="99258">OUZBEKISTAN</data:p>
            <data:p V="99213">PAKISTAN</data:p>
            <data:p V="99261">PALESTINE</data:p>
            <data:p V="99220">PHILIPPINES</data:p>
            <data:p V="99221">POSSESSIONS BRITANNIQUES AU PROCHE-ORIENT</data:p>
            <data:p V="99248">QATAR</data:p>
            <data:p V="99209">SIBERIE</data:p>
            <data:p V="99226">SINGAPOUR</data:p>
            <data:p V="99235">SRI LANKA</data:p>
            <data:p V="99206">SYRIE</data:p>
            <data:p V="99259">TADJIKISTAN</data:p>
            <data:p V="99236">TAIWAN</data:p>
            <data:p V="99219">THAILANDE</data:p>
            <data:p V="99262">TIMOR ORIENTAL</data:p>
            <data:p V="99210">TURKESTAN RUSSE</data:p>
            <data:p V="99260">TURKMENISTAN</data:p>
            <data:p V="99208">TURQUIE</data:p>
            <data:p V="99243">VIET NAM</data:p>
            <data:p V="99244">VIET NAM DU NORD</data:p>
            <data:p V="99245">VIET NAM DU SUD</data:p>
            <data:p V="99251">YEMEN</data:p>
            <data:p V="99233">YEMEN DEMOCRATIQUE</data:p>
            <data:p V="99202">YEMEN (REPUBLIQUE ARABE DU)</data:p>
            <data:p V="99319">ACORES, MADERE</data:p>
            <data:p V="99303">AFRIQUE DU SUD</data:p>
            <data:p V="99352">ALGERIE</data:p>
            <data:p V="99395">ANGOLA</data:p>
            <data:p V="99327">BENIN</data:p>
            <data:p V="99347">BOTSWANA</data:p>
            <data:p V="99331">BURKINA</data:p>
            <data:p V="99321">BURUNDI</data:p>
            <data:p V="99322">CAMEROUN</data:p>
            <data:p V="99305">CAMEROUN ET TOGO</data:p>
            <data:p V="99313">CANARIES (ILES)</data:p>
            <data:p V="99396">CAP-VERT</data:p>
            <data:p V="99323">CENTRAFRICAINE (REPUBLIQUE)</data:p>
            <data:p V="99397">COMORES</data:p>
            <data:p V="99324">CONGO</data:p>
            <data:p V="99312">CONGO (REPUBLIQUE DEMOCRATIQUE)</data:p>
            <data:p V="99326">COTE D'IVOIRE</data:p>
            <data:p V="99399">DJIBOUTI</data:p>
            <data:p V="99301">EGYPTE</data:p>
            <data:p V="99317">ERYTHREE</data:p>
            <data:p V="99315">ETHIOPIE</data:p>
            <data:p V="99328">GABON</data:p>
            <data:p V="99304">GAMBIE</data:p>
            <data:p V="99329">GHANA</data:p>
            <data:p V="99330">GUINEE</data:p>
            <data:p V="99314">GUINEE EQUATORIALE</data:p>
            <data:p V="99392">GUINEE-BISSAU</data:p>
            <data:p V="99320">ILES PORTUGAISES DE L'OCEAN INDIEN</data:p>
            <data:p V="99332">KENYA</data:p>
            <data:p V="99348">LESOTHO</data:p>
            <data:p V="99302">LIBERIA</data:p>
            <data:p V="99316">LIBYE</data:p>
            <data:p V="99333">MADAGASCAR</data:p>
            <data:p V="99334">MALAWI</data:p>
            <data:p V="99335">MALI</data:p>
            <data:p V="99350">MAROC</data:p>
            <data:p V="99390">MAURICE</data:p>
            <data:p V="99336">MAURITANIE</data:p>
            <data:p V="99393">MOZAMBIQUE</data:p>
            <data:p V="99311">NAMIBIE</data:p>
            <data:p V="99337">NIGER</data:p>
            <data:p V="99338">NIGERIA</data:p>
            <data:p V="99308">OCEAN INDIEN (TERRITOIRE BRITANNIQUE DE L')</data:p>
            <data:p V="99339">OUGANDA</data:p>
            <data:p V="99313">PRESIDES</data:p>
            <data:p V="99313">PROVINCES ESPAGNOLES D'AFRIQUE</data:p>
            <data:p V="99340">RWANDA</data:p>
            <data:p V="99389">SAHARA OCCIDENTAL</data:p>
            <data:p V="99306">SAINTE-HELENE</data:p>
            <data:p V="99394">SAO TOME-ET-PRINCIPE</data:p>
            <data:p V="99341">SENEGAL</data:p>
            <data:p V="99398">SEYCHELLES</data:p>
            <data:p V="99342">SIERRA LEONE</data:p>
            <data:p V="99318">SOMALIE</data:p>
            <data:p V="99343">SOUDAN</data:p>
            <data:p V="99307">SOUDAN ANGLO-EGYPTIEN, KENYA, OUGANDA</data:p>
            <data:p V="99391">SWAZILAND</data:p>
            <data:p V="99325">TANGER</data:p>
            <data:p V="99309">TANZANIE</data:p>
            <data:p V="99344">TCHAD</data:p>
            <data:p V="99345">TOGO</data:p>
            <data:p V="99351">TUNISIE</data:p>
            <data:p V="99346">ZAMBIE</data:p>
            <data:p V="99308">ZANZIBAR</data:p>
            <data:p V="99310">ZIMBABWE</data:p>
            <data:p V="99404">ALASKA</data:p>
            <data:p V="99425">ANGUILLA</data:p>
            <data:p V="99441">ANTIGUA-ET-BARBUDA</data:p>
            <data:p V="99431">ANTILLES NEERLANDAISES</data:p>
            <data:p V="99415">ARGENTINE</data:p>
            <data:p V="99431">ARUBA</data:p>
            <data:p V="99436">BAHAMAS</data:p>
            <data:p V="99434">BARBADE</data:p>
            <data:p V="99429">BELIZE</data:p>
            <data:p V="99425">BERMUDES</data:p>
            <data:p V="99418">BOLIVIE</data:p>
            <data:p V="99416">BRESIL</data:p>
            <data:p V="99425">CAIMAN (ILES)</data:p>
            <data:p V="99401">CANADA</data:p>
            <data:p V="99417">CHILI</data:p>
            <data:p V="99419">COLOMBIE</data:p>
            <data:p V="99406">COSTA RICA</data:p>
            <data:p V="99407">CUBA</data:p>
            <data:p V="99408">DOMINICAINE (REPUBLIQUE)</data:p>
            <data:p V="99438">DOMINIQUE</data:p>
            <data:p V="99414">EL SALVADOR</data:p>
            <data:p V="99420">EQUATEUR</data:p>
            <data:p V="99404">ETATS-UNIS</data:p>
            <data:p V="99427">GEORGIE DU SUD ET LES ILES SANDWICH DU SUD</data:p>
            <data:p V="99435">GRENADE</data:p>
            <data:p V="99430">GROENLAND</data:p>
            <data:p V="99409">GUATEMALA</data:p>
            <data:p V="99428">GUYANA</data:p>
            <data:p V="99410">HAITI</data:p>
            <data:p V="99411">HONDURAS</data:p>
            <data:p V="99426">JAMAIQUE</data:p>
            <data:p V="99403">LABRADOR</data:p>
            <data:p V="99427">MALOUINES, OU FALKLAND (ILES)</data:p>
            <data:p V="99405">MEXIQUE</data:p>
            <data:p V="99425">MONTSERRAT</data:p>
            <data:p V="99412">NICARAGUA</data:p>
            <data:p V="99413">PANAMA</data:p>
            <data:p V="99421">PARAGUAY</data:p>
            <data:p V="99422">PEROU</data:p>
            <data:p V="99432">PORTO RICO</data:p>
            <data:p V="99442">SAINT-CHRISTOPHE-ET-NIEVES</data:p>
            <data:p V="99439">SAINTE-LUCIE</data:p>
            <data:p V="99440">SAINT-VINCENT-ET-LES GRENADINES</data:p>
            <data:p V="99437">SURINAME</data:p>
            <data:p V="99432">TERR. DES ETATS-UNIS D'AMERIQUE EN AMERIQUE</data:p>
            <data:p V="99427">TERR. DU ROYAUME-UNI DANS L'ATLANTIQUE SUD</data:p>
            <data:p V="99402">TERRE-NEUVE</data:p>
            <data:p V="99431">TERRITOIRE DES PAYS-BAS</data:p>
            <data:p V="99425">TERRITOIRES DU ROYAUME-UNI AUX ANTILLES</data:p>
            <data:p V="99433">TRINITE-ET-TOBAGO</data:p>
            <data:p V="99425">TURKS ET CAIQUES (ILES)</data:p>
            <data:p V="99423">URUGUAY</data:p>
            <data:p V="99424">VENEZUELA</data:p>
            <data:p V="99425">VIERGES BRITANNIQUES (ILES)</data:p>
            <data:p V="99432">VIERGES DES ETATS-UNIS (ILES)</data:p>
            <data:p V="99501">AUSTRALIE</data:p>
            <data:p V="99501">CHRISTMAS (ILE)</data:p>
            <data:p V="99501">COCOS ou KEELING (ILES)</data:p>
            <data:p V="99502">COOK (ILES)</data:p>
            <data:p V="99508">FIDJI</data:p>
            <data:p V="99505">GUAM</data:p>
            <data:p V="99504">HAWAII (ILES)</data:p>
            <data:p V="99501">HEARD ET MACDONALD (ILES)</data:p>
            <data:p V="99513">KIRIBATI</data:p>
            <data:p V="99505">MARIANNES DU NORD (ILES)</data:p>
            <data:p V="99515">MARSHALL (ILES)</data:p>
            <data:p V="99516">MICRONESIE (ETATS FEDERES DE)</data:p>
            <data:p V="99507">NAURU</data:p>
            <data:p V="99502">NIUE</data:p>
            <data:p V="99501">NORFOLK (ILE)</data:p>
            <data:p V="99502">NOUVELLE-ZELANDE</data:p>
            <data:p V="99517">PALAOS (ILES)</data:p>
            <data:p V="99510">PAPOUASIE-NOUVELLE-GUINEE</data:p>
            <data:p V="99503">PITCAIRN (ILE)</data:p>
            <data:p V="99512">SALOMON (ILES)</data:p>
            <data:p V="99505">SAMOA AMERICAINES</data:p>
            <data:p V="99506">SAMOA OCCIDENTALES</data:p>
            <data:p V="99505">TERR. DES ETATS-UNIS D'AMERIQUE EN OCEANIE</data:p>
            <data:p V="99502">TOKELAU</data:p>
            <data:p V="99509">TONGA</data:p>
            <data:p V="99511">TUVALU</data:p>
            <data:p V="99514">VANUATU</data:p>
        </data:codePaysINSEE>
    </data:data>
    </xsl:variable>
    
    <!-- Correspondance entre le code de pays INSEE et son nom -->
    <xsl:template name="codePaysINSEE" xmlns:data="data.uri">
        <xsl:param name="codePays"/>
        <xsl:value-of select="$data/data:data/data:codePaysINSEE/data:p[@V=$codePays]/text()"/>
    </xsl:template>
    
    <xsl:template name="slash-date">
        <xsl:param name="datebrute"/>
        <date xmlns:data="data.uri" xsl:exclude-result-prefixes="data">
            <xsl:value-of select="substring($datebrute, 9, 2)"/>
            <xsl:text>/</xsl:text>
            <xsl:value-of select="substring($datebrute, 6, 2)"/>
            <xsl:text>/</xsl:text>
            <xsl:value-of select="substring($datebrute, 1, 4)"/>
        </date>
    </xsl:template>
    <xsl:template name="number">
        <xsl:param name="num"/>
        <xsl:choose>
            <xsl:when test="string-length(string($num)) = 0"/>
            <xsl:when test="number($num) = 0">0,00</xsl:when>
            <xsl:when test="string(number($num)) = 'NaN'"/>
            <xsl:otherwise>
                <xsl:value-of select="format-number($num,'# ###,00;-# ###,00','decformat')"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
    <xsl:template name="FAC_CadreFournisseur">
        <xsl:param name="fournisseur"/>
        <!-- attention, $fournisseur peut etre un Tiers ou un Emetteur -->
        <table style="margin: 0; border-collapse: collapse; border-style: solid; border-width: 1px; padding: 3px;">
            <tr>
                <td class="label noborder right">Fournisseur&#160;/&#160;Créancier&#160;:&#160;</td>
                <td class="data noborder"><xsl:value-of select="$fournisseur//n:InfoTiers/n:Nom/@V"/></td>
            </tr>
            <tr>
                <td class="label noborder right">Adresse&#160;:&#160;</td>
                <td class="data noborder">
                    <xsl:if test="string-length($fournisseur//n:Adresse/n:Adr1/@V) &gt; 0">
                        <xsl:value-of select="$fournisseur//n:Adresse/n:Adr1/@V"/>
                    </xsl:if>
                    <xsl:if test="string-length($fournisseur//n:Adresse/n:Adr2/@V) &gt; 0">
                        <xsl:value-of select="$fournisseur//n:Adresse/n:Adr2/@V"/>
                    </xsl:if>
                    <xsl:if test="string-length($fournisseur//n:Adresse/n:Adr3/@V) &gt; 0">
                        <xsl:value-of select="$fournisseur//n:Adresse/n:Adr3/@V"/>
                    </xsl:if>
                    <br/>
                    <xsl:value-of select="$fournisseur//n:Adresse/n:CP/@V"/>&nbsp;
                    <xsl:value-of select="$fournisseur//n:Adresse/n:Ville/@V"/>                    
                    <xsl:call-template name="codePaysINSEE">
                        <xsl:with-param name="codePays" select="$fournisseur//n:Adresse/n:CodPays/@V"/>
                    </xsl:call-template>
                </td>
            </tr>
            <tr>
                <td class="label noborder right">Banque&#160;:&#160;</td>
                <td class="data noborder"><xsl:value-of select="$fournisseur//n:CpteBancaire/n:LibBanc/@V"/></td>
            </tr>
            <tr>
                <td class="label noborder right">Titulaire&#160;:&#160;</td>
                <td class="data noborder"><xsl:value-of select="$fournisseur//n:CpteBancaire/n:TitCpte/@V"/></td>
            </tr>
            <tr>
                <td class="label noborder right">Compte&#160;:&#160;</td>
                    <xsl:variable name="cpte" select="$fournisseur//n:CpteBancaire"/>
                <td class="data noborder"><xsl:value-of select="$cpte/n:CodeEtab/@V"/>-<xsl:value-of select="$cpte/n:CodeGuic/@V"/>-<xsl:value-of select="$cpte/n:IdCpte/@V"/>-<xsl:value-of select="$cpte/n:CleRib/@V"/></td>
            </tr>
            <tr>
                <td class="label noborder right">SIRET&#160;:&#160;</td>
                <td class="data noborder"><xsl:value-of select="$fournisseur//n:InfoTiers/n:IdTiers/@V"/></td>
            </tr>
        </table>
    </xsl:template>
    <xsl:template name="FAC_CadreClient">
        <xsl:param name="fournisseur"/>
        <!-- attention, $fournisseur peut etre un Tiers ou un Emetteur -->
        <table style="margin: 0; border-collapse: collapse; border-style: solid; border-width: 1px; padding: 3px;">
            <tr>
                <td class="label noborder right">Client&#160;/&#160;Débiteur&#160;:&#160;</td>
                <td class="data noborder"><xsl:value-of select="$fournisseur//n:InfoTiers/n:Nom/@V"/></td>
            </tr>
            <tr>
                <td class="label noborder right">Adresse&#160;:&#160;</td>
                <td class="data noborder">
                    <xsl:if test="string-length($fournisseur//n:Adresse/n:Adr1/@V) &gt; 0">
                        <xsl:value-of select="$fournisseur//n:Adresse/n:Adr1/@V"/><br/>
                    </xsl:if>
                    <xsl:if test="string-length($fournisseur//n:Adresse/n:Adr2/@V) &gt; 0">
                        <xsl:value-of select="$fournisseur//n:Adresse/n:Adr2/@V"/><br/>
                    </xsl:if>
                    <xsl:if test="string-length($fournisseur//n:Adresse/n:Adr3/@V) &gt; 0">
                        <xsl:value-of select="$fournisseur//n:Adresse/n:Adr3/@V"/><br/>
                    </xsl:if>
                    <xsl:value-of select="$fournisseur//n:Adresse/n:CP/@V"/>&#160;
                    <xsl:value-of select="$fournisseur//n:Adresse/n:Ville/@V"/>                    
                    <xsl:call-template name="codePaysINSEE">
                        <xsl:with-param name="codePays" select="$fournisseur//n:Adresse/n:CodPays/@V"/>
                    </xsl:call-template>
                </td>
            </tr>
            <tr>
                <td class="label noborder right">SIRET&#160;:&#160;</td>
                <td class="data noborder"><xsl:value-of select="$fournisseur//n:InfoTiers/n:IdTiers/@V"/></td>
            </tr>
        </table>
    </xsl:template>
    
    <xsl:template name="FAC_CadreFacture">
        <xsl:param name="facture"/>
        <table style="width: 100%; border: solid black 1px; margine: 0;">
            <tr>
                <td class="label noborder right">Facture&#160;n&#176;&#160;:&#160;</td>
                <td class="data noborder" style="width: 3cm;"><xsl:value-of select="$facture/n:NumeroFacture/@V"/></td>
                <td class="label noborder right" style="width: 3cm;">Date d'émission : </td>
                <td class="data noborder"><xsl:call-template name="slash-date"><xsl:with-param name="datebrute" select="$facture/n:DateEmission/@V"/></xsl:call-template>
                </td>
            </tr>
            <tr>
                <td class="label noborder right">Marché&#160;n&#176;&#160;:&#160;</td>
                <td colspan="3" class="data noborder"><xsl:value-of select="$facture/n:NumeroMarche/@V"/></td>
            </tr>
            <tr>
                <td class="label noborder right">Commande&#160;n&#176;&#160;:&#160;</td>
                <td colspan="3" class="data noborder"><xsl:value-of select="$facture/n:Reference[n:TypePiece/@V='COMMANDE']/n:NumeroPiece/@V"/></td>
            </tr>
            <tr>
                <td class="label noborder right">Objet&#160;:&#160;</td>
                <td colspan="3" class="data noborder" style="width: 100%;"><xsl:value-of select="$facture/n:Objet/@V"/></td>
            </tr>
        </table>
        <br/>
        <table style="text-align: left; width: 100%; border-style: none; margin: 0; cell-spacing: 0; padding: 0; border-collapse: collapse;">
            <tbody>
                <tr>
                    <td style="width:80%; margin: 0; padding: 0;" class="noborder">
                        <table style="border-style: solid; border-width: 1px; margin-right: 2px; width: 100%; height: 100%;">
                            <tr>
                                <td class="label right noborder" style="width: 3.2cm;">Mode de règlement : </td>
                                <td class="noborder data" style="width; 17cm;"><xsl:value-of select="$facture/n:ModalitesReglement/@V"/></td>
                            </tr>
                            <tr>
                                <td class="label right noborder">Conditions générales : </td>
                                <td class="noborder data"><xsl:value-of select="$facture/n:ConditionsGen/@V"/></td>
                            </tr>
                        </table>
                    </td>
                    <td style="width: 8px;" class="noborder"/>
                    <td class="noborder" style="margin: 0; padding: 0;">
                        <table style="border-style: solid; border-width: 1px; width: 100%; height: 100%;">
                            <tr>
                                <td class="label noborder right" style="width: 2cm;">Total HT : </td>
                                <td class="noborder right data"><xsl:call-template name="number"><xsl:with-param name="num" select="./n:TotalAPayer/n:MtTotalHT/@V"/></xsl:call-template></td>
                            </tr>
                            <tr>
                                <td class="label right noborder">Total TVA : </td>
                                <td class="noborder right data"><xsl:call-template name="number"><xsl:with-param name="num" select="./n:TotalAPayer/n:MtTotalTVA/@V"/></xsl:call-template></td>
                            </tr>
                            <tr>
                                <td class="label noborder right">Total TTC : </td>
                                <td class="noborder right data"><xsl:call-template name="number"><xsl:with-param name="num" select="./n:TotalAPayer/n:MtTotalTTC/@V"/></xsl:call-template></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </tbody>
        </table>
        
        <xsl:if test="count(//n:LigneFacture[n:Taux]) gt 0">
            <br/>
            <table style="text-align: left;"  class="tableau3">
                <thead>
                    <tr>
                        <td class="label" colspan="2">Totaux T.V.A par Taux</td>
                    </tr>
                    <tr>
                        <td class="label">Taux</td>
                        <td class="label">Montant</td>
                    </tr>
                </thead>
                <tbody>
                    <xsl:for-each-group select="//n:LigneFacture/n:Taux" group-by="@V">
                        <xsl:sort select="current-grouping-key()"/>
                        <tr>
                            <td class="data right"><xsl:value-of select="current-grouping-key()"/>&#160;%</td>
                            <td class="data right">
                                <xsl:call-template name="number"><xsl:with-param name="num" select="sum(//n:LigneFacture[n:Taux/@V=current-grouping-key()]/n:MtTVA/@V)"/></xsl:call-template>
                            </td>
                        </tr>
                    </xsl:for-each-group>
                </tbody>
            </table>
        </xsl:if>
        
        <br/>
        <table style="border-collapse: collapse; margin: 0; padding: 0; width: 100%; -fs-table-paginate: paginate; border-style: solid; border-width: 1px;">
            <colgroup>
                <col width="100%"/>
                <col/>
                <col/>
                <col/>
                <col/>
                <col/>
                <col/>
                <col/>
                <col/>
                <col/>
            </colgroup>
            <thead>
                <tr>
                    <td class="label center" rowspan="2">Libellé</td>
                    <td class="label center" rowspan="2">Code</td>
                    <td class="label center" rowspan="1" colspan="2">Période&#160;de&#160;facturation</td>
                    <td class="label center" rowspan="2">Quantité</td>
                    <td class="label center" rowspan="2">Unité</td>
                    <td class="label center" rowspan="2">Prix&#160;Unitaire</td>
                    <td class="label center" rowspan="2">Montant&#160;HT</td>
                    <td class="label center" rowspan="2">Taux&#160;TVA</td>
                    <td class="label center" rowspan="2">Montant&#160;TVA</td>
                    <td class="label center" rowspan="2">Montant&#160;TTC</td>
                </tr>
                <tr>
                    <td class="label center">Début</td>
                    <td class="label center">Fin</td>
                </tr>
            </thead>
            <!-- LIGNES DE FACTURE DE CETTE FACTURE -->
            <xsl:for-each select="$facture/n:LigneFacture">
                <xsl:element name="tr">
                    <xsl:attribute name="style">page-break-inside: avoid;<xsl:if test="@added:generated-id = $IdLigne"> background-color: #FFFF66;</xsl:if></xsl:attribute>
                    <td class="data"><xsl:value-of select="./n:Libelle/@V"/>
                        <xsl:if test="n:Caracteristique">
                            <br/><div style="margin-left: 1em;">
                                <xsl:for-each select="n:Caracteristique">
                                    <xsl:variable name="codeCarac" select="./n:Code/@V"/>
                                    <xsl:value-of select="$repository/n:DOC_PES_Facture/n:Nomenclatures/n:NomenclatureCaracteristique/n:Correspondance[n:Code/@V=$codeCarac]/n:Libelle/@V"/>: <xsl:value-of select="./n:Valeur/@V"/><br/>
                                </xsl:for-each>
                            </div>
                        </xsl:if></td>
                    <td class="data"><xsl:value-of select="./n:CodeProduit/@V"/></td>
                    <xsl:choose>
                        <xsl:when test="exists(./n:Date)">
                            <td class="data" colspan="2"><xsl:for-each select="./n:Date"><xsl:call-template name="slash-date"><xsl:with-param name="datebrute" select="./@V"/></xsl:call-template><xsl:if test="not(position()=last())"><br/></xsl:if></xsl:for-each></td>
                        </xsl:when>
                        <xsl:otherwise>
                            <td class="data"><xsl:call-template name="slash-date"><xsl:with-param name="datebrute" select="./n:DateDebut/@V"/></xsl:call-template></td>
                            <td class="data"><xsl:call-template name="slash-date"><xsl:with-param name="datebrute" select="./n:DateFin/@V"/></xsl:call-template></td>
                        </xsl:otherwise>
                    </xsl:choose>
                    <td class="data right"><xsl:value-of select="./n:Quantite/@V"/></td>
                    <td class="data"><xsl:choose>
                        <xsl:when test="exists(./n:Unite)"><xsl:value-of select="tech:escape(./n:Unite/@V)"/></xsl:when>
                    </xsl:choose>
                    </td>
                    <td class="data right"><xsl:call-template name="number"><xsl:with-param name="num" select="./n:MtUnitaire/@V"/></xsl:call-template></td>
                    <td class="data right"><xsl:call-template name="number"><xsl:with-param name="num" select="./n:MtHT/@V"/></xsl:call-template></td>
                    <td class="data right"><xsl:call-template name="number"><xsl:with-param name="num" select="./n:TauxTVA/@V"/></xsl:call-template></td>
                    <td class="data right"><xsl:call-template name="number"><xsl:with-param name="num" select="./n:MtTVA/@V"/></xsl:call-template></td>
                    <td class="data right"><xsl:call-template name="number"><xsl:with-param name="num" select="./n:MtTTC/@V"/></xsl:call-template></td>
                </xsl:element>     
            </xsl:for-each>
        </table>

    </xsl:template>

    <!-- debut du document -->
    <xsl:template match="/n:DOC_PES_Facture">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" style="page: landscape">
            <head>
                <style type="text/css" media="all">
                    
                    body {
                        margin: 1cm 1cm 1cm 1cm; 
                        font-family: verdana, sans-serif;
                        font-size: 10px;
                        background-color: #FFFFFF;
                    }

                    .anomalie { background-color: #FFFF66; }
                    tr { margin: 0; }
                    td {
                        margin: 0;
                        border-style: inset;
                        border-width: 1px;
                        border-color: black;
                        vertical-align: top;
                        line-height: 13px;
                    }

                    .label { font-family: Verdana, Arial, Sans-serif; font-size: 10px; font-weight: bold; }
                    .data { font-family: Verdana, Arial, Sans-serif; font-size: 10px; }
                    
                    .bordHaut   { border-top: solid 1px #000000; }
                    .bordGauche { border-left: solid 1px #000000; }
                    .bordBas    { border-bottom: solid 1px #000000; }
                    .bordDroit  { border-right: solid 1px #000000; }

                    noupper { border-top-style: none; }
                    :link { color: #00c; background: transparent }
                    :visited { color: #609; background: transparent }
                    a:active { color: #c00; background: transparent }
                    a:link img, a:visited img { border-style: none }
                    .gras { font-weight: bold; }
                    
                    .total {
                    position: relative;
                    left: 23cm;
                    width: 6cm;
                    }
                    
                    .noborder { border-style: none; }
                    .right { text-align: right; }
                    .center { text-align: center; }
                </style>
                <style media="print">
                    @page portrait { size: 210mm 297mm; }
                    @page landscape { size: 297mm 210mm; }
                    body { font-family: verdana, sans-serif; font-size: 10px; width: 210mm; margin: 0px; }
				    a { text-decoration: none; color: black;}
				    .label { font-family: Verdana, Arial, Sans-serif; font-size: 9px; font-weight: bold; }
				    .data { font-family: Verdana, Arial, Sans-serif; font-size: 9px; }
                </style>
                <title>Facture Dépense</title>
                
            </head>
            <body>
                <!-- pour une facture -->
                <xsl:for-each select="./n:PESFacture/n:FactureIndiv[n:NumeroFacture/@V = $numeroFacture]">
                    <!-- FOURNISSEUR -->
                    <xsl:variable name="fournisseur">
                        <xsl:choose>
                            <xsl:when test="exists(./n:Tiers[n:TypeTiersFacture/@V=24])"><xsl:copy-of select="./n:Tiers[n:TypeTiersFacture/@V=24]"/></xsl:when>
                            <xsl:otherwise><xsl:copy-of select="/n:DOC_PES_Facture/n:Emetteur"/></xsl:otherwise>
                        </xsl:choose>
                    </xsl:variable>
                    <table style="width: 100%; margin: 0; padding: 0; border-style: none;">
                        <tr>
                            <td style="width: 50%; border-style: none; margin: 0; padding: 0;"><xsl:call-template name="FAC_CadreFournisseur">
                                <xsl:with-param name="fournisseur" select="$fournisseur"/>
                            </xsl:call-template></td>
                            <td style="width: 50%; text-align: right; border-style: none; margin: 0; padding: 0;">
                                <xsl:call-template name="FAC_CadreClient">
                                    <xsl:with-param name="fournisseur" select="./n:Debiteur"/>
                                </xsl:call-template>
                            </td>
                        </tr>
                    </table>
                    
                    <br/>
                    <!-- FACTURE -->
                    <xsl:call-template name="FAC_CadreFacture">
                        <xsl:with-param name="facture" select="."/>
                    </xsl:call-template>
                </xsl:for-each>
            </body>        
            
            </html>
    </xsl:template>

    <xsl:function name="tech:escape" as="xs:string">
        <xsl:param name="s" as="xs:string"/>
        <xsl:sequence select="replace($s, ' ', '&#160;')"/>
    </xsl:function>
</xsl:stylesheet>
