gss.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Google Sitemaps Stylesheets (GSStylesheets)
  3. Project Home: http://sourceforge.net/projects/gstoolbox
  4. Copyright (c) 2005 Baccou Bonneville SARL (http://www.baccoubonneville.com)
  5. License http://www.gnu.org/copyleft/lesser.html GNU/LGPL
  6. Created by Serge Baccou
  7. 1.0 / 20 Aug 2005
  8. Changes by Johannes Müller ( http://GSiteCrawler.com/ )
  9. 1.1 / 20 Aug 2005 - sorting by clicking on column headers
  10. - open urls in new window/tab
  11. - some stylesheet/CSS cleanup
  12. Changes by Tobias Kluge ( http://enarion.net/ )
  13. 1.2 / 22 Aug 2005 - moved sitemap file and sitemap index file into one file gss.xsl
  14. 1.5 / 27 Aug 2005 - added js and css into xslt stylesheet; only gss.xsl is needed now
  15. Changes by Serge Baccou
  16. 1.3 / 23 Aug 2005 - some XSLT cleanup
  17. 1.4 / 24 Aug 2005 - sourceForge and LGPL links and logos
  18. - sorting is working for siteindex (see gss.js)
  19. Johannes Müller ( http://gsitecrawler.com/ )
  20. 1.5a/ 31 Aug 2005 - added version number in footer
  21. - removed images (don't allow tracking on other servers)
  22. 1.5b/ 05 Jul 2006 - removed (unnecessary) link to (missing) CSS file
  23. - moved necessary items from Googles CSS file intern
  24. - javascript code not compatible with Opera 9.0
  25. 1.6/ 19 Nov 2006 - Changed namespace to http://www.sitemaps.org/schemas/sitemap/0.9
  26. -->
  27. <xsl:stylesheet version="2.0"
  28. xmlns:html="http://www.w3.org/TR/REC-html40"
  29. xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
  30. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  31. <xsl:output method="html" version="1.0" encoding="iso-8859-1" indent="yes"/>
  32. <!-- Root template -->
  33. <xsl:template match="/">
  34. <html>
  35. <head>
  36. <title>Google Sitemap File for </title>
  37. <style type="text/css">
  38. <![CDATA[
  39. <!--
  40. body {
  41. font-family: arial, sans-serif;
  42. font-size: 0.8em;
  43. height:100%;
  44. }
  45. body * {
  46. font-size: 100%;
  47. }
  48. h1 {
  49. font-weight:bold;
  50. font-size:1.5em;
  51. margin-bottom:0;
  52. margin-top:1px; }
  53. h2 {
  54. font-weight:bold;
  55. font-size:1.2em;
  56. margin-bottom:0;
  57. color:#707070;
  58. margin-top:1px; }
  59. h3 {
  60. font-weight:bold;
  61. font-size:1.2em;
  62. margin-bottom:0;
  63. color:#000;
  64. margin-top:1px; }
  65. td, th {
  66. font-family: arial, sans-serif;
  67. font-size: 0.9em;
  68. }
  69. .header {
  70. font-weight: bold;
  71. font-size: 1.1em;
  72. }
  73. p.sml {
  74. font-size:0.8em;
  75. margin-top:0;
  76. }
  77. .data {
  78. border-collapse:collapse;
  79. border:1px solid #b0b0b0;
  80. margin-top:3px;
  81. width:100%;
  82. padding:5em;
  83. }
  84. .data td {
  85. border-bottom:1px solid #b0b0b0;
  86. text-align:left;
  87. padding:3px;
  88. }
  89. .sortup {
  90. background-position: right center;
  91. background-image: url(http://www.google.com/webmasters/sitemaps/images/sortup.gif);
  92. background-repeat: no-repeat;
  93. font-style:italic;
  94. white-space:pre; }
  95. .sortdown {
  96. background-position: right center;
  97. background-image: url(http://www.google.com/webmasters/sitemaps/images/sortdown.gif);
  98. background-repeat: no-repeat;
  99. font-style:italic;
  100. white-space:pre; }
  101. table.copyright {
  102. width:100%;
  103. border-top:1px solid #ddad08;
  104. margin-top:1em;
  105. text-align:center;
  106. padding-top:1em;
  107. vertical-align:top; }
  108. .copyright {
  109. color: #6F6F6F;
  110. font-size: 0.8em;
  111. }
  112. -->
  113. ]]>
  114. </style>
  115. <script language="JavaScript">
  116. <![CDATA[
  117. var selectedColor = "blue";
  118. var defaultColor = "black";
  119. var hdrRows = 1;
  120. var numeric = '..';
  121. var desc = '..';
  122. var html = '..';
  123. var freq = '..';
  124. function initXsl(tabName,fileType) {
  125. hdrRows = 1;
  126. if(fileType=="sitemap") {
  127. numeric = ".3.";
  128. desc = ".1.";
  129. html = ".0.";
  130. freq = ".2.";
  131. initTable(tabName);
  132. setSort(tabName, 3, 1);
  133. }
  134. else {
  135. desc = ".1.";
  136. html = ".0.";
  137. initTable(tabName);
  138. setSort(tabName, 1, 1);
  139. }
  140. var theURL = document.getElementById("head1");
  141. theURL.innerHTML += ' ' + location;
  142. document.title += ': ' + location;
  143. }
  144. function initTable(tabName) {
  145. var theTab = document.getElementById(tabName);
  146. for(r=0;r<hdrRows;r++)
  147. for(c=0;c<theTab.rows[r].cells.length;c++)
  148. if((r+theTab.rows[r].cells[c].rowSpan)>hdrRows)
  149. hdrRows=r+theTab.rows[r].cells[c].rowSpan;
  150. for(r=0;r<hdrRows; r++){
  151. colNum = 0;
  152. for(c=0;c<theTab.rows[r].cells.length;c++, colNum++){
  153. if(theTab.rows[r].cells[c].colSpan<2){
  154. theCell = theTab.rows[r].cells[c];
  155. rTitle = theCell.innerHTML.replace(/<[^>]+>|&nbsp;/g,'');
  156. if(rTitle>""){
  157. theCell.title = "Change sort order for " + rTitle;
  158. theCell.onmouseover = function(){setCursor(this, "selected")};
  159. theCell.onmouseout = function(){setCursor(this, "default")};
  160. var sortParams = 15; // bitmapped: numeric|desc|html|freq
  161. if(numeric.indexOf("."+colNum+".")>-1) sortParams -= 1;
  162. if(desc.indexOf("."+colNum+".")>-1) sortParams -= 2;
  163. if(html.indexOf("."+colNum+".")>-1) sortParams -= 4;
  164. if(freq.indexOf("."+colNum+".")>-1) sortParams -= 8;
  165. theCell.onclick = new Function("sortTable(this,"+(colNum+r)+","+hdrRows+","+sortParams+")");
  166. }
  167. } else {
  168. colNum = colNum+theTab.rows[r].cells[c].colSpan-1;
  169. }
  170. }
  171. }
  172. }
  173. function setSort(tabName, colNum, sortDir) {
  174. var theTab = document.getElementById(tabName);
  175. theTab.rows[0].sCol = colNum;
  176. theTab.rows[0].sDir = sortDir;
  177. if (sortDir)
  178. theTab.rows[0].cells[colNum].className='sortdown'
  179. else
  180. theTab.rows[0].cells[colNum].className='sortup';
  181. }
  182. function setCursor(theCell, mode){
  183. rTitle = theCell.innerHTML.replace(/<[^>]+>|&nbsp;|\W/g,'');
  184. if(mode=="selected"){
  185. if(theCell.style.color!=selectedColor)
  186. defaultColor = theCell.style.color;
  187. theCell.style.color = selectedColor;
  188. theCell.style.cursor = "hand";
  189. window.status = "Click to sort by '"+rTitle+"'";
  190. } else {
  191. theCell.style.color = defaultColor;
  192. theCell.style.cursor = "";
  193. window.status = "";
  194. }
  195. }
  196. function sortTable(theCell, colNum, hdrRows, sortParams){
  197. var typnum = !(sortParams & 1);
  198. sDir = !(sortParams & 2);
  199. var typhtml = !(sortParams & 4);
  200. var typfreq = !(sortParams & 8);
  201. var tBody = theCell.parentNode;
  202. while((tBody.nodeName!="TBODY") && (tBody.nodeName!="TABLE")) {
  203. tBody = tBody.parentNode;
  204. }
  205. var tabOrd = new Array();
  206. if(tBody.rows[0].sCol==colNum) sDir = !tBody.rows[0].sDir;
  207. if (tBody.rows[0].sCol>=0)
  208. tBody.rows[0].cells[tBody.rows[0].sCol].className='';
  209. tBody.rows[0].sCol = colNum;
  210. tBody.rows[0].sDir = sDir;
  211. if (sDir)
  212. tBody.rows[0].cells[colNum].className='sortdown'
  213. else
  214. tBody.rows[0].cells[colNum].className='sortup';
  215. for(i=0,r=hdrRows;r<tBody.rows.length;i++,r++){
  216. colCont = tBody.rows[r].cells[colNum].innerHTML;
  217. if(typhtml) colCont = colCont.replace(/<[^>]+>/g,'');
  218. if(typnum) {
  219. colCont*=1;
  220. if(isNaN(colCont)) colCont = 0;
  221. }
  222. if(typfreq) {
  223. switch(colCont.toLowerCase()) {
  224. case "always": { colCont=0; break; }
  225. case "hourly": { colCont=1; break; }
  226. case "daily": { colCont=2; break; }
  227. case "weekly": { colCont=3; break; }
  228. case "monthly": { colCont=4; break; }
  229. case "yearly": { colCont=5; break; }
  230. case "never": { colCont=6; break; }
  231. }
  232. }
  233. tabOrd[i] = [r, tBody.rows[r], colCont];
  234. }
  235. tabOrd.sort(compRows);
  236. for(i=0,r=hdrRows;r<tBody.rows.length;i++,r++){
  237. tBody.insertBefore(tabOrd[i][1],tBody.rows[r]);
  238. }
  239. window.status = "";
  240. }
  241. function compRows(a, b){
  242. if(sDir){
  243. if(a[2]>b[2]) return -1;
  244. if(a[2]<b[2]) return 1;
  245. } else {
  246. if(a[2]>b[2]) return 1;
  247. if(a[2]<b[2]) return -1;
  248. }
  249. return 0;
  250. }
  251. ]]>
  252. </script>
  253. </head>
  254. <!-- Store in $fileType if we are in a sitemap or in a siteindex -->
  255. <xsl:variable name="fileType">
  256. <xsl:choose>
  257. <xsl:when test="//sitemap:url">sitemap</xsl:when>
  258. <xsl:otherwise>siteindex</xsl:otherwise>
  259. </xsl:choose>
  260. </xsl:variable>
  261. <!-- Body -->
  262. <body onLoad="initXsl('table0','{$fileType}');">
  263. <!-- Text and table -->
  264. <h1 id="head1">Google Sitemap</h1>
  265. <xsl:choose>
  266. <xsl:when test="$fileType='sitemap'"><xsl:call-template name="sitemapTable"/></xsl:when>
  267. <xsl:otherwise><xsl:call-template name="siteindexTable"/></xsl:otherwise>
  268. </xsl:choose>
  269. <!-- Copyright notice -->
  270. <br/>
  271. <table class="copyright" id="table_copyright">
  272. <tr>
  273. <td>
  274. <p>Google Sitemaps: (c) 2005-2007 <a href="http://www.google.com">Google</a> - <a href="https://www.google.com/webmasters/sitemaps/stats">My Sitemaps</a> - <a href="http://www.google.com/webmasters/sitemaps/docs/en/about.html">About</a> - <a href="http://www.google.com/webmasters/sitemaps/docs/en/faq.html">FAQ</a> - <a href="http://groups-beta.google.com/group/google-sitemaps">Discussion</a> - <a href="http://sitemaps.blogspot.com/">Blog</a></p>
  275. Google Sitemaps Stylesheets v1.6: (c) 2005-2007 <a href="http://www.baccoubonneville.com">Baccou Bonneville</a> - <a href="http://sourceforge.net/projects/gstoolbox">Project</a> - <a href="http://www.baccoubonneville.com/blogs/index.php/webdesign/2005/08/20/google-sitemaps-stylesheets">Blog</a><br/>
  276. Johannes Mueller, SOFTplus <a href="http://gsitecrawler.com">GSiteCrawler</a> - Tobias Kluge, enarion.net <a href="http://enarion.net/google/phpsitemapng">phpSitemapNG</a>
  277. </td>
  278. </tr>
  279. </table>
  280. </body>
  281. </html>
  282. </xsl:template>
  283. <!-- siteindexTable template -->
  284. <xsl:template name="siteindexTable">
  285. <h2>Number of sitemaps in this Google sitemap index: <xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"></xsl:value-of></h2>
  286. <p class="sml">Click on the table headers to change sorting.</p>
  287. <table border="1" width="100%" class="data" id="table1">
  288. <tr class="header">
  289. <td>Sitemap URL</td>
  290. <td>Last modification date</td>
  291. </tr>
  292. <xsl:apply-templates select="sitemap:sitemapindex/sitemap:sitemap">
  293. <xsl:sort select="sitemap:lastmod" order="descending"/>
  294. </xsl:apply-templates>
  295. </table>
  296. </xsl:template>
  297. <!-- sitemapTable template -->
  298. <xsl:template name="sitemapTable">
  299. <h2>Number of URLs in this Google Sitemap: <xsl:value-of select="count(sitemap:urlset/sitemap:url)"></xsl:value-of></h2>
  300. <p class="sml">Click on the table headers to change sorting.</p>
  301. <table border="1" width="100%" class="data" id="table0">
  302. <tr class="header">
  303. <td>Sitemap URL</td>
  304. <td>Last modification date</td>
  305. <td>Change freq.</td>
  306. <td>Priority</td>
  307. </tr>
  308. <xsl:apply-templates select="sitemap:urlset/sitemap:url">
  309. <xsl:sort select="sitemap:priority" order="descending"/>
  310. </xsl:apply-templates>
  311. </table>
  312. </xsl:template>
  313. <!-- sitemap:url template -->
  314. <xsl:template match="sitemap:url">
  315. <tr>
  316. <td>
  317. <xsl:variable name="sitemapURL"><xsl:value-of select="sitemap:loc"/></xsl:variable>
  318. <a href="{$sitemapURL}" target="_blank" ref="nofollow"><xsl:value-of select="$sitemapURL"></xsl:value-of></a>
  319. </td>
  320. <td><xsl:value-of select="sitemap:lastmod"/></td>
  321. <td><xsl:value-of select="sitemap:changefreq"/></td>
  322. <td><xsl:value-of select="sitemap:priority"/></td>
  323. </tr>
  324. </xsl:template>
  325. <!-- sitemap:sitemap template -->
  326. <xsl:template match="sitemap:sitemap">
  327. <tr>
  328. <td>
  329. <xsl:variable name="sitemapURL"><xsl:value-of select="sitemap:loc"/></xsl:variable>
  330. <a href="{$sitemapURL}"><xsl:value-of select="$sitemapURL"></xsl:value-of></a>
  331. </td>
  332. <td><xsl:value-of select="sitemap:lastmod"/></td>
  333. </tr>
  334. </xsl:template>
  335. </xsl:stylesheet>