Skip to content

Commit ab56d84

Browse files
committed
create: sitemap.xsl — styling for {site}/sitemap.xml
1 parent a3c50fa commit ab56d84

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/sitemap.xsl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsl:stylesheet
3+
version="3.0"
4+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5+
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
6+
>
7+
<xsl:output method="html" indent="yes" encoding="UTF-8"/>
8+
<xsl:template match="/">
9+
<xsl:message>Powered by <a href="https://www.sitemap.style/">Sitemap Style</a></xsl:message>
10+
11+
12+
<!-- get the hostname from the first url/loc -->
13+
<xsl:variable name="hostname" select="substring-before(substring-after(/sitemap:urlset/sitemap:url[1]/sitemap:loc, '://'), '/')" />
14+
15+
<html>
16+
<head>
17+
<meta name="viewport" content="width=device-width, initial-scale=1" />
18+
<meta name="referrer" content="unsafe-url" />
19+
<title>Sitemap for <xsl:value-of select="$hostname"/></title>
20+
<link rel="stylesheet" href="https://www.sitemap.style/css/pico.classless.min.css" />
21+
</head>
22+
<body>
23+
<main class="container">
24+
<h1>Pages on <xsl:value-of select="$hostname"/></h1>
25+
<ul>
26+
<xsl:for-each select="sitemap:urlset/sitemap:url">
27+
<xsl:variable name="sitemap_loc"><xsl:value-of select="sitemap:loc"/></xsl:variable>
28+
<xsl:variable name="sitemap_lastmod"><xsl:value-of select="sitemap:lastmod"/></xsl:variable>
29+
<li>
30+
<a href="{$sitemap_loc}"><xsl:value-of select="sitemap:loc" /></a>
31+
<xsl:if test="$sitemap_lastmod!=''">
32+
(<xsl:value-of select="sitemap:lastmod" />)
33+
</xsl:if>
34+
</li>
35+
</xsl:for-each>
36+
</ul>
37+
<p><xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> pages</p>
38+
</main>
39+
</body>
40+
</html>
41+
</xsl:template>
42+
</xsl:stylesheet>

0 commit comments

Comments
 (0)