Tuesday 30 December 2008

InfoPath Rich Text Display in Form: Expression Box

Recently I faced an issue whereby a customer needed to pull rich text (XHTML) from a database, and have that displayed in the form (read-only) - through a web service.

For whatever reason, I couldn't use the Rich Text Box control within InfoPath to display the data. Normally I would just use an expression box to display read-only data on the form, as it renders and resizes appropriately and looks seamless.

However - the expression box was just rendering the XHTML source code ("<div class="'....'">asfsdgf</div>....."). So - to force the expression box to render the source code 'properly', we have to open the view xsl source file, and modify the tag that renders the data. This is easier than it sounds:

1. Bind an expression box to your Rich text data source element
2. File -> Save as Source Files
3. Open the appropriate view.xsl file in notepad
4. Find your expression box in the markup. This will look like <xsl:value-of select="MyElement" />
5. Add the following parameter to the xsl:value of tag: disable-output-escaping="yes"
So the updated tag will read:
<xsl:value-of select="MyElement" disable-output-escaping="yes" /> (where "MyElement" is your data source element).
6. Save, close, open the manifest file up in InfoPath and presto - your Rich Text XHTML is rendered as HTML in the form rather than as plain text.



This bugged me for a while - so hopefully it might save some of you some time!

davros.

No comments: