PANVEGA’s Blog

DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

Using DDWRT in xslt-based web parts

Posted by PANVEGA on November 30, 2007

What is DDWRT?
well, its a script that microsoft packaged for it’s xslt dataviews, that gives them more xslt power.
I needed to use the ddwrt functions in my content query web part, but I guess that the following approach will work in the search web parts as well.

Why do we need it?

I needed it to format the date I was getting back from the content query. The format I was getting back was ugly to the user (2007-06-27 15:52:00) and I wanted to format it, but I didn’t want to write my own function.
So how to use it?

you need to add to your xslt the following namespace where the namespaces are declared (at the top of the xsl file, in the “xsl:stylesheet” tag):

xmlns:ddwrt=”http://schemas.microsoft.com/WebParts/v2/DataView/runtime”

Then you can use the ddwrt’s functions. For example, to format the date I used the following:

<xsl:value-of disable-output-escaping=”no” select=”ddwrt:FormatDate(string(@Modified), 3081, 5)” />

Note that in the FormatDate function I used 2 hard coded values – 3081 which is the LCID for Australia (so the date will be formatted to Australian date format) and 5 which specifies the what do I want to display – date, time, date and time ect. I have no idea what values give what, but I do know that 5 gives me the date and the time.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: