如何格式化/缩进 XSL 转换的输出

发布于 2024-10-04 13:22:52 字数 980 浏览 3 评论 0原文

我正在尝试输出一段 html 代码。但我需要它打印漂亮/缩进。 有没有办法在不使用 &#xa;&#9;< 的情况下执行此操作;/xsl:text>?

我使用了以下行,但没有任何结果。

<xsl:output method="html" indent="yes"/>

以下是c#代码;

    XslCompiledTransform XSLT = new XslCompiledTransform();
    XSLT.Load(xslPath);

    using (XmlTextWriter writer = new XmlTextWriter(writePath, null))
    {
        if (isTopLevel)
        {
            XSLT.Transform(XMLDocumentForCurrentUser, writer);
        }
        else
        {
            XsltArgumentList xslArg = new XsltArgumentList();
            xslArg.AddParam("MenuIndex", "", menuIndex);
            XSLT.Transform(XMLDocumentForCurrentUser, xslArg, writer);
        }
    }
 // I write the output to file  
//All this works fine, only now I need the HTML to be readable (in the browser's view source or any notepad)

有人知道格式化(至少缩进)XSLT 输出的方法吗?

I am trying to output a fragment of html code. But I need it to be pretty-printed/indented.
Is there any way to do this without using <xsl:text> </xsl:text> and <xsl:text> </xsl:text>?

I have used the following line without any results.

<xsl:output method="html" indent="yes"/>

Follwoing is the c# code;

    XslCompiledTransform XSLT = new XslCompiledTransform();
    XSLT.Load(xslPath);

    using (XmlTextWriter writer = new XmlTextWriter(writePath, null))
    {
        if (isTopLevel)
        {
            XSLT.Transform(XMLDocumentForCurrentUser, writer);
        }
        else
        {
            XsltArgumentList xslArg = new XsltArgumentList();
            xslArg.AddParam("MenuIndex", "", menuIndex);
            XSLT.Transform(XMLDocumentForCurrentUser, xslArg, writer);
        }
    }
 // I write the output to file  
//All this works fine, only now I need the HTML to be readable (in the browser's view source or any notepad)

Does anybody know of a way to format(atleast indent) XSLT output?

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

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

发布评论

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

评论(1

〗斷ホ乔殘χμё〖 2024-10-11 13:22:52

如果您希望 XSLT 处理器应用 xsl:output 指令,请勿创建自己的 XmlTextWriter。相反,直接写入文件或创建 XmlWriter,如下所示:

using (XmlWriter result = XmlWriter.Create(writePath, XSLT.OutputSettings))
{
        if (isTopLevel)
        {
            XSLT.Transform(XMLDocumentForCurrentUser, result);
        }
        else
        {
            XsltArgumentList xslArg = new XsltArgumentList();
            xslArg.AddParam("MenuIndex", "", menuIndex);
            XSLT.Transform(XMLDocumentForCurrentUser, xslArg, result);
        }
}

Don't create your own XmlTextWriter if you want the XSLT processor to apply the xsl:output directive. Instead either write directly to a file or create an XmlWriter as follows:

using (XmlWriter result = XmlWriter.Create(writePath, XSLT.OutputSettings))
{
        if (isTopLevel)
        {
            XSLT.Transform(XMLDocumentForCurrentUser, result);
        }
        else
        {
            XsltArgumentList xslArg = new XsltArgumentList();
            xslArg.AddParam("MenuIndex", "", menuIndex);
            XSLT.Transform(XMLDocumentForCurrentUser, xslArg, result);
        }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文