simple_sitemap.xsl 5.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
                xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
                xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <xsl:output method="html" encoding="UTF-8" indent="yes"/>

  <!-- Root template -->
  <xsl:template match="/">
    <html>
      <head>
        <title>[title]</title>
        <script type="text/javascript" src="[jquery]"/>
        <script type="text/javascript" src="[jquery-tablesorter]"/>
16
        <script type="text/javascript" src="[parser-date-iso8601]"/>
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
        <script type="text/javascript" src="[xsl-js]"/>
        <link href="[xsl-css]" type="text/css" rel="stylesheet"/>
      </head>
      <body>
        <h1>[title]</h1>

        <xsl:choose>
          <xsl:when test="//sitemap:url">
            <xsl:call-template name="sitemapTable"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="sitemapIndexTable"/>
          </xsl:otherwise>
        </xsl:choose>

        <div id="footer">
          <p>[generated-by]</p>
        </div>
      </body>
    </html>
  </xsl:template>

  <!-- sitemapIndexTable template -->
  <xsl:template name="sitemapIndexTable">
    <div id="information">
      <p>[number-of-sitemaps]:
        <xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"/>
      </p>
    </div>
    <table class="sitemap index">
      <thead>
        <tr>
          <th>[sitemap-url]</th>
          <th>[lastmod]</th>
        </tr>
      </thead>
      <tbody>
        <xsl:apply-templates select="sitemap:sitemapindex/sitemap:sitemap"/>
      </tbody>
    </table>
  </xsl:template>

  <!-- sitemapTable template -->
  <xsl:template name="sitemapTable">
    <div id="information">
      <p>[number-of-urls]:
        <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/>
      </p>
    </div>
    <table class="sitemap">
      <thead>
        <tr>
          <th>[url-location]</th>
          <th>[lastmod]</th>
          <th>[changefreq]</th>
          <th>[priority]</th>
          <!-- Show this header only if xhtml:link elements are present -->
          <xsl:if test="sitemap:urlset/sitemap:url/xhtml:link">
            <th>[translation-set]</th>
          </xsl:if>
          <!-- Show this header only if image:image elements are present -->
          <xsl:if test="sitemap:urlset/sitemap:url/image:image">
            <th>[images]</th>
          </xsl:if>
        </tr>
      </thead>
      <tbody>
        <xsl:apply-templates select="sitemap:urlset/sitemap:url"/>
      </tbody>
    </table>
  </xsl:template>

  <!-- sitemap:sitemap template -->
  <xsl:template match="sitemap:sitemap">
    <tr>
      <td>
        <xsl:variable name="sitemap_location">
          <xsl:value-of select="sitemap:loc"/>
        </xsl:variable>
        <a href="{$sitemap_location}">
          <xsl:value-of select="$sitemap_location"/>
        </a>
      </td>
      <td>
        <xsl:value-of select="sitemap:lastmod"/>
      </td>
    </tr>
  </xsl:template>

  <!-- sitemap:url template -->
  <xsl:template match="sitemap:url">
    <tr>
      <td>
        <xsl:variable name="url_location">
          <xsl:value-of select="sitemap:loc"/>
        </xsl:variable>
        <a href="{$url_location}" rel="nofollow">
          <xsl:value-of select="$url_location"/>
        </a>
      </td>
      <td>
        <xsl:value-of select="sitemap:lastmod"/>
      </td>
      <td>
        <xsl:value-of select="sitemap:changefreq"/>
      </td>
      <td>
        <xsl:choose>
          <!-- If priority is not defined, show the default value of 0.5 -->
          <xsl:when test="sitemap:priority">
            <xsl:value-of select="sitemap:priority"/>
          </xsl:when>
          <xsl:otherwise>0.5</xsl:otherwise>
        </xsl:choose>
      </td>
      <!-- Show this column only if xhtml:link elements are present -->
      <xsl:if test="/sitemap:urlset/sitemap:url/xhtml:link">
        <td>
          <xsl:if test="xhtml:link">
            <dl class="translation-set">
              <xsl:apply-templates select="xhtml:link"/>
            </dl>
          </xsl:if>
        </td>
      </xsl:if>
      <!-- Show this column only if image:image elements are present -->
      <xsl:if test="/sitemap:urlset/sitemap:url/image:image">
        <td>
          <xsl:if test="image:image">
            <ul class="images">
              <xsl:apply-templates select="image:image"/>
            </ul>
          </xsl:if>
        </td>
      </xsl:if>
    </tr>
  </xsl:template>

  <!-- xhtml:link template -->
  <xsl:template match="xhtml:link">
    <xsl:variable name="url_language">
      <xsl:value-of select="@hreflang"/>
    </xsl:variable>
    <xsl:variable name="url_location">
      <xsl:value-of select="@href"/>
    </xsl:variable>
    <dt>
      <xsl:value-of select="$url_language"/>
    </dt>
    <dd>
      <a href="{$url_location}" rel="nofollow">
        <xsl:value-of select="$url_location"/>
      </a>
    </dd>
  </xsl:template>

  <!-- image:image template -->
  <xsl:template match="image:image">
    <xsl:variable name="image_location">
      <xsl:value-of select="image:loc"/>
    </xsl:variable>
    <li>
      <a href="{$image_location}" rel="nofollow">
        <xsl:value-of select="$image_location"/>
      </a>
    </li>
  </xsl:template>

</xsl:stylesheet>