Solved

Transforming xml to rss via xsl - transformation isn't right?

Posted on 2008-10-22
13
1,624 Views
Last Modified: 2013-11-18
I am trying to generate an RSS feed from XML data from a calendar (events, locations, dates, etc.). To do this, I've been trying to use an XSL to transform the raw XML into an RSS file. The XSL only uses the components of the XML that I want to display.

The problem I'm having is that I can only get text back. I don't get a feed. Browsers and readers don't recognize my transformed file as RSS.

 A simplified version of the XML I want to translate is below:

<?xml version="1.0" ?>
<?xml-stylesheet href="calendartransform.xsl" type="text/xsl"?>

       <eventtitle>The event title goes here</eventtitle>
       <qlink>http://www.linktoinfogoeshere.com/</qlink>

My XSL is attached as a code snippet. Any suggestions as to how to get the xml returned as a feed would be most appreciated.
<?xml version="1.0" ?>
 
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
<xsl:output method="xml" indent="yes"  />
 
 
  <xsl:template match="/">
<rss version="2.0">
      <channel>
        <title>Title goes here</title>
        <link>http://www.link.com</link>
        <description>Feed description goes here.</description>
        <language>en-us</language>
        <image>
          <title>Organization goes here</title>
          <url>http://link.com/images/image.jpg</url>
          <link>http://link.com</link>
        </image>
        <item>
          <title>
            <xsl:value-of select="eventtitle" />
          </title>
          <link>
            <xsl:value-of select="qlink" />
          </link>
          <description>
            Description goes here.
          </description>
        </item>
		</channel>
		</rss>
      </xsl:template>
</xsl:stylesheet>

Open in new window

0
Comment
Question by:theatreWAC
  • 4
  • 4
  • 3
13 Comments
 
LVL 23

Expert Comment

by:Tiggerito
ID: 22784742
Your example xml is invalid as it doesn't have a root element. Maybe its the post hiding it!

I've assumed your xml has a root element called "rss". Then you will need to add that to your value-of elements....


<!-- XML -->
 
<?xml version="1.0" ?>
<?xml-stylesheet href="calendartransform.xsl" type="text/xsl"?>
<rss>
  <eventtitle>The event title goes here</eventtitle>
  <qlink>http://www.linktoinfogoeshere.com/</qlink>
</rss>
 
<!-- XSLT -->
 
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
  <xsl:output method="xml" indent="yes"  />
 
  <xsl:template match="/">
    <rss version="2.0">
      <channel>
        <title>Title goes here</title>
        <link>http://www.link.com</link>
        <description>Feed description goes here.</description>
        <language>en-us</language>
        <image>
          <title>Organization goes here</title>
          <url>http://link.com/images/image.jpg</url>
          <link>http://link.com</link>
        </image>
        <item>
          <title>
            <xsl:value-of select="rss/eventtitle" />
          </title>
          <link>
            <xsl:value-of select="rss/qlink" />
          </link>
          <description>
            Description goes here.
          </description>
        </item>
      </channel>
    </rss>
  </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:theatreWAC
ID: 22785764
Thanks for the suggestion. I made sure the actual XML I'm transforming has a root element.

I'm still in the same boat, though - The XML is being transformed like I want, but isn't transforming into an RSS feed. My understanding is that this is possible with just XML data and an XSLT, but maybe I need something else? Right now all I'm getting is the text that I want, but it isn't recognized as a feed. So my output for the above would be:

Title goes here http://www.link.com Feed description goes here. en-us Organization goes here http://link.com/images/image.jpg http://link.com The event title goes here. http://www.linktoinfogoeshere.com Description goes here.

Granted, I can style this however I want with line breaks, etc., but I would like it to be a standard feed that RSS readers recognize.

Thanks again for any suggestions.
0
 
LVL 23

Expert Comment

by:Tiggerito
ID: 22786887
Not sure on that, and its late here!

It seems its not picking it up as the right content type. What you are seing is it interpreting the result as html. Check the source to see if its xml underneath.

My rss feeds specifically set the content-type to text/xml and then the browsers seem to pick up its rss compiant. I'm not sure how to do that with xml that is being transformed using the xml-stylesheet tag
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 109

Expert Comment

by:Ray Paseur
ID: 22804115
@theatreWAC: Do you have a scripting language available to you, such as PHP?  I've generated plenty of Podcasts and RSS feeds using PHP with no need for any XSLT.  Here is an example of one in the code snippet.
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
<!-- -->
<!-- -->
<!--     IF YOU CAN SEE THIS, YOU NEED AN RSS READER!   -->
<!-- -->
<!-- -->
<channel>
<title>National Trust Community Investment Corporation News</title>
<link>http://www.NTCICFunds.com/</link>
<description>NTCIC makes equity investments in real estate projects that qualify for historic tax credits.</description>
<language>en-us</language>
<pubDate>Fri, 17 Aug 2007 09:25:38 CDT</pubDate>
<image>
<url>http://NTCICFunds.com/images/ntcic_rss_logo.png</url>
<title>NTCIC Web Site</title>
<link>http://www.NTCICFunds.com/</link>
</image>
<item>
<title>NTCIC News Updated on Fri, 17 Aug 2007 09:25:38 CDT!</title>
<link>http://www.NTCICFunds.com/news/</link>
<description>The RSS Feed from www.NTCICFunds.com has been updated.</description>
<pubDate>Fri, 17 Aug 2007 09:25:38 CDT</pubDate>
</item>
</channel>
</rss>

Open in new window

0
 

Author Comment

by:theatreWAC
ID: 22813012
I have been trying out a .net solution. I'm not convinced that XML can be transformed into RSS without using a script of some sort. It would be convenient if it was possible, but I haven't found a way to do it.

Thanks for the suggestion, though.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 22813193
If it helps to clarify any, RSS is a specialized subset of XML.  There is no need to "transform" XML into RSS.  Just generate the RSS like the example shown above.  The news readers can handle it.  Here is a good discussion:
http://www.xml.com/pub/a/2002/12/18/dive-into-xml.html

HTH, ~Ray
0
 

Author Comment

by:theatreWAC
ID: 22813225
I get that, but I'm relying on our CMS for the XML. I suppose I could try to customize the way that it generates the XML, but I thought there might be a way to make RSS compliant XML out of the CMS's default XML using XSL.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 22813382
Wow, "CMS" is a pretty important part of the question here!  Any chance we can learn what CMS?
0
 

Author Comment

by:theatreWAC
ID: 22813416
Sure - it's Ektron. I'm specifically working with its XML for the calendar.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 22813513
Any help available from here?
http://www.ektron.com/search_display.aspx?searchtext=rss

If not, I would definitely contact the vendor -- they are one of the most responsive tech support groups around!

Good luck, ~Ray
0
 
LVL 23

Assisted Solution

by:Tiggerito
Tiggerito earned 250 total points
ID: 22929971
You probably need to transform your xml server side so the rss page presents the correct xml directly.

rss readers most likely don't understand the concept of xml-stylesheet. As far as I understand, xml-stylesheet  is a way to convert xml to something else (e.g. html) and as rss is xml based it is not expecting that directive.

I don't know the CMS in question, it seems to be .Net based. So you probably need to create an rss.aspx page that gets the xml and writes out the transfomed version of it.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now