RSS to google sitemap.xml conveter – using xslt

Balaji D Loganathan

1 min read

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

Related posts:

5 Replies to “RSS to google sitemap.xml conveter – using xslt”

  1. Hi
    I am trying to get my Pebble blog Google Sitemap compliant…
    Did you ever manage to automate the process?
    Regards
    Lyndon

Leave a Reply

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