Showing posts with label XSL. Show all posts
Showing posts with label XSL. Show all posts

Wednesday, March 25, 2009

News v4.x Alternating color background...

by Phil 'iwonder' Guerra - (Mission, KS) - Sometimes you would like to change the look of your news feed presentation. One such possibility is alternating background color of a news feed item. It's fairly easy to do, but with the new version of the News module v4.x you must remember to fashion your new custom xsl to respect the parameters used in the module setup.

The simplest way to develop a custom xsl for the News v4.x module is to just copy the existing default.xsl which resides in the ~/DesktopModules/News/transformations folder. Use your favorite text editor and make whatever changes you need. Be careful to keep the parameters that are used in the default.xsl that match what is setup in the News v4.x module.

Now, after modifying your custom xsl, save the new file to your portals/n folder and change the module setting to use the new xsl. Always test your new xsl, either using a suitable XML/XSL editor, or in a test instance of your DNN site. Also, I find it works best to place your test News module in a special page of it's own, to avoid causing issues. If your test module fails to display with your new xsl, it could cause your site to 'freeze' or lock up, so you do not want to test a new moduel setup on your 'home' page.

Here's an example xsl that alternates the background of the items in a feed. Try it out and make it your own.

<?xml version="1.0" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<!-- alternating background color -->
<!-- for use with DNN News module v4.x -->
<!-- by Phil 'iwonder' Guerra' -->
<!-- 2008-09-21 -->
<xsl:output method="html" indent="yes" />
<xsl:param name="ItemsToShow" /> <xsl:param name="ShowItemDetails" /> <xsl:param name="ShowItemDate" />
<xsl:param name="Locale" />
<xsl:template match="rss">
<xsl:for-each select="channel/item[position()<=$ItemsToShow or $ItemsToShow<1]">
<div>
<xsl:if test="position() mod 2 != 0"> <xsl:attribute name="style">background-color: #F5F5F5</xsl:attribute>
</xsl:if>
<p class="DNN_News_ItemLink"> <a href="{link}" target="_blank">
<xsl:value-of select="title" /> </a>
</p>
<xsl:if test="$ShowItemDate='true'">
<p class="DNN_News_ItemDate">
<xsl:value-of select="pubDate" />
</p>
</xsl:if>
<xsl:if test="$ShowItemDetails='true'">
<p class="DNN_News_ItemDetails">
<xsl:value-of select="description" disable-output-escaping="yes" />
</p>
</xsl:if>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Tuesday, December 30, 2008

DNN and Podcasting

by Phil 'iwonder' Guerra

- (Mission, KS) - Here's a bit of something I ran across while looking into a question about DNN and whether or not it supports podcasts. First, out of the box, DNN will support podcast with only the XML/XSL module, and you'll need a custom xsl to do it.

Secondly, the presentation and results vary by browser. I created a custom xsl that enables presentation of the information in a newsfeed that point (links) to the actual podcast, which is usually an mp3 or video file of some sort. It's pretty straightforward transformation of the enclosure element, which contains a URL, type, and size. All 3 attributes are important as there are some issues with downloading that content for some browsers, at least that's the case when IE7 is used. Firefox did not have a problem, but I ran into issues when I used IE7. Why?

Well, it took some googling, but here's a link to the secret, IE7 has a 'limit' on the size it will allow to be downloaded. No file larger than 15MB on servers that do not support HTTP range requests. Since, I'm using a test environment built on Windows XP, and using IIS v5.0, I'm not sure if that's the real problem or not. I'll toss the custom XSL I created to test and show how I'm doing this for a particular site, DNN Creative DotNetNuke Podcasts and give me feedback. (I don't have a public DNN website, it's a matter of controlling my expenses, which is why I blog freely.)

Anyway, using FireFox, tells me that DNN will support presentation of news feeds that include podcasts, and that's the good news.

