Skip to content

Instantly share code, notes, and snippets.

@josephbales
Created January 14, 2016 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephbales/6ed300cb45e20edfd356 to your computer and use it in GitHub Desktop.
Save josephbales/6ed300cb45e20edfd356 to your computer and use it in GitHub Desktop.
XSLT to convert Wordpress RSS feed to HTML
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:content="http://purl.org/rss/1.0/modules/content/">
<xsl:output omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="channel">
<xsl:apply-templates select="item"/>
</xsl:template>
<xsl:template match="item">
<xsl:text>&#10;</xsl:text>
<xsl:element name="article" namespace="">
<xsl:apply-templates select="title|pubDate|content:encoded"/>
</xsl:element>
<xsl:text>&#10;</xsl:text>
</xsl:template>
<xsl:template match="title">
<xsl:text>&#10;</xsl:text>
<xsl:element name="h2" namespace="">
<xsl:element name="a" namespace="">
<xsl:attribute name="href">
<xsl:value-of select="//channel/item/link"/>
</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="pubDate">
<xsl:text>&#10;</xsl:text>
<xsl:element name="time" namespace="">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="content:encoded">
<xsl:text>&#10;</xsl:text>
<xsl:element name="div" namespace="">
<xsl:value-of select="substring-before(., ' &lt;a rel=&quot;nofollow')" disable-output-escaping="yes"/>
</xsl:element>
<xsl:text>&#10;</xsl:text>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment