Jump to content

Create an RSS file from XML source using XSL


g_clarkey

Recommended Posts

Hi.I am implementing a website that will have its data in an XML source document.There are goin to be two transformations, one to XHTML, and one to RSS.The one to XHTML works fine, but i have a problem when it comes to RSS. I want to use XSL to create an RSS file from my original XML source.So i will have my xml file, with the link to the rss.xsl transformation at the top. I was hopeing this would display the rss file on screen. I can get it to do this, but it is just as a text file.I want my "text" file to be able to use the stylesheet it references, and to be readable by a rss reader.Have you any general ideas on how to do this?If you need the exact code i will post it.Thanks in advance for any help.

Link to comment
Share on other sites

Hi. I'll try to help, but not sure if I understand everything completely . . .Your original XML is NOT in RSS format?What is generating your original XML document?You are trying to take an unformated XML document and transform it into an RSS formatted XML document using XSL?

Link to comment
Share on other sites

RSS is actually a plain XML document. By putting a reference to the XSLT file that transforms the custom XML to RSS, you are practically making XML to XML transformation, or in other words: no actual visual information.What I would suggest is to somehow put a reference to another stylesheet in the XSLT file so that it appears in the output (damn it... haven't really figured how is that going to happen).Also, try to check if your <xsl:output> is set to method="xml". If it's "html" or "text" instead, it's quite obvious why you see only plain text.By the way, it would be really good if you could a server side scripting language to generate the actual RSS file. This should make it good for some incufficient RSS readers.

Link to comment
Share on other sites

Hi i have kind changed the way i am doing things a little.I have a XML source.I run a transformation on that to create an rss file.This works fine, my rss worls in my reader, links back to site.My problem is i want the rss to be displayable to people who view the rss outside of a reader (much like the bbc do if you click on their rss).BBC SportI know how to attach the style sheet, just use the line

<?xml-stylesheet type="text/xsl" href="nolsol.xsl"?>

BUT. as i am creating my rss file from my xml source, i need to write the stylesheet line in my xsl code. What i want my code to look like is:rss.xml:

<?xml version="1.0" encoding="ISO-8859-1" ?><?xml-stylesheet title="XSL_formatting" type="text/xsl" href="nolsol.xsl"?><rss version="2.0">	<channel>

To do this i have currently this code in my xsl stylesheet:rss.xsl:

<?xml version="1.0" encoding="ISO-8859-1" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	<xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes'/>  	<xsl:value-of select="title"/>		<?xml-stylesheet type="text/xsl" href="nolsol.xsl"?>	<rss version="2.0">	<channel>

Now currently this outputs:current output:

<rss version="2.0">	<channel><title>PWSB RSS</title><link>NewMusicReview.xml</link>	<description>

Which as you can see doesnt include the stylesheet, and thus displays a tree structure when it is viewed.I am guessing the way i am trying to indicate the rss file has to use the stylesheet is incorrect, currently

<?xml-stylesheet type="text/xsl" href="nolsol.xsl"?>

just before the rss declaration.Any ideas on how i can go about getting this line to output? If i can get this one line to start of the rss.xml file my work would be done!cheers in advance,clarkey

Link to comment
Share on other sites

That's exatly what I meant when I said that I haven't figured out how you can add xsl refernce in the XSLT. If you add it the ordinary way (the way you have done) then it's not the final output that is styled, but the XSLT itself is transformed.The only possible way I can currently think of is to bind a server side script in the XSLT and execute the transformation with a server side script as well. This way, the output should have the final output + the server side "deeds" which in our case is the reference.As for "the way BBC Sport do it", I think they fill the feed manually, considering the xml entension. That is certanly a way you can't go wrong with :) .

Link to comment
Share on other sites

That's exatly what I meant when I said that I haven't figured out how you can add xsl refernce in the XSLT. If you add it the ordinary way (the way you have done) then it's not the final output that is styled, but the XSLT itself is transformed.The only possible way I can currently think of is to bind a server side script in the XSLT and execute the transformation with a server side script as well. This way, the output should have the final output + the server side "deeds" which in our case is the reference.As for "the way BBC Sport do it", I think they fill the feed manually, considering the xml entension. That is certanly a way you can't go wrong with :) .

cheers for the replies mate, but i managed to get a way to do it.I originally wanted to do it manually as you say, but wasnt allowed too, as "updating two xml files can cause confusion". for who? mutants thats who.server side script i was just about to look into, when i thought i thought id check out the xsl commands for the millionth time and found:
<xsl:processing-instruction name="xml-stylesheet"> href="nolsol.xsl" type="text/xsl" </xsl:processing-instruction>

Which does exactly what i wanted it two. i cant believe ive wasted a whole day on this!cheers again for the extra thought processes. appreciate it!clarkey.

Link to comment
Share on other sites

Wow. Never heared of this element before. I learned my lesson here (despite the fact that you were the one asking) :) .

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...