如何格式化/缩进 XSL 转换的输出
我正在尝试输出一段 html 代码。但我需要它打印漂亮/缩进。 有没有办法在不使用
和
?
我使用了以下行,但没有任何结果。
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望 XSLT 处理器应用 xsl:output 指令,请勿创建自己的 XmlTextWriter。相反,直接写入文件或创建 XmlWriter,如下所示:
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: