Think Good
View list of my frequently visited bloglines
Tags - Categories : All | General | Software Development

The below xslt will convert RSS to google sitemap.xml format.
Note:

  • This xslt will only work for rss which has the date format like "Wed, 25 Jan 2006 16:17:16 GMT", for other formats please modify the xslt template.
  • You can upload this converted file to your blog(if supported) and point it to google sitemap.
  • Its seems like GoogleBot itself has some listener to keep updating the blog contents via feed fetcher
  • Pebble also got some blog listeners, hmm..but i yet have to learn it for better use.
  • This is not an automated one, you have update the sitemap file locally and upload it whenever the blog got updated.

--------rss2sitemap.xsl---------------

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">

	<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
	    <xsl:for-each select="rss/channel/item">
	      <url>
		    <loc><xsl:value-of select="link"/></loc>
		    <lastmod><xsl:apply-templates select="pubDate"/></lastmod>
		    <changefreq>weekly</changefreq>
		    <priority>0.8</priority>
	      </url>
	    </xsl:for-each>
	</urlset>
</xsl:template>


<!-- Template to convert rss date format to ISO8601 date format(YYYY-MM-DD) 
Sample input datetime:Wed, 25 Jan 2006 16:17:16 GMT
Sample output: 2006-01-25
For other format, please modify the below template
-->
<xsl:template match="pubDate">
	<xsl:variable name="rawMonth">
	 <xsl:value-of select="substring(., 9, 3)"/>
	</xsl:variable>
	<xsl:variable name="isoMon">
	 <xsl:choose>
	  <xsl:when test="$rawMonth='Jan'">01</xsl:when>
	  <xsl:when test="$rawMonth='Feb'">02</xsl:when>
	  <xsl:when test="$rawMonth='Mar'">03</xsl:when>
	  <xsl:when test="$rawMonth='Apr'">04</xsl:when>
	  <xsl:when test="$rawMonth='May'">05</xsl:when>
	  <xsl:when test="$rawMonth='Jun'">06</xsl:when>
	  <xsl:when test="$rawMonth='Jul'">07</xsl:when>
	  <xsl:when test="$rawMonth='Aug'">08</xsl:when>
	  <xsl:when test="$rawMonth='Sep'">09</xsl:when>
	  <xsl:when test="$rawMonth='Oct'">10</xsl:when>
	  <xsl:when test="$rawMonth='Nov'">11</xsl:when>
	  <xsl:when test="$rawMonth='Dec'">12</xsl:when>
	 </xsl:choose>
	</xsl:variable>
<xsl:value-of select="concat(substring(., 13, 4),'-',$isoMon, '-', substring(., 6, 2))"/>
</xsl:template>

</xsl:stylesheet>
--------------------------------------

Sample input balajidl.rss
Sample output google sitemap.xml


Hi I am trying to get my Pebble blog Google Sitemap compliant... Did you ever manage to automate the process? Regards Lyndon
Not yet Lyndon
Great blog! I managed to use this for another project I'm working on that involves formatting the pubDate.
How can I get this to work with a url like this: http://link.brightcove.com/services/link/bcpid1174357538?action=mrss? I am trying to build a Google video sitemap based on an MRSS feed... Thanks, Chris


Add a comment

Title
Body
HTML : b, i, blockquote, br, p, pre, a href="", ul, ol, li
Math Quiz 2 + 1 = (Helps stop blog spam)
Name
E-mail address
Website
Remember me Yes  No 

E-mail addresses are not publicly displayed, so please only leave your e-mail address if you would like to be notified when new comments are added to this blog entry (you can opt-out later).

TrackBack to http://radio.javaranch.com/balajidl/addTrackBack.action?entry=1138284553756