Here's an example XSL to use with the DNN XML/XSL module to present the DNNCreative Podcast newsfeed. Just a couple notes:
1) I'm not advocating adding the ability to include enclosures wholesale on a website. There are a number of security issues with doing so. I provide this example as quick 'how-to' not as a reccommended practice. Above all know your newssource and test on a non-production site to aovid issues.

2) This example was specifically built to transform the DNN Creative DotNetNuke Podcast feed. As such, you would have to modify it for any other use. Also, feeds change formats from time to time, so it may not always work. However, if you are seriously considering doing this type of thing, you'll need to be more than a novice with XML and XSL to get the most of this type of transformation.

3) To use this code, cut and paste it into a text file using a simple text editor. Save it as PodcastEnabled.xsl, and then upload it to you site during the setup conversation of a DNN XML/XSL module. I know the formatting of this code is less than desireable, but that's a function of my blogger app, so sorry. If you have a lot of problems with the xsl example, leave a comment and I'll go over it.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" >
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<!-- phil 'iwonder' guerra - PodcastEnabled.xsl - custom xsl for DnnCreative Podcasts -->
<xsl:template match="/">
<div>
<xsl:apply-templates select="rss/channel"/>
</div>
</xsl:template>
<xsl:template match="rss/channel">
<xsl:apply-templates select="item"/>
</xsl:template>
<xsl:template match="item">

<xsl:variable name="item_link" select="link"/>
<xsl:variable name="podlink" select="enclosure/@url"/>
<xsl:variable name="podmedia" select="enclosure/@type"/>
<xsl:variable name="altmedia" select="feedburner:origLink"/>
<xsl:variable name="item_title" select="description"/>
<div class="rssItemDescription">
<xsl:value-of select="description" disable-output-escaping="yes"/>
</div>
<div class="rssItemSub">
<xsl:if test="enclosure/@url">
<a href="{$podlink}">Listen Now</a> (<xsl:value-of select="$podmedia"/> - Size <xsl:value-of select="enclosure/@length"/>)<br></br>
</xsl:if>
<xsl:if test="not(enclosure/@url)">
<a href="{$altmedia}">See the Video</a>
</xsl:if>

(<xsl:value-of select="pubDate"/>) <hr/>
</div>
</xsl:template>
</xsl:stylesheet>

Wednesday, September 10, 2008

DNN News Module - Headlines.xsl Ticker Available

Two XSL files are included that allow vertical or horizontal scrolling of newsfeeds items in the new DNN News module v04.00.00. After playing around with the new News module, I found a slight implementation issue with using the Ticker.xsl. When I choose to use this xsl, I don't get the expected results, which is seeing a display of the news headlines scroll across my module 1 at a time. Instead the xsl displays all of the items, and scrolls them all across the module container. If you have 10 or more items, this kind of implementation is really distracting, as all of the items display and are scrolled.

Now, that is not the implementation I've seen with other similar web usage. So, I created an alternative xsl that can be dropped into the modules transformation folder and used to provide the display of News Headlines scrolling across the module container. This is mostly useful for the Top container area, but suppose you could put it elsewhere - I use it in the Top area.

The settings for 'Show Items Date', and 'Show Items Detail' are not used, as this xsl is desigened just to display the headlines (title element), which I think is the more oft used implementation.

The other thing about this new xsl is that it will support the "ItemsToShow" parameter, but keep in mind that if you are agregating a number of feeds, the count is for the total number of items to show, not the number of items to show per feed.

I placed this HeadlinesTicker.xsl in the same folder as the other default News xsl files

\Website\DesktopModules\News\Transformations

I'm guessing that you could upload it, and choose it for using for your module, as it does transform RSSv2.0 feeds, which is the only custom xsl types that I've seen actually work with the new module. Copy and paste the code, save it to a file using your favorite bare bones text editor. Then, place it our upload it. Be sure to test it out first, though to ensure it does what you think it should.

Click on the blog Title to view the DNN News Forum post where I give the actual code. Sorry, can't provide it here.