HiddenNetwork.com Banner
Showing posts with label XSLT. Show all posts
Showing posts with label XSLT. Show all posts

Wednesday, August 01, 2007

Modifying Search to Add a Send Link By Email link

My customer wanted a "send link by email" next to each search result item. "Easy", I thought and went ahead to edit the xslt for the search results. But I found out a problem with links that had spaces in them - the link in outlook would appear broken. To solve this, I had to write some simple javascript, and the process is described below.

Problem:
If you want a mailto link (href="mailto") that has in the body a link to a file, you may get a link like this:
href="mailto:body=http://server/site/library/this is my file.doc"
This is a problem, because the file name contains spaces. The email will open with a broken link in it's body:

Solution:
Luckily, SharePoint has a javascript functions that solves that for us. They are "escapeProperly" and "navigateMailToLink". What I did is create a function of my own in the page:

function SendEmailWithLink(link)
{
      var link = "mailto:?body=" + escapeProperly(link);
      navigateMailToLink(link);
      return false;
}

And my link is:
href="#nowhere" onclick="javascript:SendEmailWithLink('');"

This article would'nt be complete if I didn't explain why I did this - this if for the search results xslt - the idea was to add a "send link by email" button next to each search result. The solution - change the xslt to include the script above, and a button like this:

<a title="E-mail a Link" href="#nowhere">
      <xsl:attribute name="onclick">
         javascript:SendEmailWithLink('<xsl:value-of select="$url"></xsl:value-of>');
       </xsl:attribute>
       <img border="0" src="/_layouts/images/ICMSG.GIF"/> 
</a>

We also added other actions (I will try to get them published) and came up with the following for each result item:

Monday, July 02, 2007

Tips on xslt dataviews by Mark Kruger!

Take a look at "Free SharePoint DataView Tips" by Mark Kruger. Useful!

Wednesday, June 27, 2007

Adding table headers and/or footers to a Content Query Web Part Layout

Just found this article by Mike Gehard which shows a good step by step of making a content query web part look like a grid - with column headers and all.
Mike is even using the same ddwrt trick as I am for formatting dates, and I now see that his blog seems to be dedicated to the content query web part!


I recommend you go to Mike's blog and read all about it. The method he is taking is chaning the "ContentQueryMain.xsl" file to pass the lastrow as a parameter to the "CallItemTemplate", and then in "CallItemTemplate" he passes the lastrow to the apply templates itemstyle.
In the "Itemstyle.xsl" file you add html variables for the header and the footer, and use them before the first row and after the last row.
I will try to contact Mike and ask for permission to reprint his article here for redundancy.

Mike - if you are reading this, how about you join the Enhanced Content Query Web Part project?

Tuesday, June 26, 2007

Using DDWRT in xslt-based web parts

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.