-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-sitemap.xsl
114 lines (102 loc) · 3.26 KB
/
wp-sitemap.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
exclude-result-prefixes="sitemap"
>
<xsl:output method="html" encoding="UTF-8" indent="yes" />
<!--
Set variables for whether lastmod, changefreq or priority occur for any url in the sitemap.
We do this up front because it can be expensive in a large sitemap.
-->
<xsl:variable name="has-lastmod" select="count( /sitemap:urlset/sitemap:url/sitemap:lastmod )" />
<xsl:variable name="has-changefreq" select="count( /sitemap:urlset/sitemap:url/sitemap:changefreq )" />
<xsl:variable name="has-priority" select="count( /sitemap:urlset/sitemap:url/sitemap:priority )" />
<xsl:template match="/">
<html lang="en-US">
<head>
<title>XML Sitemap</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
color: #444;
}
#sitemap {
max-width: 980px;
margin: 0 auto;
}
#sitemap__table {
width: 100%;
border: solid 1px #ccc;
border-collapse: collapse;
}
#sitemap__table tr td.loc {
/*
* URLs should always be LTR.
* See https://core.trac.wordpress.org/ticket/16834
* and https://core.trac.wordpress.org/ticket/49949
*/
direction: ltr;
}
#sitemap__table tr th {
text-align: left;
}
#sitemap__table tr td,
#sitemap__table tr th {
padding: 10px;
}
#sitemap__table tr:nth-child(odd) td {
background-color: #eee;
}
a:hover {
text-decoration: none;
}
</style>
</head>
<body>
<div id="sitemap">
<div id="sitemap__header">
<h1>XML Sitemap</h1>
<p><a href="https://www.sitemaps.org/">Learn more about XML sitemaps.</a></p>
</div>
<div id="sitemap__content">
<p class="text">Number of URLs in this XML Sitemap: <xsl:value-of select="count( sitemap:urlset/sitemap:url )" />.</p>
<table id="sitemap__table">
<thead>
<tr>
<th class="loc">URL</th>
<xsl:if test="$has-lastmod">
<th class="lastmod">Last Modified</th>
</xsl:if>
<xsl:if test="$has-changefreq">
<th class="changefreq">Change Frequency</th>
</xsl:if>
<xsl:if test="$has-priority">
<th class="priority">Priority</th>
</xsl:if>
</tr>
</thead>
<tbody>
<xsl:for-each select="sitemap:urlset/sitemap:url">
<tr>
<td class="loc"><a href="{sitemap:loc}"><xsl:value-of select="sitemap:loc" /></a></td>
<xsl:if test="$has-lastmod">
<td class="lastmod"><xsl:value-of select="sitemap:lastmod" /></td>
</xsl:if>
<xsl:if test="$has-changefreq">
<td class="changefreq"><xsl:value-of select="sitemap:changefreq" /></td>
</xsl:if>
<xsl:if test="$has-priority">
<td class="priority"><xsl:value-of select="sitemap:priority" /></td>
</xsl:if>
</tr>
</xsl:for-each>
</tbody>
</table>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>