Showing posts with label web part. Show all posts
Showing posts with label web part. Show all posts

Thursday, 28 January 2016

Use DDWRT to format your dates

The ddwrt date functions in SharePoint are not the easiest things to get to grips with. And it's quite difficult to find a definitive list of all the functions When I have found lists in other people's blogs, the functions posted don't always coincide with what I'm seeing in my site collection. This might be a result of us all using slightly different builds of SharePoint, but I'm going to list the ddwrt variations that I have observed on my SharePoint Site Collection by actually using them.

If you are going to use ddwrt date formatting in your Data View Web Part, you must include the line:

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

... inside the <xsl:stylesheet ...> tag, like this:

<xsl:stylesheet 
   version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" 
   xmlns:x="http://www.w3.org/2001/XMLSchema" 
   xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" 
   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"
   xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">

The 1033 LCID is used for US date formatting and the 2057 LCID is for UK date formatting. Where there's a hyphen in the Result column below, it means that the relevant ddwrt value produced no result for me.

DDWRT valueResult
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),1033,1)" />2/21/2016
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),1033,2)" />-
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),1033,3)" />Sunday, February 21, 2016
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),1033,4)" />1:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,5)" />2/21/2016 1:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,6)" />1:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,7)" />Sunday, February 21, 2016 1:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,8)" />-
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,9)" />2/21/2016
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,10)" />-
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,11)" />Sunday, February 21, 2016
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,12)" />1:00:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,13)" />2/21/2016 1:00:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,14)" />1:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,15)" />Sunday, February 21, 2016 1:00:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,16)" />-
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,17)" />2/21/2016
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,18)" />-
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,19)" />Sunday, February 21, 2016
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,20)" />1:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,21)" />2/21/2016 1:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,22)" />1:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,23)" />Sunday, February 21, 2016 1:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),1033,25)" />2/21/2016
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),1033,27)" />Sunday, February 21, 2016
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,28)" />1:00:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,29)" />2/21/2016 1:00:00 PM
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,30)" />1:00:00 PM
DDWRT valueResult
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),2057,1)" />21/02/2016
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),2057,2)" />-
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),2057,3)" />21 February 2016
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),2057,4)" />13:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,5)" />21/02/2016 13:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,6)" />13:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,7)" />21 February 2016 13:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,8)" />-
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,9)" />21/02/2016
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,10)" />-
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,11)" />21 February 2016
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,12)" />13:00:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,13)" />21/02/2016 13:00:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,14)" />13:00:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,15)" />21 February 2016 13:00:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,16)" />-
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,17)" />21/02/2016
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,18)" />-
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,19)" />21 February 2016
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,20)" />13:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,21)" />21/02/2016 13:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,22)" />13:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,23)" />21 February 2016 13:00
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),2057,25)" />21/02/2016
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),2057,27)" />21 February 2016
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,28)" />13:00:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,29)" />21/02/2016 13:00:00
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,30)" />13:00:00

If you're using the FormatDateTime specifier, it doesn't matter whether you define the LCID as 1033 or 2057.

DDWRT valueResult
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate),1033,'dd-MMM-yy')" />21-Jan-15
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate),1033,'dd/MM/yy')" />21/01/15
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate),1033,'dd/M/yy')" />21/1/15
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate),1033,'ddd, dd/M/yy')" />Sun, 21/1/15
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate),1033,'dddd, dd/M/yy')" />Sunday, 21/1/15

The full list of specifiers is as follows:

SpecifierResult
dDay of the month, single digit 1-9, double digit 10 up
ddDay of the month, leading zero 1-9, double digit 10 up
dddAbbreviated day of the week, ie, Wed
ddddFull name of the day of the week
Specifier Result
MThe month, 1 to 12
MMThe month, 01 to 12
MMMAbbreviated name of the month
MMMMFull name of the month
Specifier Result
yThe year, from 0 to 99
yyThe year, from 00 to 99
yyyThe year with a minumum of three digits, ie 900
yyyyThe year as a four-digit number

You can also add the following, if you want to display the time, as well:

Specifier Result
h12-hour clock, 1 to 12
hh12-hour clock, 01 to 12
H24 hour clock, 1 to 24
HH24 hour clock, 01 to 24
mMinutes, 0 to 59
mmMinutes, 00 to 59
sSeconds, 0 to 59
ssSeconds, 00 to 59

Use anything you like to separate the components ... a dash, a slash or wordpsaces and/or commas.

Hope this helps someone.


Monday, 8 July 2013

Place a Picture Library SlideShow on a SharePoint 2007 page

I wanted to embed a Picture Library as a SlideShow in a SharePoint 2007 page, but when I checked the Microsoft web site, their coverage of the SharePoint 2007 Picture Library function didn't have the information I needed. So, I had to figure it out for myself.

So here's what I did to embed a Picture Library SlideShow on the page ...

  1. First, I created a SharePoint Picture Library in the normal way and loaded up the images.
  2. Next, in the newly-created Picture Library, I selected View Slide Show from the Actions menu.


  3. This brings up the Slide Show in a new browser window. I right-clicked on the Slide Show and selected Properties.


  4. I highlighted the URL of the Slide Show and copied to the clipboard with the ctrl-c function.


  5. Then I placed a Page Viewer Web Part on the selected SharePoint page and added the URL from the clipboard. You may have to adjust the height of the Page Viewer Web Part to accommodate the size of image you're using.
That's it ...

Thursday, 23 August 2012

Concertina - reveal and hide text by click

In our SharePoint 2007 site collection we've had quite a few requests for FAQs that open when the question is clicked then snap shut when the question is clicked again. This is a fairly simple effect to achieve in a Data View Web Part.


To contain the FAQ questions and answers, create a custom list and add a single additional multi-line text column, Answer, to hold the answers. You'll use the Title column to hold the questions. If you expect the FAQs to divide into sections, you can another field called Category, perhaps as a Choice field, and add your categories as choice values.

Now add one or two questions and answers (and if applicable, assign a Category value to each q&a) so you'll be able to see content as you build your Data View Web Part.

Next, create a Data View Web Part on the appropriate page and insert data from the fields Title and Answer.

Finally, replace the table-row that's displaying your list data in the DVWP with this code:

    <xsl:if test="position() = 1">
     <tr>
      <td>
       <h2><xsl:value-of select="@Category"/></h2>
      </td>
     </tr>
     </xsl:if>
     <tr>
      <td class="ms-vb"><span style="cursor:pointer" onclick="if (this.parentNode.parentNode.nextSibling.style.display=='none') this.parentNode.parentNode.nextSibling.style.display='block'; else this.parentNode.parentNode.nextSibling.style.display='none';" >
       <h3 style="margin:0px"><img src="/masterPageTemplateImages/miniplus.gif" />&#x9;<xsl:value-of select="@Title" /></h3></span></td>
 
     </tr>
     <tr style="display:none">
      <td class="ms-vb">
       <xsl:value-of select="@Answer" disable-output-escaping="yes" /></td>
 
     </tr>
     <tr><td><img src="/masterPageTemplateImages/spacer.gif" height="10" width="50"/></td></tr>


The "miniplus.gif" image is optional, but helps clarify for the users that the question is clickable to reveal the answer and the final table cell with the spacer.gif just adds a little space between the q&as.

That's it - job done!