Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.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#_Asp.net_Xml_Xslt_Webforms - Fatal编程技术网

C# 未加载来自XSLT的数据

C# 未加载来自XSLT的数据,c#,asp.net,xml,xslt,webforms,C#,Asp.net,Xml,Xslt,Webforms,我有一个ASP.NET Web表单应用程序。 我使用XSLT来形成HTML页面 <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/"> <ht

我有一个ASP.NET Web表单应用程序。 我使用XSLT来形成HTML页面

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>
  <xsl:template match="/">
    <html>
      <head>
        <title>Footballer's XSLT Demo</title>
      </head>
      <body>
        <h2>Footballer's Information</h2>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
但没有显示任何信息。
我应该怎么做?

下面是加载xslt文件的代码

            XmlDocument xmlDoc = new XmlDocument();
            System.IO.Stream xmlStream;
            System.Xml.Xsl.XslCompiledTransform xsl = new System.Xml.Xsl.XslCompiledTransform();
            ASCIIEncoding enc = new ASCIIEncoding();
            System.IO.StringWriter writer = new System.IO.StringWriter();

        String TransactionXML = "<xml><node></node></xml>";
        // Get Xsl
        xsl.Load(HttpContext.Current.Server.MapPath("footballers.xslt"));
        // Remove the utf encoding as it causes problems with the XPathDocument
        TransactionXML = TransactionXML.Replace("utf-32", "");
        TransactionXML = TransactionXML.Replace("utf-16", "");
        TransactionXML = TransactionXML.Replace("utf-8", "");
        xmlDoc.LoadXml(TransactionXML);

        // Get the bytes
        xmlStream = new System.IO.MemoryStream(enc.GetBytes(xmlDoc.OuterXml), true);

        // Load Xpath document
        System.Xml.XPath.XPathDocument xp = new System.Xml.XPath.XPathDocument(xmlStream);

        // Perform Transform
        xsl.Transform(xp, null, writer);
        Response.Write(writer.ToString());

您正在提供转换,但源数据在哪里?转换用于读取XML并根据xslt输出,但您似乎缺少XML源代码。前面的评论员是对的,尽管我会使用不同的措辞:xslt通常转换XML输入文档。而且,在我看来,您并没有真正调用转换。
            XmlDocument xmlDoc = new XmlDocument();
            System.IO.Stream xmlStream;
            System.Xml.Xsl.XslCompiledTransform xsl = new System.Xml.Xsl.XslCompiledTransform();
            ASCIIEncoding enc = new ASCIIEncoding();
            System.IO.StringWriter writer = new System.IO.StringWriter();

        String TransactionXML = "<xml><node></node></xml>";
        // Get Xsl
        xsl.Load(HttpContext.Current.Server.MapPath("footballers.xslt"));
        // Remove the utf encoding as it causes problems with the XPathDocument
        TransactionXML = TransactionXML.Replace("utf-32", "");
        TransactionXML = TransactionXML.Replace("utf-16", "");
        TransactionXML = TransactionXML.Replace("utf-8", "");
        xmlDoc.LoadXml(TransactionXML);

        // Get the bytes
        xmlStream = new System.IO.MemoryStream(enc.GetBytes(xmlDoc.OuterXml), true);

        // Load Xpath document
        System.Xml.XPath.XPathDocument xp = new System.Xml.XPath.XPathDocument(xmlStream);

        // Perform Transform
        xsl.Transform(xp, null, writer);
        Response.Write(writer.ToString());