logo

Using XSLT and Microsoft's MSXML to integrate an RDF / RSS news feed into a web site

ecommnet has been using Blogger Pro for some time as the web log tool of choice for managing the content of the news column.

Just recently however Blogger Pro has changed several things, the most important of these is the format of their RSS output. Note Blogger did this without any warning, and got it wrong in the first instance, how many sites did they temporarily blind doing this I wonder?

The format of the feed has gone from a very simplified RSS XML document to a full blown RDF RSS 1.0 one. The first task was to produce the list of links and news headlins as seen on the home page. The changes in the XML of the actual RSS output from blogger now included several new name spaces who's syntax was not at all obvious. Off to the standards references for help, and finally arrived at the XSLT transform seen below, the rdf:resource prefix finally doing the trick. See an example of blogger RDF output on the next page.

References well the obvious ones are the standards for both W3 XSLT standard and RDF, as well as the RSS specification. A special mention must go to Jon Hanna and his article The R in RSS 1.0 which helped my understanding no end.


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="rdf rss l dc admin content xsl"
  version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                  xmlns:rss="http://purl.org/rss/1.0/"
                xmlns:dc="http://purl.org/dc/elements/1.1/"
                  xmlns:admin="http://webns.net/mvcb/"
                  xmlns:l="http://purl.org/rss/1.0/modules/link/"
                  xmlns:content="http://purl.org/rss/1.0/modules/content/">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/rdf:RDF">
    <div id="newslist">
        <h2>News</h2>
        <ul>
            <xsl:apply-templates select="rss:item" />
        </ul>
    </div>
</xsl:template>

<xsl:template match="rss:item">
    <li>
        <xsl:element name="a">
            <xsl:attribute name="href">
                <xsl:apply-templates select="l:source"/>
            </xsl:attribute>
            <xsl:value-of select="rss:title"/>
        </xsl:element>
    </li>
</xsl:template>


<xsl:template match="l:source"><xsl:value-of select="@rdf:resource"/></xsl:template>

</xsl:stylesheet>

The second stylesheet is used to create the full page news articles.


<?xml version='1.0'?>
<xsl:stylesheet
  version="1.0" exclude-result-prefixes="rdf rss l dc admin content xsl"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                  xmlns:rss="http://purl.org/rss/1.0/"
                xmlns:dc="http://purl.org/dc/elements/1.1/"
                  xmlns:admin="http://webns.net/mvcb/"
                  xmlns:l="http://purl.org/rss/1.0/modules/link/"
                  xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <xsl:output omit-xml-declaration="yes"/>
    <xsl:template match="/rdf:RDF">
        <xsl:for-each select="rss:item">    
            <h3 style="color:#cc0000; clear:left;">        
                <a class="headlines">        
                    <xsl:attribute name="name">            
                        <xsl:value-of select="rss:link"/>        
                    </xsl:attribute>        
                    <xsl:value-of select="rss:title"/>        
                </a>    
            </h3>    
            <p>        
                <xsl:value-of disable-output-escaping="yes" select="rss:description"/>
                <br/>
                <span class="date">
                    <xsl:value-of select="dc:creator"/>
                </span>    
            </p>    
            <hr/>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

The third stylesheet produces a series of links for the archived pages

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rss="http://purl.org/rss/1.0/"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:admin="http://webns.net/mvcb/"
xmlns:l="http://purl.org/rss/1.0/modules/link/"
xmlns:content="http://purl.org/rss/1.0/modules/content/">

<xsl:template match="/rdf:RDF">
	<div id="newslist"> 
		<h2>News Archive</h2> 
		<ul>
		  <xsl:apply-templates select="//rss:items/rdf:Seq/rdf:li" />
		</ul>
	</div>
</xsl:template>

<xsl:template match="//rss:items/rdf:Seq/rdf:li">
	<li>
	  <xsl:value-of select="@rdf:resource"/>
	</li>
</xsl:template>

<xsl:template match="l:source">
  <xsl:value-of select="@rdf:resource"/>
</xsl:template>

</xsl:stylesheet>

Links

Ted's Radio Weblog

copyright © 2003 ecommnet