<?xml version="1.0" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" indent="yes"/>

  <!-- Transformer un élément ou un attribut : 
       quelconque -> on recopie
       table      -> on tourne -->

  <xsl:template match="*|@*">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
      <xsl:choose>
	<xsl:when test="name()='table'">
	  <xsl:call-template name="TourneTable">
	    <xsl:with-param name="iCol" select="1" />
	    <xsl:with-param name="laTable" select="." />
	  </xsl:call-template>
	</xsl:when>
	<xsl:otherwise>
	  <xsl:apply-templates />
	</xsl:otherwise>
      </xsl:choose>
    </xsl:copy>
  </xsl:template>


  <!-- La fonction qui tourne une colonne + appel sur la colonne suivante -->

  <xsl:template name="TourneTable">
    <xsl:param name="iCol" />
    <xsl:param name="laTable" />
    <xsl:variable name="cases" select="$laTable/tr/*[position()=$iCol]" />
    <xsl:if test="count($cases)>0">
      <tr>
	<xsl:apply-templates select="$cases" />
      </tr>
      <xsl:call-template name="TourneTable">
	<xsl:with-param name="iCol" select="$iCol+1" />
	<xsl:with-param name="laTable" select="$laTable" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>


</xsl:stylesheet>

