Sunday, June 01, 2008

SharePoint Designer: Show Line Break for Multi Text (Plain Text)

If you have Multiline type column and set it with "Plain Text", you might have difficulty to show it using Data View (that is added using SharePoint Designer) for the content that has a line break. It will show as a single line. If you view the HTML Source of the page, the line-break character is actually printed there. It's just that HTML will not interpret such white-space character as line break.

There're 2 ways to overcome this issue:

1. Wrap your <xsl:value-of select="@Column_Name" escaping="yes"></xsl:value-of>using <pre>. However, you will lose the text-wrap functionality, since most browser will render <pre> as it is, no line break means no line break. This maybe a no-go to this solution.

2. Using xslt functionality to change all line break to.For example your original text is:
<xsl:value-of select="@Column_Name" escaping="yes"></xsl:value-of>

Replace it to:
<xsl:call-template name="breakitemdesc"></xsl:call-template>

Add below to the beginning of the other <xslt:template> or after </xslt:template> of the section:

<xsl:template name="breakitemdesc">
<xsl:param name="text" select="@item_x0020_Description"/>
<xsl:when test="contains($text, ' ')">
<xsl:value-of select="substring-before($text, ' ')"/>
<xsl:call-template name="breakitemdesc">
<xsl:with-param name="text" select="substring-after($text,' ')"/>
<xsl:value-of select="$text"/>


Anonymous said...

Hi Gunady,
i am in aa similar situation where i am using 'pre' tag but it doesnt wrap the text which is another problem!!
When i run your solution it gives an error 'cannot find template 'break'.. did u by chance miss any code snippet in this..
thanks for any help!!


Gunady said...

Hi SP,
Sorry, the "break" should be "breakitemdesc", as it is actually a recursive call. Thank you for highlighting back. Hope it's solved your problem.

Dlite said...

Thanks a lot for this! I had to change one detail from your code with the one from:

The code on this page gave me a
after each word. Replacing the space with
worked for me:

($text, '

George Michael Mavridis said...

Hi there.
This is a brilliant solution which saved me a lot of time.
The only backdraft is, that you will run into some display issues when you have some special characters like &">< etc.
To prohibit this some slight modifications are required:

1) Replace your substring before function to:

2) Replace your value of function to:

Hope this helps