Showing posts with label xslt newline. Show all posts
Showing posts with label xslt newline. Show all posts

Wednesday, January 20, 2010

Newline breaks in XSLT (SharePoint DataForm Web Part)

Scenario: In a custom sharepoint .aspx page, I placed a dataform web part for display page of an item. The item has a column called "Contents". This is a field contains data as paragraphs. When I created a new item, entered data into "Contents" field with spaces between paragraphs. I want to see the data as I entered earlier in the EditForm.aspx & DisplayForm.aspx pages.

When I used , the contents field showed the data without newlines between the paragraphs.

Example:

I entered the data in NewForm.aspx as below:
"
aasdflasdf asdf asdf asdf asdf asdf.

234234aefase5asfgasdfa
asdfasdf
asdf
asdf
a

asdfasdfas"

Note: You can see spaces between the above statements. When I tried to display above content in DisplayForm.aspx, it showed without spaces & special characters as below:

"aasdflasdf asdf asdf asdf asdf asdf.234234aefase5asfgasdfaasdfasdfasdfasdfaasdfasdfas"

Solution:

Add following attributes to xsl:value-of tag:
a. select="ddwrt:AutoNewLine(string(@Contents))"
b. disable-output-escaping="yes"

Note:
1. You can find information about ddwrt:AutoNewLine at Microsoft Site.
2. disable-output-escaping="yes" attribute is meant for showing all special characters like quotes and so on.