SIGN UP MEMBER LOGIN:    
ARTICLE

Remove HTML Tags and Hyperlink using XSLT in Data form Webpart

Posted by Suri meenakshi Sundaram Articles | SharePoint October 25, 2010
In this article you will learn how to Remove HTML Tags and Hyperlink using XSLT in Data form Webpart.
Reader Level:


Here we will see how to remove HTML using XSLT in Data form Web part to Control the Rich text field Content.

The Following XSL template shows how to remove the tags from the HTML so that you are only left with the text within the HTML to handle the Rich text field Content Value.

<xsl:template name="deleteHtmlTags">
<xsl:param name="html"/>
<xsl:choose>
<
xsl:when test="contains($html, '&lt;')">
<xsl:value-of select="substring-before($html, '&lt;')"/>
<!-- Recurse through HTML -->
<xsl:call-template name="deleteHtmlTags">
<xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
</xsl:call-template>
</
xsl:when>
<
xsl:otherwise>
<
xsl:value-of select="$html"/>
</xsl:otherwise>
</
xsl:choose>
</xsl:template>

To use the template you call it passing the HTML as a paramter... to delete the HTML tags.

<xsl:variable name="onlyText">
<xsl:call-template name=" deleteHtmlTags">
<xsl:with-param name="html" select="@Body" />
</xsl:call-template>
</xsl:variable>

Before Using the Variable it will display all the content like as follows :

1.gif

Then using this variable to display only text with Read more Option to view the

2.gif

<div class="ms-PostBody">
<div >
<xsl:value-of select="substring($onlyText, 0, 360)" />
<div align="right" style="color:red;text-decoration:none">
<a href="{$HttpVDir}/Lists/Posts/Post.aspx?ID={@ID}">
<font color="red">Read more</font></a>...</div>
</div>
</div>

After you Implementing this, it will be like as follows

3.gif

Remove person (Author) hyper link from Data view Webpart using XSLT

Here we will see how you can eliminate the hyperlink, when displaying the column @Author (posted by) in a Data View Web Part (DVWP) SharePoint displays a link to the UserDisp.aspx page.

If you don't want to have the link just extract the Person's name from the column HTML generated code.
Just you have to replace with

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

By:

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

In some cases Author format is like xxxxxxx(xxx,IND) / xxxxxxx(xxx,USA). If you want to replace the Author from this format

You can use the below one.

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

After applying the changes, it will show only Author name without hyperlink.

Enjoy!!!

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Become a Sponsor