- User types text into a multi-line text box in the browser
- Data is stored as part of an XML snippet in a SQL Server xml column
- XML snippet is later incorporated into a larger xml document
- Document is processed via XSLT into an HTML email
- Recipient is expected to see the original line breaks
I tried:
- CDATA (removed by SQL)
<PRE>tag in the output around the comments and encoding of the NL character- encoded
<BR>tag in the data (does not get decoded in the HTML)
Can this be done without rearchitecting everything?
Per request in the comments, here is the actual code:
The XSL
<TD>
<xsl:value-of select="//MemoComment"/>
</TD>
Variations of input data into the XSLT
<MemoComment>Previous job: Associate, Boston<br/>Test1<br/>Test2</MemoComment><MemoComment>Previous job: Associate, Boston &#xA;Test1 &#xA;Test2</MemoComment><MemoComment>Previous job: Associate, Boston&lt;br/&gt;Test1<br/>Test2</MemoComment>
Corresponding XSLT Results
<TD>Previous job: Associate, BostonTest1Test2</TD><TD>Previous job: Associate, Boston&#xA;Test1&#xA;Test2</TD><TD>Previous job: Associate, Boston&lt;br/&gt;Test1<br/>Test2</TD>
None of which renders correctly in Outlook.
Reason for your problem was that you used
<xsl:value-of>when you actually needed
<xsl:copy-of><xsl:value-of>only selects the string value of the selected node. What you actually wanted is to copy of whole node including the elements that it contained. Then you can save the data as a formatted XHTML snippet without the need of element syntax escaping (format number 1 on your input list).Usage of
disabe-output-escaping="yes"is often discouraged because it can lead to outputting malformed XML. Also all XSLT processors don’t implement this feature since it actually takes effect only when the document is serialized, and might not have any effect if the output document is passed on from the processor as a data structure.