Skip to content

Commit 6559117

Browse files
authored
Merge pull request #40 from jadwigo/feature/xslt
[FEATURE] Add xslt to to the xml sitemap
2 parents 63aaa3d + e6957ac commit 6559117

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,14 @@ sitemapXml:
4343
4444
Note, if you have a ContentType with the property `searchable: false`, that
4545
content type will be ignored.
46+
47+
## Sitemap stylesheets
48+
49+
You can customize the sitemap with an xslt stylesheet if you copy the `templates/sitemap_xml.twig`
50+
file and the `web/sitemap.xsl` file to your theme directory and by adding the xsl-stylesheet declaration
51+
after the xml declaration so the first two lines of the `themes/{yourthemename}/sitemap_xml.twig` look like:
52+
53+
```xml
54+
<?xml version="1.0" encoding="UTF-8"?>
55+
<?xml-stylesheet type="text/xsl" href="{{ paths.theme }}/sitemap.xsl"?>
56+
```

web/sitemap.xsl

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsl:stylesheet version="2.0"
3+
xmlns:html="http://www.w3.org/TR/REC-html40"
4+
xmlns:s="http://www.sitemaps.org/schemas/sitemap/0.9"
5+
xmlns:n="http://www.google.com/schemas/sitemap-news/0.9"
6+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
7+
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
8+
<xsl:template match="/">
9+
<html xmlns="http://www.w3.org/1999/xhtml">
10+
<head>
11+
<title>XML Sitemap</title>
12+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
13+
<style type="text/css">
14+
body {
15+
font-family: Helvetica, Arial, sans-serif;
16+
font-size: 13px;
17+
color: #545353;
18+
margin: 0 auto;
19+
width: 80%;
20+
min-width: 60em;
21+
}
22+
table {
23+
border: none;
24+
border-collapse: collapse;
25+
}
26+
tr:nth-child(odd) {
27+
background-color: #eee;
28+
}
29+
tbody tr:hover {
30+
background-color: #ccc;
31+
}
32+
tbody tr:hover td,
33+
tbody tr:hover td a {
34+
color: #000;
35+
}
36+
p {
37+
margin: 10px 3px;
38+
line-height: 1.3em;
39+
}
40+
a {
41+
color: #da3114;
42+
text-decoration: none;
43+
}
44+
a:visited {
45+
color: #777;
46+
}
47+
a:hover {
48+
text-decoration: underline;
49+
}
50+
td {
51+
font-size:11px;
52+
}
53+
th {
54+
text-align:left;
55+
padding-right:30px;
56+
font-size:11px;
57+
}
58+
thead th {
59+
border-bottom: 1px solid #000;
60+
}
61+
</style>
62+
</head>
63+
<body>
64+
<div id="content">
65+
<h1>XML Sitemap</h1>
66+
<p>
67+
Generated by the <a href="http://bolt.cm/">Bolt</a> sitemap extension, this is an XML Sitemap, meant for consumption by Google.
68+
</p>
69+
<p>
70+
You can find more information about XML News sitemaps <a href="http://www.google.com/support/webmasters/bin/answer.py?hl=en&amp;answer=74288">here</a>.
71+
</p>
72+
<p>
73+
This sitemap contains <xsl:value-of select="count(s:urlset/s:url)"/> URLs.
74+
</p>
75+
<table id="sitemap" cellpadding="3">
76+
<thead>
77+
<tr>
78+
<th width="50%">Title</th>
79+
<th width="15%">Publication Date</th>
80+
</tr>
81+
</thead>
82+
<tbody>
83+
<xsl:for-each select="s:urlset/s:url">
84+
<tr>
85+
<td>
86+
<xsl:variable name="itemURL">
87+
<xsl:value-of select="s:loc"/>
88+
</xsl:variable>
89+
<a href="{$itemURL}">
90+
<xsl:value-of select="s:loc"/>
91+
</a>
92+
</td>
93+
<td>
94+
<xsl:value-of select="concat(substring(s:lastmod,0,11),concat(' ', substring(s:lastmod,12,5)))"/>
95+
</td>
96+
</tr>
97+
</xsl:for-each>
98+
</tbody>
99+
</table>
100+
</div>
101+
</body>
102+
</html>
103+
</xsl:template>
104+
</xsl:stylesheet>

0 commit comments

Comments
 (0)