在没有HTML编码最终输出的情况下,使用XSL进行转换的属性方法是什么? [英] What's the property way to transform with XSL without HTML encoding my final output?
问题描述
因此,我正在使用.NET.我有一个XSL文件,即C#中的XslTransform对象,它读取XSL文件并将一个XML数据(内部制造)转换为HTML.
So, I am working with .NET. I have an XSL file, XslTransform object in C# that reads in the XSL file and transforms a piece of XML data (manufactured in-house) into HTML.
我注意到我的最终输出已自动编码为< 和& gt;的< 和> ..有什么办法可以防止这种情况发生?有时我需要加粗或斜体显示文本,但无意中将其清除了.
I notice that my final output has < and > automatically encoded into < and >. Is there any ways I can prevent that from happening? Sometimes I need to bold or italicize my text but it's been unintentionally sanitized.
推荐答案
您的xsl文件应具有:
Your xsl file should have:
- html的输出
- 省略xslt中使用的所有名称空间
即
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="xsl msxsl">
<xsl:output method="html" indent="no" omit-xml-declaration="yes"/>
<!-- lots -->
</xsl:stylesheet>
并且理想情况下,您应该使用接受 TextWriter
或 Stream
(不是 XmlWriter
)的重载-例如:>
And you should ideally use the overloads that accept either a TextWriter
or a Stream
(not XmlWriter
) - i.e. something like:
StringBuilder sb = new StringBuilder();
using (XmlReader reader = XmlReader.Create(source)
using (TextWriter writer = new StringWriter(sb))
{
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("Foo.xslt"); // in reality, you'd want to cache this
xslt.Transform(reader, options.XsltOptions, writer);
}
string html = sb.ToString();
在xslt中,如果您确实想要独立的<
/>
(即,由于某种原因而希望其格式错误),则需要禁用输出转义:
In the xslt, if you really want standalone <
/ >
(i.e. you want it to be malformed for some reason), then you need to disable output escaping:
<xsl:text disable-output-escaping="yes">
Your malformed text here
</xsl:text>
但是,通常转义字符是正确.
However, in general it is correct to escape the characters.
这篇关于在没有HTML编码最终输出的情况下,使用XSL进行转换的属性方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!