HTML 在 .NET 中呈现不正确

发布于 2024-07-11 21:41:37 字数 221 浏览 12 评论 0 原文

我试图在 VB.NET 中获取字符串“
”并通过 XSLT 将其转换为 HTML。 然而,当 HTML 出来时,它看起来像这样:

<BR>

我只能假设它会继续并尝试渲染它。 有什么方法可以将这些 </> 转换回括号中,以便我得到我想要的换行符吗?

I am trying to take the string "<BR>" in VB.NET and convert it to HTML through XSLT. When the HTML comes out, though, it looks like this:

<BR>

I can only assume it goes ahead and tries to render it. Is there any way I can convert those </> back into the brackets so I get the line break I'm trying for?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

弃爱 2024-07-18 21:41:37

检查 XSLT 是否具有:

<xsl:output method="html"/>

编辑:注释中的解释

默认情况下,XSLT 输出为 XML(1),这意味着它将转义任何重要字符。 您可以在特定实例中使用属性 disable-output-escaping="yes" 覆盖此设置(简介 此处),但更强大的是将输出更改为 HTML 的显式值,这在全局范围内具有相同的好处,如下所示:

  • 对于脚本和样式元素,替换任何转义字符(例如
    作为& 和 >) 及其实际值
    (分别为& 和>)。
  • 对于属性,替换所有出现的 > 与 >。
  • 写入空元素,如
    ,不带
    结束标签或斜杠。
  • 将通过其存在来传达信息的属性编写为
    反对它们的价值,例如
    检查并选择,以最小化
    形式。

来自涵盖该主题的可靠 IBM 文章, stylusstudio 此处的最新报道

如果 HTML 输出是您想要的想要的 HTML 输出是您应该指定的。

(1) 实际上存在输出默认为 HTML 的极端情况,但我认为它不是通用的,而且依赖它有点迟钝。

Check the XSLT has:

<xsl:output method="html"/>

edit: explanation from comments

By default XSLT outputs as XML(1) which means it will escape any significant characters. You can override this in specific instances with the attribute disable-output-escaping="yes" (intro here) but much more powerful is to change the output to the explicit value of HTML which confides same benefit globally, as the following:

  • For script and style elements, replace any escaped characters (such
    as & and >) with their actual values
    (& and >, respectively).
  • For attributes, replace any occurrences of > with >.
  • Write empty elements such as <br>, <img>, and <input> without
    closing tags or slashes.
  • Write attributes that convey information by their presence as
    opposed to their value, such as
    checked and selected, in minimized
    form.

from a solid IBM article covering the subject, more recent coverage from stylusstudio here

If HTML output is what you desire HTML output is what you should specify.

(1) There is actually corner case where output defaults to HTML, but I don't think it's universal and it's kind of obtuse to depend on it.

遗弃M 2024-07-18 21:41:37

尝试用 <br> 包裹它

Try wraping it with <xsl:text disable-output-escaping="yes"><br></xsl:text>

神也荒唐 2024-07-18 21:41:37

不了解 XSLT,但是..

一种解决方法可能是使用 HttpUtility.HtmlDecode

using System;
using System.Web;

class Program
{
    static void Main()
    {
        Console.WriteLine(HttpUtility.HtmlDecode("<br>"));
        Console.ReadKey();
    }
}

...

Don't know about XSLT but..

One workaround might be using HttpUtility.HtmlDecode from System.Web namespace.

using System;
using System.Web;

class Program
{
    static void Main()
    {
        Console.WriteLine(HttpUtility.HtmlDecode("<br>"));
        Console.ReadKey();
    }
}

...

千と千尋 2024-07-18 21:41:37

知道了! 除了选定的答案之外,我还在我的字符串上做了类似的事情:

htmlString = htmlString.Replace("<","<")
htmlString = htmlString.Replace(">",">")

不过,我认为最终我可能只是使用

 标签来保留所有内容。

Got it! On top of the selected answer, I also did something similar to this on my string:

htmlString = htmlString.Replace("<","<")
htmlString = htmlString.Replace(">",">")

I think, though, that in the end, I may just end up using <pre> tags to preserve everything.

染火枫林 2024-07-18 21:41:37

字符串“
”已经是 HTML,因此您只需 Response.Write("
")
即可。

但你指的是 XSLT,所以我想正在进行一些转换。 在这种情况下,变换肯定应该将其作为节点插入到正确的位置。 更好的问题可能会得到更好的答案

The string "<br>" is already HTML so you can just Response.Write("<br>").

But you meantion XSLT so I imagine there some transform going on. In that case surely the transform should be inserting it at the correct place as a node. A better question will likely get a better answer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文