eXSLT to the rescue

XSLT is extremly powerful but limited in many important ways.  For example, it lacks basic date handling functions.  I recently ran into this problem when I was trying to format an RSS feed for my home page.  Luckily, eXSLT solves many of these problems.  Even better, there is a .NET implementation on GotDotNet Workspaces.

I found this RSS xslt stylesheet out on the net (can't remember where) and adapted it to use eXSLT for date formatting. 

Here's how...

First, add the namespace for the functions you want to import:
(such as the date namespace below)

<xsl:stylesheet version="1.0"
   
xmlns:xsl
="http://www.w3.org/1999/XSL/Transform"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rss="http://purl.org/rss/1.0/"
    xmlns:ns="http://my.netscape.com/rdf/simple/0.9/"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
   
xmlns:date
="http://exslt.org/dates-and-times"
    xmlns="http://purl.org/rss/1.0/">

Next, use a function within your stylesheet.

<xsl:value-of select="date:format-date(./rss:pubDate|./pubDate|./ns:pubDate,'M-dd-yyyy')"/>

Finally, perform the transformation within your Page_Load event.  Since eXSLT has it's own transform object, we can't use the XSL Server Control.  In this example, I just stuff the rendered HTML into the text of a label.

using System.IO;
using
GotDotNet.Exslt;
using
System.Xml.XPath;

private void Page_Load(object sender, System.EventArgs e)
{
    MemoryStream ms=
new
MemoryStream();
    XPathDocument doc =
new
XPathDocument(“http://dotnetweblogs.com/Britchie/Rss.aspx“);
    ExsltTransform xslt =
new ExsltTransform();
    xslt.Load(MapPath("rss.xslt"));
    xslt.Transform(doc,
null
, ms);
    ms.Seek(0,System.IO.SeekOrigin.Begin);
    StreamReader reader=
new
StreamReader(ms);
    XslPlaceHolderLabel.Text=reader.ReadToEnd();
    reader.Clse();
}

That's it!  This opens even more power to the XSLT developer than ever before.  I hope you find eXSLT helpful, I sure did!

 

Published Tuesday, July 20, 2004 12:27 AM by brian_ritchie
Filed under:

Comments

Friday, May 25, 2007 8:23 AM by Gdsffsd

# re: eXSLT to the rescue

Friday, September 07, 2007 4:17 AM by janie

# re: eXSLT to the rescue

hey Brian  r u ever comming back to Denver   from Janie  remember marty from the persian rug store

Tuesday, December 02, 2008 11:40 AM by Asina

# re: eXSLT to the rescue

<a href= bestpre.com ></a>

Saturday, February 28, 2009 10:08 PM by elexx-ws

# re: eXSLT to the rescue

<a href= http://adultchatsfinder.com >singles</a>

Saturday, March 07, 2009 8:00 AM by szmah

# re: eXSLT to the rescue

Beautiful work! 8 jewmz

Friday, March 13, 2009 2:19 PM by qnzam

# re: eXSLT to the rescue

I like your work! 000.423ok4.us/ ">Patrick deuel i weigh 1 rullf

Monday, March 16, 2009 1:27 PM by clrjf

# re: eXSLT to the rescue

Nice portal! 000.f37rj8.us/ ">Patrick deuel i weigh 1 dpzej

Leave a Comment

(required) 
(required) 
(optional)
(required)