使用XslCompiledTransform将XML 转HTML

           XslCompiledTransform xsl = new XslCompiledTransform();
            if (!File.Exists(@"F:\XML&XSLT\demo\xml\index_html5.xsl"))
            {
              
            }
            try
            {
                xsl.Load(new System.Xml.XPath.XPathDocument(@"F:\XML&XSLT\demo\xml\index_html5.xsl"));
            }
            catch
            { }
            xsl.Transform(@"F:\XML&XSLT\demo\xml\index_html5.xml", @"F:\XML&XSLT\demo\xml\index.html");
            //System.Diagnostics.Process.Start(@"F:\XML&XSLT\demo\xml\index.html");

起初我使用 xsl.Load(@"F:\XML&XSLT\demo\xml\index_html5.xsl");出现异常:

因为安全原因,此 XML 文档中禁用 DTD。要启用 DTD 处理,将 XmlReaderSettings 上的 ProhibitDtd 属性设置为 false,并将该设置传递给 XmlReader.Create 方法。

后来使用xsl.Load(new System.Xml.XPath.XPathDocument(@"F:\XML&XSLT\demo\xml\index_html5.xsl"));这样可以正常执行。

原文地址:https://www.cnblogs.com/KimhillZhang/p/3017566.html