<?xml version="1.0" encoding="UTF-8"?>
<!--
  Export FileMaker XML (FMPXMLRESULT) vers SpreadsheetML Excel 2003.
  Utilisation : xsltproc tableau_excel.xsl tableau.xml > tableau_excel.xls
  Le contenu est du SpreadsheetML Excel 2003 avec une extension .xls.
  Excel peut afficher un avertissement car le contenu reste du XML.
-->
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fmp="http://www.filemaker.com/fmpxmlresult"
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:o="urn:schemas-microsoft-com:office:office"
  xmlns:x="urn:schemas-microsoft-com:office:excel"
  exclude-result-prefixes="fmp">

  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <!-- FileMaker ne transmet pas son critère de tri. En mode auto, les
       ruptures sont activées si chaque date forme un seul bloc contigu.
       Le tri souhaité doit être effectué dans FileMaker avant l'export. -->
  <xsl:param name="ruptureDates" select="'auto'"/>
  <!-- auto, date, decor ou aucune. En cas d'ambiguïté, auto privilégie decor. -->
  <xsl:param name="rupturePar" select="'auto'"/>
  <xsl:variable name="decorField" select="/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[translate(normalize-space(@NAME), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='seq_dec__prem::nomdecors'][1]"/>
  <xsl:variable name="decorCol" select="count($decorField/preceding-sibling::fmp:FIELD) + 1"/>
  <xsl:key name="rowsByDecor" match="fmp:ROW" use="normalize-space(fmp:COL[position() = count(/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[translate(normalize-space(@NAME), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='seq_dec__prem::nomdecors'][1]/preceding-sibling::fmp:FIELD) + 1]/fmp:DATA)"/>
  <xsl:variable name="decorGroups" select="/fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[not(preceding-sibling::fmp:ROW) or normalize-space(fmp:COL[position()=$decorCol]/fmp:DATA) != normalize-space(preceding-sibling::fmp:ROW[1]/fmp:COL[position()=$decorCol]/fmp:DATA)]"/>
  <xsl:key name="rowsByDate" match="fmp:ROW" use="normalize-space(fmp:COL[24]/fmp:DATA)"/>
  <xsl:variable name="dateGroups" select="/fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[not(preceding-sibling::fmp:ROW) or normalize-space(fmp:COL[24]/fmp:DATA) != normalize-space(preceding-sibling::fmp:ROW[1]/fmp:COL[24]/fmp:DATA)]"/>
  <xsl:variable name="useDateGroups" select="$ruptureDates = '1' or ($ruptureDates = 'auto' and boolean(/fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[normalize-space(fmp:COL[24]/fmp:DATA) != '']) and not($dateGroups[generate-id() != generate-id(key('rowsByDate', normalize-space(fmp:COL[24]/fmp:DATA))[1])]))"/>
  <xsl:variable name="useDecorGroups" select="boolean($decorField) and ($rupturePar = 'decor' or ($rupturePar = 'auto' and boolean(/fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[normalize-space(fmp:COL[position()=$decorCol]/fmp:DATA) != '']) and not($decorGroups[generate-id() != generate-id(key('rowsByDecor', normalize-space(fmp:COL[position()=$decorCol]/fmp:DATA))[1])])))"/>
  <xsl:variable name="groups" select="$dateGroups[$rupturePar = 'date' or ($rupturePar = 'auto' and $useDateGroups and not($useDecorGroups))] | $decorGroups[$useDecorGroups]"/>
  <xsl:variable name="groupCol" select="24 * number(not($useDecorGroups)) + $decorCol * number($useDecorGroups)"/>

  <!-- Position du champ FileMaker contenant la couleur du décor. -->
  <xsl:variable name="couleurCol">
    <xsl:choose>
      <xsl:when test="/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[@NAME='seq_dec_COL__PREM::CodeHexaDecimal']">
        <xsl:value-of select="count(/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[@NAME='seq_dec_COL__PREM::CodeHexaDecimal']/preceding-sibling::fmp:FIELD) + 1"/>
      </xsl:when>
      <xsl:otherwise>20</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <!-- Position du champ FileMaker indiquant la couleur du texte du décor. -->
  <xsl:variable name="couleurTexteCol">
    <xsl:choose>
      <xsl:when test="/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[@NAME='seq_dec_COL__PREM::Couleur_Texte']">
        <xsl:value-of select="count(/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[@NAME='seq_dec_COL__PREM::Couleur_Texte']/preceding-sibling::fmp:FIELD) + 1"/>
      </xsl:when>
      <xsl:otherwise>21</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <!-- Position du champ FileMaker à afficher dans l'en-tête gauche. -->
  <xsl:variable name="titreMetierCol">
    <xsl:choose>
      <xsl:when test="/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[@NAME='SEQ__PREM::zc_TitreEtMetierImp']">
        <xsl:value-of select="count(/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[@NAME='SEQ__PREM::zc_TitreEtMetierImp']/preceding-sibling::fmp:FIELD) + 1"/>
      </xsl:when>
      <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <!-- Positions des trois champs FileMaker à afficher dans l'en-tête droit. -->
  <xsl:variable name="titreRealCol">
    <xsl:choose>
      <xsl:when test="/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[translate(@NAME, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='zc_titrereal']">
        <xsl:value-of select="count(/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[translate(@NAME, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='zc_titrereal']/preceding-sibling::fmp:FIELD) + 1"/>
      </xsl:when>
      <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="titreScenarCol">
    <xsl:choose>
      <xsl:when test="/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[translate(@NAME, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='zc_titrescenar']">
        <xsl:value-of select="count(/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[translate(@NAME, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='zc_titrescenar']/preceding-sibling::fmp:FIELD) + 1"/>
      </xsl:when>
      <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="titreProdCol">
    <xsl:choose>
      <xsl:when test="/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[translate(@NAME, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='zc_prod']">
        <xsl:value-of select="count(/fmp:FMPXMLRESULT/fmp:METADATA/fmp:FIELD[translate(@NAME, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='zc_prod']/preceding-sibling::fmp:FIELD) + 1"/>
      </xsl:when>
      <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:template name="cell">
    <xsl:param name="column"/>
    <xsl:param name="style" select="'data'"/>
    <ss:Cell>
      <xsl:attribute name="ss:StyleID"><xsl:value-of select="$style"/></xsl:attribute>
      <ss:Data ss:Type="String"><xsl:value-of select="fmp:COL[position()=$column]/fmp:DATA"/></ss:Data>
    </ss:Cell>
  </xsl:template>

  <xsl:template match="/">
    <!-- Demande à Windows/Excel d'ouvrir directement le résultat comme un classeur. -->
    <xsl:processing-instruction name="mso-application">progid="Excel.Sheet"</xsl:processing-instruction>
    <ss:Workbook>
      <o:DocumentProperties>
        <o:Author>CineKlee / FileMaker</o:Author>
      </o:DocumentProperties>
      <x:ExcelWorkbook>
        <x:ProtectStructure>False</x:ProtectStructure>
        <x:ProtectWindows>False</x:ProtectWindows>
      </x:ExcelWorkbook>
      <ss:Styles>
        <ss:Style ss:ID="Default" ss:Name="Normal">
          <ss:Alignment ss:Vertical="Top" ss:WrapText="1"/>
          <ss:Font ss:FontName="Arial" ss:Size="9"/>
        </ss:Style>
        <ss:Style ss:ID="title">
          <ss:Alignment ss:Horizontal="Left" ss:Vertical="Center" ss:WrapText="1"/>
          <ss:Font ss:FontName="Arial" ss:Size="14" ss:Bold="1" ss:Color="#008ECC"/>
        </ss:Style>
        <ss:Style ss:ID="identity">
          <ss:Alignment ss:Vertical="Center" ss:WrapText="1"/>
          <ss:Font ss:FontName="Arial" ss:Size="10" ss:Bold="1"/>
        </ss:Style>
        <ss:Style ss:ID="identityRight">
          <ss:Alignment ss:Horizontal="Right" ss:Vertical="Center" ss:WrapText="1"/>
          <ss:Font ss:FontName="Arial" ss:Size="10" ss:Bold="1"/>
        </ss:Style>
        <ss:Style ss:ID="header">
          <ss:Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>
          <ss:Font ss:FontName="Arial" ss:Size="8" ss:Bold="1"/>
          <ss:Interior ss:Color="#D9EAD3" ss:Pattern="Solid"/>
          <ss:Borders>
            <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
            <ss:Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
            <ss:Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
            <ss:Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
          </ss:Borders>
        </ss:Style>
        <ss:Style ss:ID="data">
          <ss:Alignment ss:Vertical="Top" ss:WrapText="1"/>
          <ss:Borders>
            <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#B7B7B7"/>
            <ss:Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#B7B7B7"/>
            <ss:Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#B7B7B7"/>
            <ss:Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#B7B7B7"/>
          </ss:Borders>
        </ss:Style>
        <ss:Style ss:ID="dateGroup">
          <ss:Alignment ss:Horizontal="Left" ss:Vertical="Center"/>
          <ss:Borders>
            <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#B7B7B7"/>
          </ss:Borders>
          <ss:Font ss:FontName="Arial" ss:Size="11" ss:Bold="1"/>
          <ss:Interior ss:Color="#D6DCE4" ss:Pattern="Solid"/>
        </ss:Style>
        <!-- Un style de fond est créé pour chaque code couleur de décor. -->
        <xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
          <xsl:variable name="couleurBrute" select="normalize-space(fmp:COL[position()=number($couleurCol)]/fmp:DATA)"/>
          <xsl:variable name="couleur" select="translate(substring($couleurBrute, 1 + number(starts-with($couleurBrute, '#'))), 'abcdef', 'ABCDEF')"/>
          <xsl:variable name="texteBlanc" select="translate(normalize-space(fmp:COL[position()=number($couleurTexteCol)]/fmp:DATA), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'blanc'"/>
          <xsl:if test="$useDecorGroups and count(. | $groups) = count($groups)">
            <ss:Style ss:ID="decorGroup-{generate-id()}" ss:Parent="dateGroup">
              <ss:Font ss:FontName="Arial" ss:Size="11" ss:Bold="1">
                <xsl:attribute name="ss:Color"><xsl:choose><xsl:when test="$texteBlanc">#FFFFFF</xsl:when><xsl:otherwise>#000000</xsl:otherwise></xsl:choose></xsl:attribute>
              </ss:Font>
              <xsl:if test="string-length($couleur) = 6 and translate($couleur, '0123456789ABCDEF', '') = ''">
                <ss:Interior ss:Color="#{string($couleur)}" ss:Pattern="Solid"/>
              </xsl:if>
            </ss:Style>
          </xsl:if>
          <xsl:if test="string-length($couleur) = 6 and string-length(translate($couleur, '0123456789ABCDEF', '')) = 0">
            <ss:Style>
              <xsl:attribute name="ss:ID">decor-<xsl:value-of select="generate-id()"/></xsl:attribute>
              <ss:Alignment ss:Vertical="Top" ss:WrapText="1"/>
              <ss:Font>
                <xsl:attribute name="ss:Color"><xsl:choose><xsl:when test="$texteBlanc">#FFFFFF</xsl:when><xsl:otherwise>#000000</xsl:otherwise></xsl:choose></xsl:attribute>
              </ss:Font>
              <ss:Interior>
                <xsl:attribute name="ss:Color">#<xsl:value-of select="$couleur"/></xsl:attribute>
                <xsl:attribute name="ss:Pattern">Solid</xsl:attribute>
              </ss:Interior>
              <ss:Borders>
                <ss:Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#B7B7B7"/>
                <ss:Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#B7B7B7"/>
                <ss:Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#B7B7B7"/>
                <ss:Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" ss:Color="#B7B7B7"/>
              </ss:Borders>
            </ss:Style>
          </xsl:if>
        </xsl:for-each>
      </ss:Styles>
      <!-- Comme dans le PDF : identité au début, titres de colonnes répétés. -->
      <ss:Worksheet ss:Name="Dépouillement accessoires">
        <ss:Names>
          <ss:NamedRange ss:Name="Print_Titles" ss:RefersTo="='Dépouillement accessoires'!R5:R5"/>
          <ss:NamedRange ss:Name="Print_Area" ss:RefersTo="='Dépouillement accessoires'!R1C1:R{5 + count(fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW) + count($groups)}C13"/>
        </ss:Names>
        <ss:Table ss:DefaultRowHeight="15">
          <ss:Column ss:Width="58"/><ss:Column ss:Width="38"/><ss:Column ss:Width="44"/>
          <ss:Column ss:Width="145"/><ss:Column ss:Width="180"/><ss:Column ss:Width="65"/>
          <ss:Column ss:Width="250"/><ss:Column ss:Width="35"/><ss:Column ss:Width="35"/>
          <ss:Column ss:Width="75"/><ss:Column ss:Width="95"/><ss:Column ss:Width="200"/>
          <ss:Column ss:Width="160"/>
          <ss:Row ss:Height="20">
            <ss:Cell ss:StyleID="identity" ss:MergeAcross="3"><ss:Data ss:Type="String"><xsl:value-of select="substring-before(fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[15]/fmp:DATA, '&#10;')"/></ss:Data></ss:Cell>
            <ss:Cell ss:Index="8" ss:StyleID="identityRight" ss:MergeAcross="5"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[position()=number($titreRealCol)]/fmp:DATA"/></ss:Data></ss:Cell>
          </ss:Row>
          <ss:Row ss:Height="20">
            <ss:Cell ss:StyleID="identity" ss:MergeAcross="3"><ss:Data ss:Type="String"><xsl:value-of select="substring-after(fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[15]/fmp:DATA, '&#10;')"/></ss:Data></ss:Cell>
            <ss:Cell ss:Index="8" ss:StyleID="identityRight" ss:MergeAcross="5"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[position()=number($titreScenarCol)]/fmp:DATA"/></ss:Data></ss:Cell>
          </ss:Row>
          <ss:Row ss:Height="20">
            <ss:Cell ss:StyleID="identity" ss:MergeAcross="3"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[position()=number($titreMetierCol)]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:Index="8" ss:StyleID="identityRight" ss:MergeAcross="5"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[position()=number($titreProdCol)]/fmp:DATA"/></ss:Data></ss:Cell>
          </ss:Row>
          <ss:Row ss:Height="27">
            <ss:Cell ss:StyleID="title" ss:MergeAcross="12"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[43]/fmp:DATA"/></ss:Data></ss:Cell>
          </ss:Row>
          <ss:Row ss:Height="30">
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[50]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[55]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[52]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[51]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[53]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[54]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[44]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[45]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[46]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[47]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[48]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[56]/fmp:DATA"/></ss:Data></ss:Cell>
            <ss:Cell ss:StyleID="header"><ss:Data ss:Type="String"><xsl:value-of select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW[1]/fmp:COL[49]/fmp:DATA"/></ss:Data></ss:Cell>
          </ss:Row>
          <xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
            <xsl:if test="count(. | $groups) = count($groups)">
              <ss:Row ss:AutoFitHeight="0" ss:Height="24">
                <ss:Cell ss:MergeAcross="12">
                  <xsl:attribute name="ss:StyleID"><xsl:choose><xsl:when test="$useDecorGroups"><xsl:value-of select="concat('decorGroup-', generate-id())"/></xsl:when><xsl:otherwise>dateGroup</xsl:otherwise></xsl:choose></xsl:attribute>
                  <ss:Data ss:Type="String"><xsl:choose>
                    <xsl:when test="normalize-space(fmp:COL[position()=$groupCol]/fmp:DATA) != ''"><xsl:value-of select="normalize-space(fmp:COL[position()=$groupCol]/fmp:DATA)"/></xsl:when>
                    <xsl:when test="$useDecorGroups">Sans décor</xsl:when>
                    <xsl:otherwise>Sans date</xsl:otherwise>
                  </xsl:choose></ss:Data>
                </ss:Cell>
              </ss:Row>
            </xsl:if>
            <!-- Calcul de la hauteur : longueur, retours à la ligne et largeur de chaque colonne. -->
            <xsl:variable name="date" select="string-length(fmp:COL[24]/fmp:DATA) div 8"/>
            <xsl:variable name="sequence" select="string-length(fmp:COL[5]/fmp:DATA) div 5"/>
            <xsl:variable name="jour" select="string-length(fmp:COL[13]/fmp:DATA) div 6"/>
            <xsl:variable name="decor" select="string-length(fmp:COL[12]/fmp:DATA) div 22"/>
            <xsl:variable name="resume" select="string-length(fmp:COL[8]/fmp:DATA) div 28"/>
            <xsl:variable name="kit" select="string-length(fmp:COL[9]/fmp:DATA) div 10"/>
            <xsl:variable name="accessoires" select="string-length(fmp:COL[21]/fmp:DATA) div 43"/>
            <xsl:variable name="accessoireVie" select="string-length(fmp:COL[22]/fmp:DATA) div 5"/>
            <xsl:variable name="meublage" select="string-length(fmp:COL[23]/fmp:DATA) div 5"/>
            <xsl:variable name="graphisme" select="string-length(fmp:COL[18]/fmp:DATA) div 13"/>
            <xsl:variable name="vehicules" select="string-length(fmp:COL[19]/fmp:DATA) div 17"/>
            <xsl:variable name="divers" select="string-length(fmp:COL[17]/fmp:DATA) div 30"/>
            <xsl:variable name="figuration" select="string-length(fmp:COL[20]/fmp:DATA) div 25"/>
            <xsl:variable name="lignes">
              <xsl:choose>
                <xsl:when test="$date &gt;= $sequence and $date &gt;= $jour and $date &gt;= $decor and $date &gt;= $resume and $date &gt;= $kit and $date &gt;= $accessoires and $date &gt;= $accessoireVie and $date &gt;= $meublage and $date &gt;= $graphisme and $date &gt;= $vehicules and $date &gt;= $divers and $date &gt;= $figuration"><xsl:value-of select="ceiling($date)"/></xsl:when>
                <xsl:when test="$sequence &gt;= $jour and $sequence &gt;= $decor and $sequence &gt;= $resume and $sequence &gt;= $kit and $sequence &gt;= $accessoires and $sequence &gt;= $accessoireVie and $sequence &gt;= $meublage and $sequence &gt;= $graphisme and $sequence &gt;= $vehicules and $sequence &gt;= $divers and $sequence &gt;= $figuration"><xsl:value-of select="ceiling($sequence)"/></xsl:when>
                <xsl:when test="$jour &gt;= $decor and $jour &gt;= $resume and $jour &gt;= $kit and $jour &gt;= $accessoires and $jour &gt;= $accessoireVie and $jour &gt;= $meublage and $jour &gt;= $graphisme and $jour &gt;= $vehicules and $jour &gt;= $divers and $jour &gt;= $figuration"><xsl:value-of select="ceiling($jour)"/></xsl:when>
                <xsl:when test="$decor &gt;= $resume and $decor &gt;= $kit and $decor &gt;= $accessoires and $decor &gt;= $accessoireVie and $decor &gt;= $meublage and $decor &gt;= $graphisme and $decor &gt;= $vehicules and $decor &gt;= $divers and $decor &gt;= $figuration"><xsl:value-of select="ceiling($decor)"/></xsl:when>
                <xsl:when test="$resume &gt;= $kit and $resume &gt;= $accessoires and $resume &gt;= $accessoireVie and $resume &gt;= $meublage and $resume &gt;= $graphisme and $resume &gt;= $vehicules and $resume &gt;= $divers and $resume &gt;= $figuration"><xsl:value-of select="ceiling($resume)"/></xsl:when>
                <xsl:when test="$kit &gt;= $accessoires and $kit &gt;= $accessoireVie and $kit &gt;= $meublage and $kit &gt;= $graphisme and $kit &gt;= $vehicules and $kit &gt;= $divers and $kit &gt;= $figuration"><xsl:value-of select="ceiling($kit)"/></xsl:when>
                <xsl:when test="$accessoires &gt;= $accessoireVie and $accessoires &gt;= $meublage and $accessoires &gt;= $graphisme and $accessoires &gt;= $vehicules and $accessoires &gt;= $divers and $accessoires &gt;= $figuration"><xsl:value-of select="ceiling($accessoires)"/></xsl:when>
                <xsl:when test="$accessoireVie &gt;= $meublage and $accessoireVie &gt;= $graphisme and $accessoireVie &gt;= $vehicules and $accessoireVie &gt;= $divers and $accessoireVie &gt;= $figuration"><xsl:value-of select="ceiling($accessoireVie)"/></xsl:when>
                <xsl:when test="$meublage &gt;= $graphisme and $meublage &gt;= $vehicules and $meublage &gt;= $divers and $meublage &gt;= $figuration"><xsl:value-of select="ceiling($meublage)"/></xsl:when>
                <xsl:when test="$graphisme &gt;= $vehicules and $graphisme &gt;= $divers and $graphisme &gt;= $figuration"><xsl:value-of select="ceiling($graphisme)"/></xsl:when>
                <xsl:when test="$vehicules &gt;= $divers and $vehicules &gt;= $figuration"><xsl:value-of select="ceiling($vehicules)"/></xsl:when>
                <xsl:when test="$divers &gt;= $figuration"><xsl:value-of select="ceiling($divers)"/></xsl:when>
                <xsl:otherwise><xsl:value-of select="ceiling($figuration)"/></xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <ss:Row ss:AutoFitHeight="0">
              <!-- Arial 9 : 12 points par ligne estimée et 4 points de marge. -->
              <xsl:attribute name="ss:Height"><xsl:choose><xsl:when test="number($lignes) * 12 + 4 &gt; 409"><xsl:text>409</xsl:text></xsl:when><xsl:when test="number($lignes) &lt; 1">16</xsl:when><xsl:otherwise><xsl:value-of select="format-number(number($lignes) * 12 + 4, '0')"/></xsl:otherwise></xsl:choose></xsl:attribute>
              <xsl:call-template name="cell"><xsl:with-param name="column" select="24"/></xsl:call-template>
              <xsl:call-template name="cell"><xsl:with-param name="column" select="5"/></xsl:call-template>
              <xsl:call-template name="cell"><xsl:with-param name="column" select="13"/></xsl:call-template>
              <xsl:choose>
                <xsl:when test="string-length(translate(substring(normalize-space(fmp:COL[position()=number($couleurCol)]/fmp:DATA), 1 + number(starts-with(normalize-space(fmp:COL[position()=number($couleurCol)]/fmp:DATA), '#'))), 'abcdef', 'ABCDEF')) = 6 and string-length(translate(translate(substring(normalize-space(fmp:COL[position()=number($couleurCol)]/fmp:DATA), 1 + number(starts-with(normalize-space(fmp:COL[position()=number($couleurCol)]/fmp:DATA), '#'))), 'abcdef', 'ABCDEF'), '0123456789ABCDEF', '')) = 0">
                  <xsl:call-template name="cell">
                    <xsl:with-param name="column" select="12"/>
                    <xsl:with-param name="style" select="concat('decor-', generate-id())"/>
                  </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:call-template name="cell"><xsl:with-param name="column" select="12"/></xsl:call-template>
                </xsl:otherwise>
              </xsl:choose>
              <xsl:call-template name="cell"><xsl:with-param name="column" select="8"/></xsl:call-template>
              <xsl:call-template name="cell"><xsl:with-param name="column" select="9"/></xsl:call-template>
              <xsl:call-template name="cell"><xsl:with-param name="column" select="21"/></xsl:call-template>
              <xsl:call-template name="cell"><xsl:with-param name="column" select="22"/></xsl:call-template>
              <xsl:call-template name="cell"><xsl:with-param name="column" select="23"/></xsl:call-template>
              <xsl:call-template name="cell"><xsl:with-param name="column" select="18"/></xsl:call-template>
              <xsl:call-template name="cell"><xsl:with-param name="column" select="19"/></xsl:call-template>
              <xsl:call-template name="cell"><xsl:with-param name="column" select="17"/></xsl:call-template>
              <xsl:call-template name="cell"><xsl:with-param name="column" select="20"/></xsl:call-template>
            </ss:Row>
          </xsl:for-each>
        </ss:Table>
        <x:WorksheetOptions>
          <x:PageSetup>
            <x:Layout x:Orientation="Landscape"/>
            <x:PageMargins x:Bottom="0.45" x:Left="0.35" x:Right="0.35" x:Top="0.45"/>
            <x:Footer x:Margin="0.2" x:Data="&amp;RPage &amp;P sur &amp;N"/>
          </x:PageSetup>
          <x:DisplayPageBreak/>
          <x:Print>
            <x:ValidPrinterInfo/>
            <x:PaperSizeIndex>9</x:PaperSizeIndex>
            <x:HorizontalResolution>600</x:HorizontalResolution>
            <x:VerticalResolution>600</x:VerticalResolution>
            <!-- Échelle fixe : toutes les colonnes tiennent sur la largeur A4 paysage
                 tout en conservant les ruptures manuelles par date. -->
            <x:Scale>52</x:Scale>
            <x:PageOrder>OverThenDown</x:PageOrder>
          </x:Print>
          <x:FreezePanes/><x:FrozenNoSplit/><x:SplitHorizontal>5</x:SplitHorizontal><x:TopRowBottomPane>5</x:TopRowBottomPane>
          <x:ProtectObjects>False</x:ProtectObjects><x:ProtectScenarios>False</x:ProtectScenarios>
        </x:WorksheetOptions>
        <!-- Rupture d'impression avant chaque nouveau groupe de date ou décor. -->
        <xsl:if test="count($groups) &gt; 1">
        <x:PageBreaks>
          <x:RowBreaks>
            <xsl:for-each select="$groups[position() &gt; 1]">
              <x:RowBreak>
                <!-- position() compte les bandeaux des groupes précédents. -->
                <x:Row><xsl:value-of select="count(preceding-sibling::fmp:ROW) + 5 + position()"/></x:Row>
              </x:RowBreak>
            </xsl:for-each>
          </x:RowBreaks>
        </x:PageBreaks>
        </xsl:if>
      </ss:Worksheet>
    </ss:Workbook>
  </xsl:template>
</xsl:stylesheet>
