Created
February 19, 2013 22:03
-
-
Save netojoaobatista/4990541 to your computer and use it in GitHub Desktop.
Simple RSS2JSON using XSLT
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
#!/bin/sh | |
curl -s "http://news.php.net/group.php?group=php.doc&format=rss" |xsltproc rss2json.xsl /dev/stdin |json_reformat |
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" encoding="UTF-8"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output method="text" /> | |
<xsl:template match="channel"> | |
<xsl:text>{"channel":{</xsl:text> | |
<xsl:text>"title":"</xsl:text><xsl:value-of select="./title" /><xsl:text>",</xsl:text> | |
<xsl:text>"description":"</xsl:text><xsl:value-of select="description" /><xsl:text>",</xsl:text> | |
<xsl:text>"items":[</xsl:text> | |
<xsl:for-each select="./item"> | |
<xsl:if test="position() != 1"><xsl:text>,</xsl:text></xsl:if> | |
<xsl:apply-templates select="." /> | |
</xsl:for-each> | |
<xsl:text>]</xsl:text> | |
<xsl:text>}}</xsl:text> | |
</xsl:template> | |
<xsl:template match="item"> | |
<xsl:text>{</xsl:text> | |
<xsl:text>"link":"</xsl:text><xsl:value-of select="./link" /><xsl:text>",</xsl:text> | |
<xsl:text>"title":"</xsl:text><xsl:value-of select="./title" /><xsl:text>",</xsl:text> | |
<xsl:text>"pubDate":"</xsl:text><xsl:value-of select="pubDate" /><xsl:text>"</xsl:text> | |
<xsl:text>}</xsl:text> | |
</xsl:template> | |
<xsl:template match="/"> | |
<xsl:text>{"rss":</xsl:text> | |
<xsl:apply-templates select=".//channel" /> | |
<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