Remove hyperlink from lookup field in XSLT list view web part

When you read the title you probably think I will discuss about client side rendering, but I am not. This example is based on SharePoint 2010 an no client side rendering is available for this web part. But you still can do this using classic XSLT and customize only specific items from the view.

I had a list containing time off requests with a lookup column called “Activity” (internal name is the same). By default, this kind of field is render like a hyperlink to the item from lookup list and, by mistake, some users clicked on this link instead of clicking on edit icon.

Timesheet - 0_Start view - Internet Explorer

If you want to remove the hyperlink, open the page with SharePoint Designer and add this code below “XmlDefinition” node.

<xsl:stylesheet xmlns:x="" xmlns:d="" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="" xmlns:asp="" xmlns:__designer="" xmlns:xsl="" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:o="urn:schemas-microsoft-com:office:office">
<xsl:include href="/_layouts/xsl/main.xsl"/> 
<xsl:include href="/_layouts/xsl/internal.xsl"/>


And now we are ready to add customization code for “Activity” field, which contains only a few lines of code, inside “xsl:stylesheet” declaration.

<xsl:template match ="FieldRef[@Name='Activity']"  mode="Lookup_body">
<xsl:param name="thisNode" select="." />
<xsl:param name="activity" select="substring-after($thisNode/@Activity.,'#')" />
<xsl:value-of select="$activity" disable-output-escaping="yes" />

Please note that activity parameter doesn’t take the value from “@Activity” attribute of current node. Instead “@Activity.” is used (a dot is added to attribute name). Also, we need to make a “substring-after” operation because the data obtained from the server has this format: “2;#Holiday”.
Timesheet - 1_My time - Internet Explorer


Leave a Reply

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

You are commenting using your 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