Tuesday, April 30, 2013

Remove hyperlink from lookup column in Dataview webpart in Sharepoint 2010

When you used lookup column in the list and implemented it in custom dataview webpart, the hyperlink appears on the lookup field value.

To remove the link from lookup field used the following tag:-

Just you have to replace with

<xsl:value-of disable-output-escaping="yes" select="@Teams"/>

By:

<xsl:value-of disable-output-escaping="yes"
select="substring-after(substring-before(substring-after(@Teams, 'ID='), '&lt;'), '&gt;')"/>


If you have added multiple selection lookup value in your list, and you want to remove hyperlink from field, the above trick will not work. For that we required to more customise the XSLT and used the following code:-

In multiple selection lookup value shows in data view web part:-

Team1; Team2; Team3; Team4

We will format it to:-

Team1
Team2
Team3
Team4

Using the following code:-

Add the below template to your data view web part:-

<!—Semicolon delimit start -- >
<xsl:template name="string-replace-all">
<xsl:param name="text" />
<xsl:param name="replace" />
<xsl:param name="by" />
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)" />                
<xsl:value-of select="$by" />
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)" />
<xsl:with-param name="replace" select="$replace" />
<xsl:with-param name="by" select="$by" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!—Semicolon delimit End -- >

<!—Remove Hyperlink start-- >

<xsl:template name="deleteAnchorTags">
<xsl:param name="Anchor"/>
<xsl:choose>
<xsl:when test="contains($Anchor, '&lt;')">                                    
<xsl:value-of select="substring-before($Anchor, '&lt;')"/>
<xsl:call-template name="deleteAnchorTags">
<xsl:with-param name="Anchor" select="substring-after($Anchor, '&gt;')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$Anchor"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!—Remove Hyperlink End-- >


And replace your tag with:-

<xsl:value-of disable-output-escaping="yes" select="@Teams"/>

By:-

<xsl:variable name="onlyText">
<xsl:call-template name="deleteAnchorTags">
<xsl:with-param name="Anchor" select="@Teams" />
</xsl:call-template>
</xsl:variable>
 <xsl:variable name="thisRow">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$onlyText" />
<xsl:with-param name="replace" select="';'" />
<xsl:with-param name="by" select="'&lt;br/&gt;'" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$thisRow" disable-output-escaping="yes"/>


Happy coding..... :-) :-) :-)

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. u r a genius. worked 1st time after I removed all the comments. . . .

    ReplyDelete
  3. Hello !

    Thanks a lot, it really helped me big time.

    I made some slights modifications because I wanted to keep my values separated with ";"

    Here's the code in case it might help someone :
























    ReplyDelete
  4. It will not work if list item contains multiple Lookup values. Please suggest approach to remove hyperlink for multiple lookup values.

    ReplyDelete