<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>
    <xsl:param name="sortIndex">1</xsl:param>
    <xsl:param name="sortOrder">ascending</xsl:param>
    <xsl:variable name="newSortOrder">
        <xsl:if test="$sortOrder='ascending'">descending</xsl:if>
        <xsl:if test="$sortOrder='descending'">ascending</xsl:if>
    </xsl:variable>
    <xsl:template match="page">
        <table>
            <tr>
                <xsl:for-each select="columns/column">
                    <th class="enteteListePaire enteteListeTriable">
                        <a>
                            <xsl:attribute name="href">
                                <xsl:text>javascript:sort(</xsl:text>
                                <xsl:value-of select="position()"/>
                                <xsl:text>, '</xsl:text>
                                <xsl:value-of select="$newSortOrder"/>
                                <xsl:text>')</xsl:text>
                            </xsl:attribute>
                            <xsl:value-of select="@libelle"/>
                        </a>
                    </th>
                </xsl:for-each>
            </tr>
            <xsl:for-each select="values/line">
                <xsl:sort select="cell[position()=$sortIndex]" order="{$sortOrder}"/>
                <tr>
                    <xsl:for-each select="cell">
                        <td>
                            <xsl:value-of select="."/>
                        </td>
                    </xsl:for-each>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>
</xsl:stylesheet>
