<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:s="http://www.sitemaps.org/schemas/sitemap/0.9"
	xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
	exclude-result-prefixes="s image">

	<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>

	<xsl:template match="/">
		<html lang="en">
			<head>
				<meta charset="UTF-8"/>
				<meta name="viewport" content="width=device-width, initial-scale=1"/>
				<meta name="robots" content="noindex,follow"/>
				<title>XML Sitemap</title>
				<style type="text/css">
					body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: #1e1e1e; margin: 0; background: #f6f7f7; }
					.wrap { max-width: 1040px; margin: 0 auto; padding: 32px 20px 64px; }
					h1 { font-size: 22px; margin: 0 0 4px; }
					.sub { color: #646970; font-size: 13px; margin: 0 0 24px; }
					.count { color: #646970; font-size: 13px; margin: 0 0 12px; }
					table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #dcdcde; border-radius: 8px; overflow: hidden; }
					th, td { text-align: left; padding: 10px 14px; font-size: 13px; border-bottom: 1px solid #f0f0f1; vertical-align: top; word-break: break-word; }
					th { background: #f6f7f7; font-weight: 600; color: #1e1e1e; }
					tr:last-child td { border-bottom: 0; }
					tr:hover td { background: #fafafa; }
					a { color: #2271b1; text-decoration: none; }
					a:hover { text-decoration: underline; }
					.num { color: #646970; width: 48px; }
					.meta { color: #646970; white-space: nowrap; }
				</style>
			</head>
			<body>
				<div class="wrap">
					<h1>XML Sitemap</h1>
					<p class="sub">This sitemap is generated by Nexter SEO and is meant for search engines. The styled view below is for humans.</p>
					<xsl:apply-templates/>
				</div>
			</body>
		</html>
	</xsl:template>

	<!-- Sitemap index: list of child sitemaps. -->
	<xsl:template match="s:sitemapindex">
		<p class="count">
			<xsl:text>Sitemaps: </xsl:text>
			<xsl:value-of select="count(s:sitemap)"/>
		</p>
		<table>
			<tr>
				<th class="num">#</th>
				<th>Sitemap</th>
				<th>Last Modified</th>
			</tr>
			<xsl:for-each select="s:sitemap">
				<tr>
					<td class="num"><xsl:value-of select="position()"/></td>
					<td><a href="{s:loc}"><xsl:value-of select="s:loc"/></a></td>
					<td class="meta"><xsl:value-of select="s:lastmod"/></td>
				</tr>
			</xsl:for-each>
		</table>
	</xsl:template>

	<!-- URL set: list of page URLs. -->
	<xsl:template match="s:urlset">
		<p class="count">
			<xsl:text>URLs: </xsl:text>
			<xsl:value-of select="count(s:url)"/>
		</p>
		<table>
			<tr>
				<th class="num">#</th>
				<th>URL</th>
				<th>Images</th>
				<th>Priority</th>
				<th>Change Freq.</th>
				<th>Last Modified</th>
			</tr>
			<xsl:for-each select="s:url">
				<tr>
					<td class="num"><xsl:value-of select="position()"/></td>
					<td><a href="{s:loc}"><xsl:value-of select="s:loc"/></a></td>
					<td class="meta"><xsl:value-of select="count(image:image)"/></td>
					<td class="meta"><xsl:value-of select="s:priority"/></td>
					<td class="meta"><xsl:value-of select="s:changefreq"/></td>
					<td class="meta"><xsl:value-of select="s:lastmod"/></td>
				</tr>
			</xsl:for-each>
		</table>
	</xsl:template>

</xsl:stylesheet>
