SharePoint XSLT data view : issues rendering special characters (e.g. &, >, “) and line breaks

I have had problem with my custom display form, where displaying the content of a multiple line text box field does not render the special characters (such as &, >, “) and line breaks properly. After Googling for a couple of hours, there were no solution to my problem. Many suggested using “disable-output-escaping” to fix the special character issue, and some suggested using select=”ddwrt:AutoNewLine(string(@Description))” to fix the line breaks issue. They cannot co-exist in the “xsl:value-of” tag because the AutoNewLine function will overwrite the special characters with their HTML encoding (see here).

Finally, I have worked out a solution to resolve both issues. Adding the following template (function) to your display form ASPX and calling it when display a multiple line text field. It replaces the new line character (n or ) with a
.

Add this function to your DispForm.aspx file:













Where your multiple line text is displaying, replace this:

with this:



Although it might be a bit of work to replace all the multi-line text fields with the template call, it will finally give you some peace of mind. I’d be happy to know if you have any better ideas to overcome all these hassles. 🙂

4 comments on “SharePoint XSLT data view : issues rendering special characters (e.g. &, >, “) and line breaks”

  1. Anonymous

    Hello,

    thanks for this post. After I have added the code into my site, I get the following error:
    'xsl:call-template' does not match the start tag xsl:width-param'

    Any idea?
    Thx in advance.
    Andreas

  2. Anonymous

    It was only a mistake in my comment, not in the code. Still the same error "This Web Part does not have a valid XSLT stylesheet: Error: End tag 'xsl:call-template' does not match the start tag 'xsl:with-param'

    I am not sure, where I have to insert the code in the Disp.Form.aspx. Can you pleae give me a hint?

Leave A Reply

Your email address will not be published. Required fields are marked *