xmlsitemap.xsl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Copyright (c) 2010 Dave Reid <https://www.drupal.org/user/53892>
  3. This file is free software: you may copy, redistribute and/or modify it
  4. under the terms of the GNU General Public License as published by the
  5. Free Software Foundation, either version 2 of the License, or (at your
  6. option) any later version.
  7. This file is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. This file incorporates work covered by the following copyright and
  14. permission notice:
  15. Google Sitmaps Stylesheets (GSStylesheets)
  16. Project Home: http://sourceforge.net/projects/gstoolbox
  17. Copyright (c) 2005 Baccou Bonneville SARL (http://www.baccoubonneville.com)
  18. License http://www.gnu.org/copyleft/lesser.html GNU/LGPL -->
  19. <xsl:stylesheet version="2.0"
  20. xmlns:html="http://www.w3.org/TR/REC-html40"
  21. xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
  22. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  23. <xsl:output method="html" doctype-system="about:legacy-compat" encoding="UTF-8" indent="yes" />
  24. <!-- Root template -->
  25. <xsl:template match="/">
  26. <html>
  27. <head>
  28. <title>Sitemap file</title>
  29. <script type="text/javascript" src="[jquery]"></script>
  30. <script type="text/javascript" src="[jquery-tablesort]"></script>
  31. <script type="text/javascript" src="[xsl-js]"></script>
  32. <link href="[xsl-css]" type="text/css" rel="stylesheet"/>
  33. </head>
  34. <!-- Store in $fileType if we are in a sitemap or in a siteindex -->
  35. <xsl:variable name="fileType">
  36. <xsl:choose>
  37. <xsl:when test="//sitemap:url">sitemap</xsl:when>
  38. <xsl:otherwise>siteindex</xsl:otherwise>
  39. </xsl:choose>
  40. </xsl:variable>
  41. <body>
  42. <h1>Sitemap file</h1>
  43. <xsl:choose>
  44. <xsl:when test="$fileType='sitemap'"><xsl:call-template name="sitemapTable"/></xsl:when>
  45. <xsl:otherwise><xsl:call-template name="siteindexTable"/></xsl:otherwise>
  46. </xsl:choose>
  47. <div id="footer">
  48. <p>Generated by the <a href="https://www.drupal.org/project/xmlsitemap">Drupal XML sitemap</a>.</p>
  49. </div>
  50. </body>
  51. </html>
  52. </xsl:template>
  53. <!-- siteindexTable template -->
  54. <xsl:template name="siteindexTable">
  55. <div id="information">
  56. <p>Number of sitemaps in this index: <xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"></xsl:value-of></p>
  57. </div>
  58. <table class="tablesorter siteindex">
  59. <thead>
  60. <tr>
  61. <th>Sitemap URL</th>
  62. <th>Last modification date</th>
  63. </tr>
  64. </thead>
  65. <tbody>
  66. <xsl:apply-templates select="sitemap:sitemapindex/sitemap:sitemap">
  67. <xsl:sort select="sitemap:lastmod" order="descending"/>
  68. </xsl:apply-templates>
  69. </tbody>
  70. </table>
  71. </xsl:template>
  72. <!-- sitemapTable template -->
  73. <xsl:template name="sitemapTable">
  74. <div id="information">
  75. <p>Number of URLs in this sitemap: <xsl:value-of select="count(sitemap:urlset/sitemap:url)"></xsl:value-of></p>
  76. </div>
  77. <table class="tablesorter sitemap">
  78. <thead>
  79. <tr>
  80. <th>URL location</th>
  81. <th>Last modification date</th>
  82. <th>Change frequency</th>
  83. <th>Priority</th>
  84. </tr>
  85. </thead>
  86. <tbody>
  87. <xsl:apply-templates select="sitemap:urlset/sitemap:url">
  88. <xsl:sort select="sitemap:priority" order="descending"/>
  89. </xsl:apply-templates>
  90. </tbody>
  91. </table>
  92. </xsl:template>
  93. <!-- sitemap:url template -->
  94. <xsl:template match="sitemap:url">
  95. <tr>
  96. <td>
  97. <xsl:variable name="sitemapURL"><xsl:value-of select="sitemap:loc"/></xsl:variable>
  98. <a href="{$sitemapURL}" ref="nofollow"><xsl:value-of select="$sitemapURL"></xsl:value-of></a>
  99. </td>
  100. <td><xsl:value-of select="sitemap:lastmod"/></td>
  101. <td><xsl:value-of select="sitemap:changefreq"/></td>
  102. <td>
  103. <xsl:choose>
  104. <!-- If priority is not defined, show the default value of 0.5 -->
  105. <xsl:when test="sitemap:priority">
  106. <xsl:value-of select="sitemap:priority"/>
  107. </xsl:when>
  108. <xsl:otherwise>0.5</xsl:otherwise>
  109. </xsl:choose>
  110. </td>
  111. </tr>
  112. </xsl:template>
  113. <!-- sitemap:sitemap template -->
  114. <xsl:template match="sitemap:sitemap">
  115. <tr>
  116. <td>
  117. <xsl:variable name="sitemapURL"><xsl:value-of select="sitemap:loc"/></xsl:variable>
  118. <a href="{$sitemapURL}"><xsl:value-of select="$sitemapURL"></xsl:value-of></a>
  119. </td>
  120. <td><xsl:value-of select="sitemap:lastmod"/></td>
  121. </tr>
  122. </xsl:template>
  123. </xsl:stylesheet>