XSL Stylesheet for a XML Sitemap

Posted on Thursday 20th Jan 2011 by Luci Smethurst No Comments

Whilst XML sitemaps are great for Google, I always find they’re not so great for Humans like you and me. Their unfriendly appearance doesn’t make it immediately obvious that things are (or aren’t) happening as they’re supposed to.

That’s where XSL stylesheets come in. XSL stylesheets for XML sitemaps means that you can essentially render your XML sitemap as if it were a HTML page: easy to use and easy on the eye.

To create an ‘XML Stylesheet’ is really easy to, when you get right down to it. Simply create your template file and name it as you see fit – I’ve called our example file ‘template.xsl’ and link it in your XML sitemap like so:

<?xml-stylesheet href="/path/to/template.xsl" type="text/xsl"?>

Then we just have to deal with the code, the fun part. The CSS for your sitemaps easy – code as normal. The only area you need to pay attention to is the processing of the xml and how you code your template, as this needs to be done to the strict standard, as it is processed as such – any problems and you’ll get a parse error.

<table cellpadding="5">
 <thead>
 <tr>
 <th width="90%">URL</th>
 <th width="10%">Priority</th>
 </tr>
 </thead>
 <tbody>
 <xsl:for-each select="sitemap:urlset/sitemap:url">
 <tr>
 <td>
 <xsl:variable name="itemURL">
 <xsl:value-of select="sitemap:loc"/>
 </xsl:variable>
 <a href="{$itemURL}">
 <xsl:value-of select="sitemap:loc"/>
 </a>
 </td>
 <td>
 <xsl:value-of select="concat(sitemap:priority*100,'%')"/>
 </td>
 </tr>
 </xsl:for-each>
 </tbody>
 </table>

I’ve included an example free template to play and modify to your hearts content:

Click below to download:
Download the Template

Hooray for easy to read sitemaps! Thanks for reading today’s web design blog!

About Luci Smethurst

Luci likes geeky things, green things, and chocolate. That pretty much sums her up, really.

See all of posts.

Add on Luci Smethurst Google+

Luci Smethurst's Tweet's

  • @missrachilli hold out! you can do it -strepsil it up! Go by the 3 day rule - day 1: bad; day 2: awful; day 3: (a bit) better :) 8 minutes ago.
  • RT @daniel_c_long: Cool Photoshop action to remove gradient banding http://t.co/XQ2lUZoj via @brdrck 11 minutes ago.
This entry was posted in Tips For Web Designers and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>