- 用户在浏览器中的多行文本框中键入文本 数据
- 作为 XML 片段的一部分存储在 SQL Server xml 列中 XML
- 片段随后合并到更大的 xml 文档中
- 文档通过 XSLT 处理成 HTML 电子邮件
- 预期收件人要查看我尝试过的原始换行符
:
- CDATA(由 SQL 删除)
-
输出中的标记围绕注释和 NL 字符编码
> 标签在数据中(不会在 HTML 中解码)
可以在不重新构建所有内容的情况下完成吗?
根据评论中的请求,以下是实际代码:
XSL
<TD>
<xsl:value-of select="//MemoComment"/>
</TD>
XSLT 输入数据的
- 变体
以前的工作:助理,波士顿
Test1
Test2
-
上一份工作:助理,波士顿 &#xA;Test1 
Test2
-
上一份工作:助理,波士顿<br/>Test1<br/& gt;Test2
相应的 XSLT 结果
以前的工作:助理, BostonTest1Test2
-
上一份工作:助理,波士顿
Test1
Test2
-
|
这些都无法在 Outlook 中正确呈现。
- 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 
Test1 
Test2</MemoComment>
<MemoComment>Previous job: Associate, Boston<br/>Test1<br/>Test2</MemoComment>
Corresponding XSLT Results
<TD>Previous job: Associate, BostonTest1Test2</TD>
<TD>Previous job: Associate, Boston
Test1
Test2</TD>
<TD>Previous job: Associate, Boston<br/>Test1<br/>Test2</TD>
None of which renders correctly in Outlook.
发布评论
评论(2)
问题的原因是您在实际需要
copy-of>
:value 时使用了
-of> 仅选择所选节点的字符串值。您真正想要的是复制整个节点,包括它包含的元素。然后,您可以将数据保存为格式化的 XHTML 片段,而无需元素语法转义(输入列表中的格式编号 1)。通常不鼓励使用
disabe-output-escaping="yes"
,因为它可能导致输出格式错误的 XML。此外,所有 XSLT 处理器都不实现此功能,因为它实际上仅在文档序列化时才生效,并且如果输出文档作为数据结构从处理器传递,则可能不会产生任何效果。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.尝试在文本中嵌入转义的
元素,并设置
元素更改为yes
:Try embedding escaped
<br>
elements in your text and setting thedisable-output-escaping
attribute of your<xsl:value-of>
element toyes
: