Heal Your Church WebSite


Teaching, rebuking, correcting & training in righteous web design.

Using XSLT to Transform the RSS 2.0 Daily Verse feed from the ESV Bible

For those of you old enough to remember the original Star Trek: The Motion Picture, you might recall a gruesome scene early in the movie where a transporter malfunction turns two incoming shipmates into disfigured piles of short-lived screaming flesh. That’s sorta the image that came to mind yesterday when I looked at the Redland Baptist homepage and noticed that my VerseScrape program had to horribly mangle yesterday’s incoming words of wisdom from the Book of Proverbs. That is, my screenscraper failed due to the changes in the incoming source file; notably, the highly identifiable and easy to tokenize parenthesis surrounding the scripture verse have been removed.

Unlike the aforementioned unfortunate Enterprise members, VerseScrape is fixable, however to do so would require bringing in the girth of the Scripturizer module to identify and hyperlink the scripture reference.

Since the purpose of VerseScrape was to import a simple JavaScript rendering of the International Bible Society’s Verse of the Day, and since a number of online Bible providers responded positively to my request for syndicated daily Scripture files, I think it is time to move on to more up-to-date method of customizing a daily verse feed to fit your website’s look-n-feel.

Hard Code:

Another shortcoming contributing to the demise of VerseScrape is the fact that I hard-coded the output in my examples. This means that whenever I make changes to fix the program, you not only have to download and deploy the fix, but you must also fix the example code to suit your site’s display. So rather than just offer a variant of my article “Using Cron with LWP::Simple and XML::RSS to retrieve news feeds,” where I also hard-code the output, why not instead practice what I preached in Chapter 14 of “Son of Web Pages That Suck” and use XSLT?

Just to catch some of you up to speed, XSLT is short for eXtensible Stylesheet Language Transformations.

Yeah, I know, it sounds scary but simply put: XSLT is a mechanism in which two files create a third file. The first being an XML file, such as an RSS 2.0 syndication file. The second file is an XSL file. When smooshed together via a transformation application/module they result in whatever file format and media type you defined in your XSL file. You can read more about it over at w3schools.com.

Assign Once, Iterate Often:

One of the other reasons I created VerseScrape was because incorporating dynamic feeds into your web pages, regardless of format, can and will slow down your page load times. As suggested in “Using Cron with LWP::Simple …” one solution is to employ a loop that makes several attempts to copy the feed locally, AND THEN process it so network failures won’t negatively impact your site’s performance.

The first example is a Perl program that after successfully downloading the ESV Bible Daily Verse RSS 2.0 feed, employs XSLT to create an include file. Beneath that is a PHP program that does the same. Both code examples call an XSL sample I’ve also provided that you can modify to suit your website’s specific needs; regardless of how many times I’m compelled to fix either the Perl or PHP versions.







Theology:

I realize some of you may be asking why I’ve switched from the IBS to the ESV. The answer is two-fold, yet simple:

  1. The IBS is still using the 0.91 RSS specification, whereas the ESV uses 2.0;
  2. The Scripture the ESV provides is generally under 264 characters, and doesn’t include embedded HTML tags – see my article entitled “the Gospel, according to RSS and/or Atom” for a more in depth discussion of this.

If you would still rather not go the XSLT route, then you might want to pay a visit to an article I wrote last summer entitled “English Standard Version Bible RSS Feed” where I demonstrate how to slice-n-dice the ESV RSS 2.0 file using either use XML::RSS or use XML::RSSLite. If you do have questions, make improvements or find bugs in the above, don’t be shy, share your findings in the form of a loving comment.
 

4 Comments

  1. Thanks Dean. That’s nifty. But I’m wondering – why rely on the fickleness of a third party web site when you could create a local database of 365 passages and display your own Scripture of the Day? That way if their site goes down, they change their format, or whatever, you wouldn’t suffer at their whim. I can understand the value of RSS when dealing with ever changeing content created by others, but when dealing with the unchanging Word of God, all we are doing is rotating a display.

    What I did was write a script that dynamically strips out the scripture quotation from Spurgeon’s Morning and Evening. Eventually I plan to make my own selections and rotate those instead.

  2. That would work, too, Don. I guess I’m just too lazy to do that. If someone else already created a “rotating display” as you called it, I’d rather use that than create another one.

    With Dean’s method above, it really doesn’t matter if the RSS source goes down because he’s caching the previous value until he can successfully fetch a new verse. So, from what I can tell, the worst that could happen is that he’d have the same verse up for more than a day. I suppose if the actual site stopped existing, then yeah, I’d need to find another RSS source. But those are getting more and more common.

    I guess all that to say, an internal source would be great, too, if I wanted to take the initial time to create it. And it might have some benefits down the road over an RSS feed that has the possibility to change format, etc. But _for me_ I like the ease of use right now of using an already established library from someone else.

    Thanks again, Dean.

  3. Nice – I wish I could convince my source (Daily Gospel) to go with an RSS feed. Since the sites that I support use the Roman Lectionary, our Daily Readings are rather specific – 3 year Sunday cycle, 2 year daily cycle. If you have any great ideas on convincing providers that RSS is “a good thing” I’m open.

  4. I’d like to get a list of 365 Bible verses so I can do the daily Bible verse in Vietnamese. If anyone has or know where to get a list of 365 Bible verses, please let me know. Thank you.