askjhx 2014-04-08 05:52 采纳率: 0%
浏览 1905

.net xslt得到转换的html

xslt转换后一定要生成一个html的文件吗 ?我想在后台将转换好的xml innerHTML的方式动态的展示在前台页面 ,应该怎么得到转换的字符串呢 ?

  • 写回答

1条回答 默认 最新

  • askjhx 2014-04-08 06:10
    关注

    已经知道答案了可以使用如下代码:

            XslCompiledTransform xslFile = new XslCompiledTransform();
            xslFile.Load(Server.MapPath("") + "/Template/SimplenessView.xsl");
            XmlDocument xmlFile = new XmlDocument();
            xmlFile.Load(Server.MapPath("") + "/Template/QBQuestion.XML");
    
            StringWriter transWrite = new StringWriter();
            xslFile.Transform(xmlFile.CreateNavigator(), new XsltArgumentList(), transWrite);
    
            this.form1.InnerHtml = transWrite.ToString();
    

    如果需要输出为文件的话可以使用如下代码 ,希望能帮助到有同样疑惑的人 !

            XslCompiledTransform xslFile = new XslCompiledTransform();
            xslFile.Load(Server.MapPath("") + "/Template/SimplenessView.xsl");
            XmlDocument xmlFile = new XmlDocument();
            xmlFile.Load(Server.MapPath("") + "/Template/QBQuestion.XML");
    
            string htmPath = Server.MapPath("XsltHtml.htm");
    
            using (StreamWriter sw = new StreamWriter(htmPath, false,Encoding.Default))
            {
                xslFile.Transform(xmlFile, null, sw);
                sw.Flush();
                sw.Close();
                sw.Dispose();
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置