我使用VS 2008,.net 3.5来使用XSLT生成页面HTML。
我的消息中包含\r\n(换行符)
我在XSL文件中使用以下代码:
<b>Message: </b><xsl:value-of select="Message"/><br/>
我需要在XSL中用<br/>
替换掉 \r\n
。我看到了一些参考资料,但没有解决我的问题:
在调用转换XSLT之前,我使用以下C#代码,但不正确:
m = m.Replace(@"\r\n", "
");
m = m.Replace(@"\n", "
");
//m = System.Web.HttpUtility.HtmlDecode(m);
m = m.Replace(@"\r\n", "<br/>");
m = m.Replace(@"\n", "<br/>");
msg = "<Exception>"
+ "<Description>" + d + "</Description>"
+ "<Message>" + m + "</Message>"
+ "<DateTime>" + localTimeString + "</DateTime>"
+ "</Exception>";
我使用了这些参考资料,但并没有解决我的问题。
Replace 函数仅适用于 XSLT 2.0 版本,而 Visual Studio 使用的是 1.0 版本。即使你已经指定版本为“2.0”,也不意味着 Visual Studio 支持它。
我像最后一个参考资料那样使用,但是我收到了错误消息:
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="Message"/>
<xsl:with-param name="replace" select="\r\n"/>
<xsl:with-param name="by" select="<br/>"/>
</xsl:call-template>
建议,有任何示例代码可用吗?