简体   繁体   English

使用XSL将XML文档渲染到HTML页面

[英]Render XML document with XSL to a HTML page

I have a xml document like below and I need to render it into HTML page. 我有一个如下所示的xml文档,我需要将其呈现为HTML页面。 When I browse the XML from IE the HTML is rendered as expected with styling. 当我从IE浏览XML时,HTML会以样式呈现。 If I load the xml document from c# code and pass to HTML page it just renders as plain text. 如果我从c#代码加载xml文档并传递到HTML页面,它将仅呈现为纯文本。 What am I missing here? 我在这里想念什么?

XML XML

<?xml-stylesheet type='text/xsl' href='xslsheet.xsl'?>
<Document xmlns="org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
....
</Document>

C# C#

XDocument doc = XDocument.Load(@"C\SampleDocument.xml");
      var result = doc.ToString();

Loading an XML document does just that - it loads the data. 加载XML文档就是这样做的-它加载数据。 It won't process a transform directive. 它不会处理转换指令。

To do that you need to do an XSLT Transform. 为此,您需要执行XSLT转换。 You can find the classes to do that on MSDN . 您可以在MSDN上找到实现此目的的类。

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

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