简体   繁体   English

如何使用XSL在部分视图中呈现XML文档?

[英]How to render the XML Document in partial view with XSL?

Please note, I have an XML file which contains such information to display into User. 请注意,我有一个XML文件,其中包含要显示给User的信息。 And I have got the XSL file which contains the style information of the Content to display. 而且我得到了XSL文件,其中包含要显示的内容的样式信息。

I wrote the following action in my controller to return the View which contains the XML file contents. 我在控制器中编写了以下操作,以返回包含XML文件内容的View。

public ActionResult GetError()
{
  XmlDocument xdoc=GetXMLError();
  return View(xdoc);
}

[#GetError.cshtml]
@model System.Xml.XmlDocument
@MvcHtmlString.Create(Model.InnerXml).ToHtmlString()

But the Screen renders the xml what it has retrieved as a String not a HTML String. 但是屏幕将它检索到的xml呈现为String而不是HTML String。 Which means its printing the xml what I sent. 这意味着它会打印我发送的xml。

I have also included the XSL file in Corresponding View Folder. 我还将XSL文件包含在相应的View Folder.

I have no clue of further proceedings. 我没有进一步诉讼的线索。

Could anyone help me to resolve this out to Render the XML in specified style format? 谁能帮我解决这个问题,以指定的样式格式呈现XML?

Finally I got the output. 终于我得到了输出。 I thank @sundar G for his comment. 我感谢@sundar G的评论。

I changed the controllers as below, 我如下更改了控制器,

public ActionResult GetError()
{
  XmlDocument xdoc=GetXMLError();
  XslCompiledTransform xsl = new XslCompiledTransform();
  xsl.Load(@"D:\Development\Test.xsl");
  XmlReader xReader = XmlReader.Create(new StringReader(xdoc.InnerXml));
  StringBuilder stringBuilder=new StringBuilder();
  XmlWriter xWriter=XmlWriter.Create(stringBuilder);
  xsl.Transform(xReader, xWriter);
  return View(stringBuilder);
}

And in the view. 并在视图中。

@model System.Text.StringBuilder
@MvcHtmlString.Create(Model.ToString())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM