<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9">

<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
<html>
<head>
    <title>Sitemap XML</title>
    <style type="text/css">
        body { font-family: sans-serif; }
        .sitemap-header { display: flex; justify-content: space-between; border-bottom: 1px solid black; margin-bottom: 1rem; }
        .sitemap-columns { font-size: 0.8rem; }
        .sitemap-container { display: flex; flex-direction: column; align-items: center; padding: 0 32vh; }
        .sitemap-body { display: flex; flex-direction: column; justify-content: start; width: 100% }
        .sitemap-meta { display: flex; font-size: 0.7rem; color: gray; }
        h2 { margin: 0; font-size: 1rem; } 
        ul { list-style-type: none; padding: 0;  }
        li { margin-bottom: 0.5rem; display: flex; justify-content: space-between; font-size: 0.8rem}
        a { text-decoration: none; color: #0073aa; }
        a:hover { text-decoration: underline; }
    </style>
</head>
<body>
    <div class="sitemap-container">
        <div class="sitemap-body">
            <h1>XML Sitemap</h1>   
            <p>Gerado por <a href="https://www.opti.marketing/">Opti</a></p>
            <xsl:choose>
                <xsl:when test="//sitemap:sitemapindex">
                    <div class="sitemap-header">
                        <h2>Sitemaps</h2>
                        <h2>Última atualização</h2>
                    </div>
                    <ul>
                        <xsl:for-each select="//sitemap:sitemap">
                            <li>
                                <a href="{sitemap:loc}">
                                    <xsl:value-of select="sitemap:loc"/>
                                </a>
                                <span><xsl:value-of select="sitemap:lastmod"/></span>
                            </li>
                        </xsl:for-each>
                    </ul>
                </xsl:when>
                
                <xsl:when test="//sitemap:urlset">
                    <div class="sitemap-header">
                        <h2>Lista de URLs</h2>
                        <h2 class="sitemap-columns">Última atualização / Frequência de Atualização / Prioridade</h2>
                    </div>
                    <ul>
                        <xsl:for-each select="//sitemap:url">
                            <li>
                                <a href="{sitemap:loc}">
                                    <xsl:value-of select="sitemap:loc"/>
                                </a>
                                <div class="sitemap-meta">
                                    <span>
                                    <xsl:value-of select="substring(sitemap:lastmod, 1, 10)"/>
                                        <xsl:text> </xsl:text>
                                        <xsl:value-of select="substring(sitemap:lastmod, 12, 8)"/>
                                        <xsl:text> </xsl:text>
                                        <xsl:value-of select="substring(sitemap:lastmod, 20, 6)"/>                                    
                                        / <xsl:value-of select="sitemap:changefreq"/> / <xsl:value-of select="sitemap:priority"/></span>
                                </div>
                            </li>
                        </xsl:for-each>
                    </ul>
                </xsl:when>
            </xsl:choose>
        </div>
    </div>    
</body>
</html>
</xsl:template>

</xsl:stylesheet>