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

1 Answer 1


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)" />


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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