Tuesday, July 29, 2008

Problems with Special Characters in XSLT

Problem:
When you use Special Character like '&' and '<' during XSLT transformation, they are not rendered properly. Eg.

Expected Output:SharePoint SharePoint & SharePoint
Output:SharePoint SharePoint &amp; SharePoint

Reason:
This is the normal behaviour if you consider the XSLT specification : "Normally, the XML output method" (the default method)" escapes '&' and '<' (and some other characters) when outputting text nodes" (i.e. when using <xsl:text>or <xsl:value-of> nodes). Resolution:
You can disable this feature by setting the 'disable-output-escaping' attribute to 'yes' in these nodes.

Steps:
In your xsl file, replace your:

<xsl:value-of select="@href">
to:

<xsl:value-of select="@href" disable-output-escaping="yes">
Risks:
http://blogs.msdn.com/sharepointdesigner/archive/2008/09/20/using-disable-output-escaping-in-data-view.aspx

0 comments: