--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE xsl:stylesheet [
+<!ENTITY nbsp " ">
+]>
+
+<xsl:transform
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:fn="http://projets.admisource.gouv.fr/xemelios/namespaces#functions"
+ xmlns:added="http://projets.admisource.gouv.fr/xemelios/namespaces#added"
+ xmlns:ano="http://projets.admisource.gouv.fr/xemelios/namspaces#anomally"
+ xmlns:n="http://www.minefi.gouv.fr/cp/helios/pes_v2/facture"
+ xmlns="http://www.minefi.gouv.fr/cp/helios/pes_v2/facture"
+ xmlns:xem="http://xemelios.org/extensions/xml/functions"
+ exclude-result-prefixes="fn xem" version="2.0">
+ <!-- fr.gouv.finances.dgfip.utils.xml.helper.HelperFunction -->
+ <xsl:output method="xml" indent="yes"/>
+
+ <xsl:output encoding="ISO-8859-1"/>
+ <xsl:output version="1.0"/>
+ <xsl:param name="language" select="'fr'"/>
+
+ <xsl:template match="/*[position()=1]">
+ <xsl:if test="local-name() = 'PES_ReleveCarteAchat'">
+ <PES_ReleveCarteAchat xmlns="http://www.minefi.gouv.fr/cp/helios/pes_v2/facture"
+ xmlns:added="http://projets.admisource.gouv.fr/xemelios/namespaces#added"
+ xmlns:n="http://www.minefi.gouv.fr/cp/helios/pes_v2/facture"
+ xmlns:ano="http://projets.admisource.gouv.fr/xemelios/namespaces#anomally">
+ <xsl:for-each select="./@*">
+ <xsl:attribute name="{local-name(.)}" namespace="{namespace-uri(.)}" select="."/>
+ </xsl:for-each>
+ <xsl:for-each select="./*">
+ <xsl:call-template name="writeElement">
+ <xsl:with-param name="el" select="."/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </PES_ReleveCarteAchat>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template name="writeElement">
+ <xsl:param name="el"/>
+ <xsl:choose>
+ <xsl:when test="namespace-uri($el) = 'http://projets.admisource.gouv.fr/xemelios/namespaces#anomally'">
+ <xsl:element name="{name($el)}" namespace="http://projets.admisource.gouv.fr/xemelios/namespaces#anomally">
+ <xsl:for-each select="$el/@*">
+ <xsl:attribute name="{name(.)}" namespace="{namespace-uri(.)}">
+ <xsl:value-of select="."/>
+ </xsl:attribute>
+ </xsl:for-each>
+ <xsl:value-of select="text()" disable-output-escaping="yes"/>
+ <xsl:for-each select="$el/*">
+ <xsl:call-template name="writeElement"><xsl:with-param name="el" select="."/></xsl:call-template>
+ </xsl:for-each>
+ </xsl:element>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:element name="{name($el)}" namespace="http://www.minefi.gouv.fr/cp/helios/pes_v2/facture">
+ <xsl:variable name="IdPesFacture" select="generate-id()"/>
+ <xsl:attribute name="generated-id" namespace="http://projets.admisource.gouv.fr/xemelios/namespaces#added">
+ <xsl:value-of select="$IdPesFacture"/>
+ </xsl:attribute>
+ <xsl:if test="name($el)='PESFacture'">
+ <xsl:attribute name="primarykey" namespace="http://projets.admisource.gouv.fr/xemelios/namespaces#added">
+ <xsl:value-of select="xem:generateUniqueID()"/>
+ </xsl:attribute>
+ <xsl:attribute name="mois" namespace="http://projets.admisource.gouv.fr/xemelios/namespaces#added"><xsl:value-of select="substring(n:Date/@V,6,2)"/></xsl:attribute>
+ </xsl:if>
+ <xsl:if test="name($el)='FactureIndiv'">
+ <xsl:attribute name="fournisseur" namespace="http://projets.admisource.gouv.fr/xemelios/namespaces#added">
+ <xsl:value-of select="./n:Tiers[n:TypeTiersFacture/@V=24]/n:InfoTiers/n:Nom/@V"/>
+ </xsl:attribute>
+ <xsl:attribute name="numero_carteachat" namespace="http://projets.admisource.gouv.fr/xemelios/namespaces#added">
+ <xsl:value-of select="./n:Tiers[n:TypeTiersFacture/@V=11]/n:InfoTiers/n:IdTiers/@V"></xsl:value-of>
+ </xsl:attribute>
+ <xsl:attribute name="numero_commande" namespace="http://projets.admisource.gouv.fr/xemelios/namespaces#added">
+ <xsl:value-of select="./n:Reference[n:TypePiece/@V='COMMANDE']/n:NumeroPiece/@V"></xsl:value-of>
+ </xsl:attribute>
+ <xsl:if test="count ($el/n:Tiers[n:TypeTiersFacture/@V=11]) = 0">
+ <xsl:if test="count(../n:Tiers[n:TypeTiersFacture/@V=11]) > 0">
+ <xsl:call-template name="writeElement">
+ <xsl:with-param name="el" select="../n:Tiers[n:TypeTiersFacture/@V=11]"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:if>
+ <xsl:if test="count ($el/n:Tiers[n:TypeTiersFacture/@V=12]) = 0">
+ <xsl:if test="count(../n:Tiers[n:TypeTiersFacture/@V=12]) > 0">
+ <xsl:call-template name="writeElement">
+ <xsl:with-param name="el" select="../n:Tiers[n:TypeTiersFacture/@V=12]"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:if>
+ <xsl:if test="count ($el/n:Tiers[n:TypeTiersFacture/@V=21]) = 0">
+ <xsl:if test="count(../n:Tiers[n:TypeTiersFacture/@V=21]) > 0">
+ <xsl:call-template name="writeElement">
+ <xsl:with-param name="el" select="../n:Tiers[n:TypeTiersFacture/@V=21]"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:if>
+ <xsl:if test="count ($el/n:Tiers[n:TypeTiersFacture/@V=22]) = 0">
+ <xsl:if test="count(../n:Tiers[n:TypeTiersFacture/@V=22]) > 0">
+ <xsl:call-template name="writeElement">
+ <xsl:with-param name="el" select="../n:Tiers[n:TypeTiersFacture/@V=22]"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:if>
+ <xsl:if test="count ($el/n:Tiers[n:TypeTiersFacture/@V=23]) = 0">
+ <xsl:if test="count(../n:Tiers[n:TypeTiersFacture/@V=23]) > 0">
+ <xsl:call-template name="writeElement">
+ <xsl:with-param name="el" select="../n:Tiers[n:TypeTiersFacture/@V=23]"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:if>
+ <xsl:if test="count ($el/n:Tiers[n:TypeTiersFacture/@V=24]) = 0">
+ <xsl:if test="count(../n:Tiers[n:TypeTiersFacture/@V=24]) > 0">
+ <xsl:call-template name="writeElement">
+ <xsl:with-param name="el" select="../n:Tiers[n:TypeTiersFacture/@V=24]"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:if>
+ </xsl:if>
+ <xsl:for-each select="$el/@*">
+ <xsl:choose>
+ <xsl:when test="namespace-uri(.) = 'http://projets.admisource.gouv.fr/xemelios/namespaces#anomally'">
+ <xsl:attribute name="{local-name(.)}" namespace="http://projets.admisource.gouv.fr/xemelios/namespaces#anomally">
+ <xsl:value-of select="."/>
+ </xsl:attribute>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:attribute name="{local-name(.)}" namespace="{namespace-uri(.)}">
+ <xsl:value-of select="."/>
+ </xsl:attribute>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ <xsl:choose>
+ <xsl:when test="name($el) = 'PESFacture'">
+ <xsl:attribute name="montantHT" namespace="http://projets.admisource.gouv.fr/xemelios/namespaces#added">
+ <xsl:value-of select="format-number(sum(./n:FactureIndiv/n:TotalAPayer/n:MtTotalHT/@V),'####.##')"/>
+ </xsl:attribute>
+ <xsl:attribute name="montantTVA" namespace="http://projets.admisource.gouv.fr/xemelios/namespaces#added">
+ <xsl:value-of select="format-number(sum(./n:FactureIndiv/n:TotalAPayer/n:MtTotalTVA/@V),'####.##')"/>
+ </xsl:attribute>
+ <xsl:attribute name="montantTTC" namespace="http://projets.admisource.gouv.fr/xemelios/namespaces#added">
+ <xsl:value-of select="format-number(sum(./n:FactureIndiv/n:TotalAPayer/n:MtTotalTTC/@V),'####.##')"/>
+ </xsl:attribute>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:for-each select="$el/*">
+ <xsl:call-template name="writeElement">
+ <xsl:with-param name="el" select="."/>
+ </xsl:call-template>
+ </xsl:for-each>
+ <xsl:value-of select="$el/text()" disable-output-escaping="yes"/>
+ </xsl:element>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:template>
+</xsl:transform>