Jump to content

XML to RSS (any version)


crypticheart07

Recommended Posts

Hi,I am new to working with the XML language, and I was wanting to turn an unstylized XML document tree feed (that I have limited control over) into a subscribeable RSS feed through XSLT.Where should one begin with this process? I have picked up books and read online tutorials, but none of them really have answers to this specific question...although I have read that it is possible to transform from XML to RSS with XSLT.I'm sure if I was provided some kind of theoretical example, I'd be able to get to work.I'm also happy to share with you what I'm working with below:https://www.brownpapertickets.com/api2/even...=academytheatreThank you for your help.

Link to comment
Share on other sites

Simply write templates that map those elements of your input format to the desired result format e.g.

<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">  <xsl:output method="xml" indent="yes"/>  <xsl:template match="document">	<rss version="2.0">	  <channel>		<title>Example</title>		<xsl:apply-templates/>	  </channel>   </rss>  </xsl:template>  <xsl:template match="event">	<item>	  <xsl:apply-templates select="title | description | link"/>	</item>  </xsl:template>  <!-- simply copy should suffice for stuff like title or link -->  <xsl:template match="event/*">	<xsl:copy>	  <xsl:apply-templates/>   </xsl:copy>  </xsl:template>  <!-- if needed add more specific templates here --></xsl:stylesheet>

That should give you an idea how to approach it. What is difficult with XSLT 1.0 is handling and generating dates, XSLT 2.0 has better support for that although I am not sure RSS date format is support out of the box, you might need to write your own function for that, but XSLT 2.0 can handle that.

Link to comment
Share on other sites

Handling dates is the least of my worries at the moment. (While it would be nice, my main objective is creating a valid RSS feed. -- And if dates are not necessary, then its okay.)So this is my current XML feed below:

<?xml version="1.0"?><listings><event> <name>Platinum Championship Wrestling</name> <description>The PCW Championship Fridays at 8 P.M.</description> <location>Academy Theatre, 119 Center St., Avondale Estates, GA, 30002</location> <contact>TEL: 404-474-8332</contact> <link>http://www.brownpapertickets.com/event/130787</link></event><event> <name>BattleActs! With Laughing Matters</name> <description>An Improv Comedy Competition! 8 Start, 1 Survives!</description> <location>Academy Theatre, 119 Center St., Avondale Estates, GA, 30002</location> <contact>TEL: 404-474-8332</contact> <link>http://www.brownpapertickets.com/event/143073</link></event><event> <name>Atlanta STEAMFEST April 9 & 10</name> <description>Goggles, & High Tea, & Theatre! Oh My!</description> <location>Academy Theatre, 119 center St., Avondale Estates, GA, 30002</location> <contact>TEL: 404-474-8332</contact> <link>http://www.brownpapertickets.com/event/145160</link></event><event> <name>ARTC Presents: Dancer in the Dark & More</name> <description>THe Atlanta Radio Theatre & Academy bring you Thomas E. Fuller's Dancer in the Dark and other aural stories</description> <location>Academy Theatre, 119 center St., Avondale Estates, GA, 30002</location> <contact>TEL: 404-474-8332</contact> <link>http://www.brownpapertickets.com/event/146638</link></event><event> <name>Thimblerig Circus' Fools Fest!</name> <description>Live Music, Magic, and Mayhem From Your Favorite Moldavian Circus!</description> <location>Academy Theatre, 119 center St., Avondale Estates, GA, 30002</location> <contact>TEL: 404-474-8332</contact> <link>http://www.brownpapertickets.com/event/166146</link></event><event> <name>Colt Cabana's $5 Wrestling Show</name> <description>NWA Champion Colt Cabana presents a comic take on Wrestling.</description> <location>Academy Theatre, 119 center St., Avondale Estates, GA, 30002</location> <contact>TEL: 404-474-8332</contact> <link>http://www.brownpapertickets.com/event/167009</link></event></listings>
And this is what I have for the XSL...which the problems will probably be found here:
<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="xml" indent="yes"/><xsl:template match="document"><rss version="0.91"><channel><title>Academy Theatre</title><link>http://www.brownpapertickets.com/producer/20154</link> <description>Upcoming Events</description> <language>en-us</language> <copyright>Copyright 2011</copyright> <webMaster>webmaster@academytheatre.org</webMaster><image><title>Academy Theatre</title> <url>https://www.brownpapertickets.com/g/u/3159-250.gif</url> <link>http://www.brownpapertickets.com/producer/20154</link> <width>250</width> <height>57</height> <description>Upcoming Events</description> </image><xsl:apply-templates/></channel></rss></xsl:template><xsl:template match="event"><item><xsl:apply-templates select="title | link | description"/></item></xsl:template><xsl:template match="event/*"><xsl:copy><xsl:apply-templates/></xsl:copy></xsl:template>
I am confused right at the very end...where the "template match="event/*" begins...how to I convert the <name> tag in the original xml into the <title> tag of the RSS?
Link to comment
Share on other sites

<xsl:template match="event/name">  <title>	<xsl:value-of select="."/>  </title></xsl:template>

should suffice to ensure any "name" child element of the "event" elements are transformed into "title" elements in the RSS. Note that my snippet was done with looking at an RSS 2.0 sample, you seem to have choosen a different version (0.91), so ensure yourself that you adapt any result elements to that version.

Link to comment
Share on other sites

<xsl:template match="event/name">  <title>	<xsl:value-of select="."/>  </title></xsl:template>

should suffice to ensure any "name" child element of the "event" elements are transformed into "title" elements in the RSS. Note that my snippet was done with looking at an RSS 2.0 sample, you seem to have choosen a different version (0.91), so ensure yourself that you adapt any result elements to that version.

Thank you so much~! :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...