-1

I have an iphone app which parses standard rss feeds and displays it on a table. However I have been given a feed from a client but the parser in the app cannot pickup the nodes and parse the data as it is not a standard rss feed.

The layout they have given me is the following:

    <rss version="0.92">
        <channel>
        <title>Feed</title>
        <link>http://google.com</link>
        <description>
        Description here
        </description>
        <lastBuildDate>30 June +0100</lastBuildDate>
        <language>en</language>
            <event>
                <eventID>123</eventID>
                <name>Name here</name>
                <date>2012-06-29</date>
                <time>21:00</time>
                <category>Arts</category>
                <info>
                 Info here
                </info>
            </event>
            <event>
                <eventID>223</eventID>
                <name>Name here</name>
                <date>2012-06-30</date>
                <time>22:00</time>
                <category>Dance</category>
                <info>
                 Info here
                </info>
            </event>
    </channel>
</rss>

Is there any way to restructure this xml file to a standard rss feed layout using XSLT or a PHP script? A standard rss feed layout being the following:

<rss>
     <channel>
     <item>
        <title>
            <![CDATA[ Title here ]]>
        </title>
        <link>
            http://www.theatre.com/
        </link>
        <guid>
        http://www.theatre.com
        </guid>
        <description> 
         <p> Description </p>

        </description>
        <dc:subject>
        <![CDATA[ ]]>
        </dc:subject>
        <dc:date>2013-02-01T18:00:04+00:00</dc:date>
      </item>
     </channel>
</rss>
Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
user1417302
  • 411
  • 3
  • 9
  • 22
  • 1
    neither of the two validate as RSS: http://validator.w3.org/appc/#validate_by_input – Gordon Jun 30 '12 at 12:17
  • 1
    Where does the output guid element content come from? What does event in the input correspond to in the output? Where does the content for cd:date come from? – Sean B. Durkin Jun 30 '12 at 12:17
  • 1
    What is the url bounding for the dc output? – Sean B. Durkin Jun 30 '12 at 12:19
  • Basically, I want to have te event name in the first feed to the title in the second, and the description in the first feed goes to the description in the second feed. – user1417302 Jun 30 '12 at 12:20
  • 1
    tell the client to provide you with a valid RSS v2.0 feed. – Gordon Jun 30 '12 at 12:25
  • 3
    You comment bears no relationship to the samples presented. Could you please supply: (1) Sample input document; (2) Expected output for the given input; (3) The rules of transformation; (4) What XSLT version are you using: 1.0 or 2.0 ? – Sean B. Durkin Jun 30 '12 at 12:25
  • @SeanB.Durkin PHP uses [libxslt](http://xmlsoft.org/xslt/) – Gordon Jun 30 '12 at 12:28
  • the samples above show the input xml data, and the sample output i would like - so the event nodes in the input xml should transform to the item nodes on the sample output – user1417302 Jun 30 '12 at 12:31
  • it probably isn't validating as i just wanted to give an idea of what i want to do and see how to go about doing it – user1417302 Jun 30 '12 at 12:37

1 Answers1

0

It's not clear what you want, so this style-sheet is just indicative of what you might need.

This XSLT 1.0 style-sheet ....

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
 <rss>
  <channel>
    <xsl:apply-templates select="rss/channel/event" /> 
  </channel>
 </rss>
</xsl:template>

<xsl:template match="event" >
 <item>
  <title><xsl:value-of select="../title" /></title>
  <link><xsl:value-of select="../link" /></link>
  <guid>http://www.theatre.com</guid>
  <description><xsl:value-of select="../description" /></description>
  <subject><xsl:value-of select="category" /></subject>
  <date><xsl:value-of select="date" />T<xsl:value-of select="time" />+00:00</date>
 </item>
</xsl:template>      

</xsl:stylesheet>

... when applied to your supplied sample input will produce this document ...*

<?xml version="1.0" encoding="utf-8"?>
<rss>
  <channel>
    <item>
      <title>Feed</title>
      <link>http://google.com</link>
      <guid>http://www.theatre.com</guid>
      <description>
        Description here
        </description>
      <subject>Arts</subject>
      <date>2012-06-29T21:00+00:00</date>
    </item>
    <item>
      <title>Feed</title>
      <link>http://google.com</link>
      <guid>http://www.theatre.com</guid>
      <description>
        Description here
        </description>
      <subject>Dance</subject>
      <date>2012-06-30T22:00+00:00</date>
    </item>
  </channel>
</rss>    
Sean B. Durkin
  • 12,659
  • 1
  • 36
  • 65