Solved

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

Posted on 2008-10-22
13
1,622 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
@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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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 108

Expert Comment

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

Author Comment

by:theatreWAC
Comment Utility
Sure - it's Ektron. I'm specifically working with its XML for the calendar.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 250 total points
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
[PHP] Hash a XML file/string 3 57
API Soap Calls 4 56
Stupid git question 2 19
ASP.NET reading ATOM 2 22
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

743 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