DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

CQWP Remove Markup from escaped page content

Posted by PANVEGA on March 18, 2009

I created a CQWP Template for displaying Items with some formatted Rich-Text Content. Nothing special. In addition the Rich-Text Description field should only display the first 180 letters and here is the small issue. An advanced Rich-Text field creates a div class around each content.

<div class=ExternalClassD7864B0CF5B14386AF6CB349205DC792> <div><font size=2>documental que toda compañía precisa: Flujos en Serie Flujos Paralelos (varios aprobadores) …

Howver when I cut the rest of the string, the closing tag is lost. The same problem with a standard Rich-Text field. If you have a open tag before the 180 letters and the closing tag after that, your whole fortmatting is gone.

Solution: Remove all the markups from the Body String in a recursive template call. If you do not want to do that, you can just use a normal multiline textfield without any formating tags in it.

Example: calling the template and give the whole body content as a parameter.

<xsl:variable name=”bodyContent”>
<xsl:call-template name=”removeMarkup”>
<xsl:with-param name=”string” select=”@Body”/>

<!– Remove Markup from escaped page content – Call function in the style –>
<xsl:template name=”removeMarkup”>
<xsl:param name=”string” />
<xsl:when test=”contains($string, ‘&lt;’)”>
<xsl:variable name=”nextString”>
<xsl:call-template name=”removeMarkup”>
<xsl:with-param name=”string” select=”substring-after($string, ‘&gt;’)” />
<xsl:value-of select=”concat(substring-before($string, ‘&lt;’), $nextString)” />
<xsl:value-of select=”$string” />

Here is the part of my body description ta

<span class=”description”>
<xsl:when test=”(string-length($bodyContent) &gt; 180)”>
<xsl:value-of select=”concat(substring($bodyContent,0,180),’ …’)”/>
<xsl:value-of select=”$bodyContent”/>
</span >

That is all you need

Good luck


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: