Created
January 14, 2016 22:01
-
-
Save josephbales/6ed300cb45e20edfd356 to your computer and use it in GitHub Desktop.
XSLT to convert Wordpress RSS feed to HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> </xsl:text> | |
<xsl:element name="article" namespace=""> | |
<xsl:apply-templates select="title|pubDate|content:encoded"/> | |
</xsl:element> | |
<xsl:text> </xsl:text> | |
</xsl:template> | |
<xsl:template match="title"> | |
<xsl:text> </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> </xsl:text> | |
<xsl:element name="time" namespace=""> | |
<xsl:value-of select="."/> | |
</xsl:element> | |
</xsl:template> | |
<xsl:template match="content:encoded"> | |
<xsl:text> </xsl:text> | |
<xsl:element name="div" namespace=""> | |
<xsl:value-of select="substring-before(., ' <a rel="nofollow')" disable-output-escaping="yes"/> | |
</xsl:element> | |
<xsl:text> </xsl:text> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment