Remove HTML Tags and Hyperlink using XSLT in Data form Webpart



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!!!

Up Next
    Ebook Download
    View all
    Learn
    View all