Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用XSLT和C将DOCTYPE添加到HTML#_C#_Xml_Xslt_Xhtml_Doctype - Fatal编程技术网

C# 如何使用XSLT和C将DOCTYPE添加到HTML#

C# 如何使用XSLT和C将DOCTYPE添加到HTML#,c#,xml,xslt,xhtml,doctype,C#,Xml,Xslt,Xhtml,Doctype,我将XSLT与C结合使用,将xml文档转换为HTML。我需要DOCTYPE在HTML文档中。但不知何故,我似乎无法让它出现。请帮忙 我的xsl包括以下内容 <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"> <xsl:outpu

我将XSLT与C结合使用,将xml文档转换为HTML。我需要DOCTYPE在HTML文档中。但不知何故,我似乎无法让它出现。请帮忙

我的xsl包括以下内容

<?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
    <xsl:output method="xml" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" indent="yes"/>

你知道我做错了什么吗?我正在使用.NET4.0。提前感谢。

不要向XmlTextWriter写入,只需使用一个重载来写入文件,例如

XslCompiledTransform proc = new XslCompiledTransform();
proc.Load(ConfigurationManager.AppSettings["XsltFilePath"] == null ? "MyTransform.xsl" : ConfigurationManager.AppSettings["XsltFilePath"]);

String resultFileName = Path.Combine(myFolder, myName, "index.html");

proc.Transform(myPath, resultFileName);
我使用了
xslcomiledtransform
而不是
XslTransform
,因为后者从.NET 2.0开始就被弃用了


如果您真的想使用
XslTransform
,那么您可以使用类似的
Transform
方法

XslCompiledTransform proc = new XslCompiledTransform();
proc.Load(ConfigurationManager.AppSettings["XsltFilePath"] == null ? "MyTransform.xsl" : ConfigurationManager.AppSettings["XsltFilePath"]);

String resultFileName = Path.Combine(myFolder, myName, "index.html");

proc.Transform(myPath, resultFileName);
我使用了
xslcomiledtransform
而不是
XslTransform
,因为后者从.NET 2.0开始就被弃用了


如果您真的想使用
XslTransform
,那么您可以使用类似的
Transform
方法。

问题确实在于不编写doctype的XmlWriter。这只是围绕着它工作。知道xmlwriter为什么不输出doctype吗?这将真正回答这个问题。据我所知,允许您写入XmlWriter的转换方法的重载允许您覆盖样式表中的
xsl:output
指令。如果要将输入文件转换为结果文件,并希望
xsl:output
控制编码、标识、doctype等,则应使用重载来写入文件或文件流。如果你真的想写一个XmlWriter,但是想用
xsl:output
设置来控制序列化选项,那么就使用
XmlWriter.Create(“result.html”,proc.OutputSettings)
(对于
xslcomiledTransform
),这就解决了我的问题,而且肯定帮助我理解了行为背后的原因。谢谢。否则我会在这里呆上好几天。谢谢。问题确实是XmlWriter没有编写doctype。这只是围绕着它工作。知道xmlwriter为什么不输出doctype吗?这将真正回答这个问题。据我所知,允许您写入XmlWriter的转换方法的重载允许您覆盖样式表中的
xsl:output
指令。如果要将输入文件转换为结果文件,并希望
xsl:output
控制编码、标识、doctype等,则应使用重载来写入文件或文件流。如果你真的想写一个XmlWriter,但是想用
xsl:output
设置来控制序列化选项,那么就使用
XmlWriter.Create(“result.html”,proc.OutputSettings)
(对于
xslcomiledTransform
),这就解决了我的问题,而且肯定帮助我理解了行为背后的原因。谢谢。否则我会在这里呆上好几天。谢谢。