<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" doctype-system="about:legacy-compat" encoding="UTF-8" />
    <xsl:template match="/">
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link href="/indexer.css" rel="stylesheet" type="text/css" />
    <title>Index of <xsl:value-of select="$x_indexdir"/></title>
    </head>
    <body>
<div id="main">
<div id="header">
<!--<img src="/header.jpg" />-->
        <h1>Index of <xsl:value-of select="$x_indexdir"/></h1><hr/>
        <!-- <iframe src="./__dirsize.txt"></iframe> -->
</div>
<div id="listing">
        <table>
            <tr class="listing-header"> <th>Name</th> <th>Date</th> <th>Size</th> </tr>
            <tr class="dir-listing"> <td><a href="..">..</a></td> <td></td> <td></td> </tr>
        <xsl:for-each select="list/directory">
            <xsl:sort select="." />
            <xsl:variable name="name">
                <xsl:value-of select="." />
            </xsl:variable>
            <xsl:variable name="date">
                <xsl:value-of select="substring(@mtime,9,2)"/>-<xsl:value-of select="substring(@mtime,6,2)"/>-<xsl:value-of select="substring(@mtime,1,4)"/><xsl:text> </xsl:text>
                <xsl:value-of select="substring(@mtime,12,2)"/>:<xsl:value-of select="substring(@mtime,15,2)"/>:<xsl:value-of select="substring(@mtime,18,2)"/>
            </xsl:variable>
            <tr class="dir-listing">
                <td><a href="{$name}/"><xsl:value-of select="."/>/</a></td>
                <td><xsl:value-of select="substring(@mtime,1,10)"/></td>
                <td></td>
            </tr>
        </xsl:for-each>
        <xsl:for-each select="list/file">
            <xsl:sort select="." />
            <xsl:variable name="name">
                <xsl:value-of select="." />
            </xsl:variable>
            <xsl:if test="not($name = '__dirsize.txt')">
            <xsl:variable name="size">
                <xsl:if test="string-length(@size) &gt; 0">
                    <xsl:if test="number(@size) &gt; 0">
                        <xsl:choose>
                            <xsl:when test="@size div 1024 &lt; 1"><xsl:value-of select="@size" /> B</xsl:when>
                            <xsl:when test="@size div 1048576 &lt; 1"><xsl:value-of select="format-number((@size div 1024), '0.00')" /> KiB</xsl:when>
                            <xsl:when test="@size div 1073741824 &lt; 1"><xsl:value-of select="format-number((@size div 1048576), '0.00')" /> MiB</xsl:when>
                            <xsl:when test="@size div 1099511627776 &lt; 1"><xsl:value-of select="format-number((@size div 1073741824), '0.00')" /> GiB</xsl:when>
                            <xsl:otherwise><xsl:value-of select="format-number((@size div 1099511627776), '0.00')" /> TiB</xsl:otherwise>
                        </xsl:choose>
                    </xsl:if>
                </xsl:if>
            </xsl:variable>
            <xsl:variable name="date">
                <xsl:value-of select="substring(@mtime,9,2)"/>-<xsl:value-of select="substring(@mtime,6,2)"/>-<xsl:value-of select="substring(@mtime,1,4)"/><xsl:text> </xsl:text>
                <xsl:value-of select="substring(@mtime,12,2)"/>:<xsl:value-of select="substring(@mtime,15,2)"/>:<xsl:value-of select="substring(@mtime,18,2)"/>
            </xsl:variable>
            <tr class="file-listing">
                <td><a href="{$name}"><xsl:value-of select="."/></a></td>
                <td><xsl:value-of select="substring(@mtime,1,10)"/></td>
                <td><xsl:value-of select="$size"/></td>
            </tr>
        </xsl:if>
        </xsl:for-each>
    </table>
<hr/>
    <div id="footer">
<p>Batch Download:</p>
<p><code>wget -m -np -c -w 3 -R &quot;index.html*&quot; &quot;<xsl:value-of select="$x_siteroot" /><xsl:value-of select="$x_indexdir" />&quot;</code></p>
    </div>
    </div>
    </div>
    </body>
    </html>
    </xsl:template>
</xsl:stylesheet>

