SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a custom webpart to display the content of an announcement list similar to that of the Summary View of List View webpart. However I am not able to limit the character length of announcement body to 250 characters due to the presence of rich content in the body. Due to the project requirement creating a custom webpart is essential and I cannot use the OOB list view webpart. Is there a way to achieve similar functionality through code? Any help is highly appreciated.

Thanks in advance, Ankita

share|improve this question

You can use a method like below. This strips the HTML from your content, and displays plain text.

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

Then you setup a variable which cleans the text:

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

and finally, call this new variable and trim it down

<xsl:value-of select="substring($pureText, 0, 250)" />


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.