Published:
Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.
As a followup to my post about creating a dynamic sitemap using Coldfusion, today I want to talk about how to style a sitemap using xsl and Coldfusion.
Note: I have tried to explain the xsl transformation rule I used here so this will be my longest post to date. However you can skip pages 3 and 4 if you are not interested in understanding the fine details.
Overcoming the limitations of Sitemaps
While xml sitemaps are a great for seo purposes, as a human usability feature they are less than optimal. They normally display in a browser as an ugly tree structure of nodes. This is not user friendly to look at, and further does not provide a direct link to the webpages listed in the node. Fortunately by using xsl we can convert our xml sitemap into a user friendly interactive webpage while webspiders such as googlebot still see a standard xml file.
In order to maintain a consistent look with the rest of our site we will use coldfusion to load our existing site template as our xsl file.
Step 1: Set the Sitemap to Use XSL
To start off lets look at a simple sitemap xml structure consisting of the xml declaration and a urlset wrapping some url nodes.
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>http://www.neiland.net/</loc>
<lastmod>2011-03-05</lastmod>
<changefreq>daily</changefreq>
<priority>1</priority>
</url>
<url>
<loc>http://www.neiland.net/blog/</loc>
<lastmod>2011-03-05</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
</urlset>
In order to style of sitemap using xsl we replace the xml declaration with a call to our xsl file as follows.
<?xml-stylesheet type="text/xsl" href="http://www.neiland.net/sitemap.xsl"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>http://www.neiland.net/</loc>
<lastmod>2011-03-05</lastmod>
<changefreq>daily</changefreq>
<priority>1</priority>
</url>
<url>
<loc>http://www.neiland.net/blog/</loc>
<lastmod>2011-03-05</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Reader Comments