Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm using SharePoint Foundation 2010 and we've added a blog as a subsite. I want to show a 'recent blog posts' webpart on the main site page, so decided to go down the route of an XML webpart using the rss feed from the blog.

This is working great, except the date format returned by the rss feed is like:

Wed, 02 May 2012 09:22:36 GMT

I just want it to be dd/MM/yyyy.

I tried referencing the ddwrt namespace in the header of the xsl file, but when I try to use:

ddwrt:FormatDate($item_date,1033,1)

to format the date, but I'm just getting 'Failed to apply XSLT to the content' whenever I do. works fine, and the ddrwrt reference I copied from an existing xsl file in SharePoint.

entire xsl (it's only short, don't worry!):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" ddwrt:oob="true">
<xsl:output method="html" indent="no"/>
        <xsl:template match="/">
            <div>
                <xsl:apply-templates select="rss/channel"/>
            </div>
        </xsl:template>
        <xsl:template match="rss/channel">
            <xsl:variable name="link" select="link"/>
            <xsl:variable name="description" select="description"/>
                <ul>
                    <xsl:apply-templates select="item"/>
                </ul>
        </xsl:template>
        <xsl:template match="item">
            <xsl:variable name="item_link" select="link"/>
            <xsl:variable name="item_title" select="description"/>
            <xsl:variable name="item_author" select="author"/>
            <xsl:variable name="item_date" select="pubDate"/>
                <xsl:if test="position() &lt; 6">
                    <li>
                        <a href="{$item_link}" title="{$item_title}"><xsl:value-of select="title"/></a><br />
                        <span class="blog-date">
                            <xsl:value-of select="$item_date"/>
                        </span>
                        <br/>
                        <span class="blog-author">
                            <xsl:value-of select="author"/>
                        </span>
                    </li>
                </xsl:if>
        </xsl:template>

If I change line 25 to:

<xsl:value-of select="$item_date" />

Then I get no errors, but the date is obviously in the full format.

This is day one of working with XSLT, so please be forgiving!

Also, I know that 1033,1 will not give the correct format, but I am just using it as a placeholder for now until I get the code working.

share|improve this question
    
I managed to find a workaround for now. I used substring to pull the relevant sections of the formatted datetime string out to how I wanted them displayed. Hacky, but works for now. Got the idea from panvega.wordpress.com/2008/01/29/… –  mikrose May 2 '12 at 14:11
add comment

3 Answers

Try this:

ddwrt:FormatDate(string($item_date) ,1038 ,1)

I am using this to format date to dd.mm.yyyy format.

share|improve this answer
add comment

Following should work

<xsl:value-of select="msxsl:format-date($item_date, 'dd/MM/yyyy')"/>
share|improve this answer
    
Interestingly, I don't get an error when I use that, but no result is returned at all... –  mikrose May 2 '12 at 13:58
add comment

If you want it to be in "dd/MM/yyyy" format, you can use the FormatDateTime function like this:

ddwrt:FormatDateTime(@DueDate, 1033, 'dd/MM/yyyy') 
share|improve this answer
    
That still throws the error 'Failed to apply XSLT to the content.' –  mikrose May 2 '12 at 13:59
    
Try this <xsl:value-of select= "ddwrt:FormatDate(string(@item_date), 1033, 1)"/> I am using this format and it is working for me –  user8513 May 24 '12 at 7:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.