But I can't get this working in Umbraco, the best I can come to getting this working is just displaying the whole
feed as one big string of text without the XML tags, not sure why that
happens.. I've tried starting with samples(RunwayFeedViewer, LastFM,...). I think what I am having a hard time doing is correctly passing the feed to the template which people seem to be done with umbraco.library:GetXmlDocumentByUrl().
What is the source of your RSS feed? you should pass it to the umbraco.library:GetXmlDocumentByUrl() as a string like this: umbraco.library:GetXmlDocumentByUrl('theurlofyourfeed') - this should be done if your feed comes from an external source.
I have tried using umbraco.library:GetXmlDocumentByUrl('http://www.nll.com/feed.php') and, like I said, the only content I can render is the entire feed as one big string with no XML tags. It seems that it is not parsing.
Ok, how do you determine that it's returning a string?
if you are using <xsl:value-of select="umbraco.library:GetXmlDocumentByUrl('http://www.nll.com/feed.php')" /> then it returns a string and then it can be a bit tough to figure out, which elements and attributes to match.
I will recommend that you write the following in your XSLT.
I think I was testing the results of the GetXmlDocumentByUrl like you said, but otherwise I'm getting no results...that's my problem ;-) I cannot seem to 'connect' the $feed variable to the XSLT that worked on the old site, which seems like the right goal.(I will be gone for the weekend in 1 hour, thanks for your help)
I took a look at this in one of my v4.5.2 installations, and I did find a solution even though I think it's a bit weird. Take a look at the following code:
This actually outputs five list elements on my page with the right title and link so that's nice and solves your problem.
But what I don't understand is why I had to use the wildcard selector (*) and then narrow it down using the name(). I my mind the following code should output the same:
But the above code doesn't output anything. I tried making some small changes in the code as well, but still with no luck. So if any of you XSLT gurus out there have an explanation I'd like to hear it :)
Anyways, the first snippet I wrote in the top should output items from the RSS-feed that you provided if you are using the new XML schema. Give it a shoot when you're back from the weekend and let us know if it works :)
Tired from my 6:15am (GMT-8?) flight, but very happy to see that Kim has helped me out, thank you! As you'd expect, since your XSLT works for you, it is also working for me in my 4.0.4.1 installation. I need to get better at XPath. Still, one weird thing is the decoding of the "&amp;" in the first few feed items. I don't know why the feed is using those characters for "&" instead of just one "&" I thought Umbraco.Library.HTMLDecode would help but there is only an HTMLEncode method. That seems strange.
The reason the two versions don't do the same has to do with namespaces - specifically default namespaces, and it's a little tricky to explain, but for now here's a quick try:
<root xmlns:demo="http://xmlns.greystate.dk/2010/demo-namespace">
<item xmlns="http://xmlns.greystate.dk/2010/demo-namespace">
I will NOT match //item
I WILL match //*[name() = 'item']
I WILL match //*[local-name() = 'item']
I WILL match //demo:item
</item>
<demo:item>
I will NOT match //item
I will NOT match //*[name() = 'item']
I WILL match //*[local-name() = 'item']
I WILL match //demo:item
</demo:item>
</root>
See - the namespace (the URL doesn't matter, only that the two are exactly the same) is assigned the prefix "demo" on the root element, but on the first <item> element, the same 'namespace-uri' is used as the default namespace (without a prefix) so the item element belongs to that namespace.
On the second <item> the prefix is used so that also belongs to that same namespace.
Sometimes it's visualized by saying that the XML parser passes both of the item elements on like this:
That's a nice explanation Chriztian. And it actually makes sense. Never thought of this, but after your post I understand why - well, at least I think I understand why :D
If the time allows it, this could maybe be a small topic at the XSLT Ping Pont Fest? ;)
RSS feed shows as one big string
I am trying to display the first few 'titles' from 'items' in this RSS feed: http://www.nll.com/feed.php
This displays correctly on an old website using this XSLT with ASP.NET xml control(<asp:Xml>):
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet
version="1.0"
xmlns:rss="http://purl.org/rss/1.0/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<xsl:output omit-xml-declaration="yes" />
<xsl:template match="rss|/rdf:RDF">
<feed>
<xsl:apply-templates select="channel/item|/rdf:RDF/rss:item" />
</feed>
</xsl:template>
<xsl:template match="channel/item|/rdf:RDF/rss:item">
<xsl:if test="position()< 5">
<tr>
<td style="vertical-align: top">
<a target="_blank" href="{link|rss:link}" class="smallred">
<xsl:value-of select="title|rss:title" disable-output-escaping="yes" />
</a></td>
</tr>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
But I can't get this working in Umbraco, the best I can come to getting this working is just displaying the whole feed as one big string of text without the XML tags, not sure why that happens.. I've tried starting with samples(RunwayFeedViewer, LastFM,...). I think what I am having a hard time doing is correctly passing the feed to the template which people seem to be done with umbraco.library:GetXmlDocumentByUrl().
Can anyone help?
Thanks
What is the source of your RSS feed? you should pass it to the umbraco.library:GetXmlDocumentByUrl() as a string like this: umbraco.library:GetXmlDocumentByUrl('theurlofyourfeed') - this should be done if your feed comes from an external source.
Hope this helps
/Jan
The feed is stated above: http://www.nll.com/feed.php
I have tried using umbraco.library:GetXmlDocumentByUrl('http://www.nll.com/feed.php') and, like I said, the only content I can render is the entire feed as one big string with no XML tags. It seems that it is not parsing.
Ok, how do you determine that it's returning a string?
if you are using <xsl:value-of select="umbraco.library:GetXmlDocumentByUrl('http://www.nll.com/feed.php')" /> then it returns a string and then it can be a bit tough to figure out, which elements and attributes to match.
I will recommend that you write the following in your XSLT.
<textarea>
<xsl:copy-of select="umbraco.library:GetXmlDocumentByUrl('http://www.nll.com/feed.php')" />
</textarea>
By using copy-of, you get the returned XML.
Copy the entire XML output to an xml document, so you can see the whole structure. Now you should be able to figure out how to parse the XML.
/Jan
Thanks Jan,
I think I was testing the results of the GetXmlDocumentByUrl like you said, but otherwise I'm getting no results...that's my problem ;-) I cannot seem to 'connect' the $feed variable to the XSLT that worked on the old site, which seems like the right goal.(I will be gone for the weekend in 1 hour, thanks for your help)
Here is the whole template:
<xsl:template match="/">
<xsl:variable name="Feed" select="umbraco.library:GetXmlDocumentByUrl('http://www.nll.com/feed.php')" />
<ul>
<xsl:value-of select="$Feed" />
<xsl:for-each select="$Feed//item">
<xsl:if test="position() <= $NumberOfItems">
<xsl:apply-templates select="." />
</xsl:if>
</xsl:for-each>
</ul>
</xsl:template>
<!-- Template: item -->
<xsl:template match="item">
<li>
<a href="{link}"><xsl:value-of select="title"/></a>
</li>
</xsl:template>
Hi organic
I took a look at this in one of my v4.5.2 installations, and I did find a solution even though I think it's a bit weird. Take a look at the following code:
This actually outputs five list elements on my page with the right title and link so that's nice and solves your problem.
But what I don't understand is why I had to use the wildcard selector (*) and then narrow it down using the name(). I my mind the following code should output the same:
But the above code doesn't output anything. I tried making some small changes in the code as well, but still with no luck. So if any of you XSLT gurus out there have an explanation I'd like to hear it :)
Anyways, the first snippet I wrote in the top should output items from the RSS-feed that you provided if you are using the new XML schema. Give it a shoot when you're back from the weekend and let us know if it works :)
/Kim A
Tired from my 6:15am (GMT-8?) flight, but very happy to see that Kim has helped me out, thank you! As you'd expect, since your XSLT works for you, it is also working for me in my 4.0.4.1 installation. I need to get better at XPath. Still, one weird thing is the decoding of the "&amp;" in the first few feed items. I don't know why the feed is using those characters for "&" instead of just one "&" I thought Umbraco.Library.HTMLDecode would help but there is only an HTMLEncode method. That seems strange.
Anyway, thanks for the help.
@Kim:
The reason the two versions don't do the same has to do with namespaces - specifically default namespaces, and it's a little tricky to explain, but for now here's a quick try:
OK, I'll shut up now... :-)
/Chriztian
That's a nice explanation Chriztian. And it actually makes sense. Never thought of this, but after your post I understand why - well, at least I think I understand why :D
If the time allows it, this could maybe be a small topic at the XSLT Ping Pont Fest? ;)
Anyways, thanks for clearing things up!
/Kim A
-- To me, that's exactly what the "XSLT Ping Pong Fest" is all about :-)
/Chriztian
is working on a reply...