Is there a simple built in xslt function or easy way to strip the html tags from a rich text field in a sharpoint list? I only want to return the text the end user put in.

The scenerio is im aggregating data and the source data in the source list has formatted html for various reasons. however we only want to show the text of that data in the report I am building.

im having a mental block and i know its rather simple its just not occuring to me at the moment. I tried something as simple as but im getting nothing back.

Thanks in advance

5 Answers 5


Marc Anderson has a blog post that covers stripping HTML from rich text fields to display the first n number of characters of a field. You can probably use a portion of his post to accomplish what you're looking to do: http://mdasblog.wordpress.com/2009/01/20/displaying-the-first-n-words-of-a-long-text-column-with-xsl/


Try using the "disable-outscape-escaping" property after xsl:value-of select="@YourField" like this:

xsl:value-of select="@Body" disable-output-escaping="yes"
  • Thank you. Doesn't address the original question but certainly fixes my issue ;-) Commented Aug 19, 2013 at 3:44

There is also a codeplex venture featuring the StripHTML template. This should give you what your result:


Cheers, Matt B.


Just use the string() function; or the xsl:value-of instruction, applied to the root node containing the "rich text". In both cases, you get the concatenation of all the descendant text nodes.


Using the trick webdes03 mentions is the way to go. Since the field value is stored as escaped html, it will be (to xsl at least) be a textnode. You'd think that doing a double value-of select (i.e. store the result of the first value-of select with disable-output-escaping set to true in a variable and then do a regular value-of select over that variable would result in clean html.

But this is not the case. If it were, it would become possible for xsl to "create" a piece of malformed xml and that would break, so a value-of will always result in a textnode, not a nodeset. And we all know how "great" (generated) html usually looks (especially in SharePoint :-D!).

So you have to strip the field content using Marc Anderson's "trick".

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.