Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

5 Answers

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/

share|improve this answer
add comment

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

http://spxslt.codeplex.com/documentation

Cheers, Matt B.

share|improve this answer
add comment

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

xsl:value-of select="@Body" disable-output-escaping="yes"
share|improve this answer
    
Thank you. Doesn't address the original question but certainly fixes my issue ;-) –  David Clarke Aug 19 '13 at 3:44
add comment

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.

share|improve this answer
add comment

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".

share|improve this answer
add comment

Your Answer

 
discard

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.