添加样式表引用XML文档中的LINQ? [英] Add Stylesheet reference to XML Document in Linq?
本文介绍了添加样式表引用XML文档中的LINQ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建一个XML文档,并希望有一个参考的XSLT文件。
//<?xml样式表的类型=文/ XSL的href =OBReport.xslt>
此XML生成:
的XElement XML =新的XElement(ReportedOn
从分升EL.DocumentLog.ToList()
加盟澳中EL.Organization
在dl.OrganizationID等于o.OrganizationId
其中,dl.ActionDate> = stDate和放大器;
dl.ActionDate< = enDate
排序依据dl.DefendantName,dl.DocumentName
选择新的XElement(人,
新XAttribute(documentName,dl.DocumentName)
新的XElement(defendantName,dl.DefendantName)
新的XElement(actionDate,dl.ActionDate.ToString()),
新的XElement(的startDate,dl.StartDate.ToString()),
新的XElement(结束日期,dl.EndDate.ToString()),
新的XElement(单位名称,o.OrganizationName)));
解决方案
添加一个 XProcessingInstruction 元素。
,而不是你的XElement(这是草率的,作为根用户使用),但是到了的XDocument。所以,在你的code:
VAR DOC =新的XDocument(新XProcessingInstruction(
xml样式表,
类型=文/ XSLHREF ='hello.xsl'),
XML); //根的XElement从LINQ的声明
I create an XML Doc and wanted have a reference to the XSLT file.
//<?xml-stylesheet type="text/xsl" href="OBReport.xslt"?>
to this XML generation:
XElement xml = new XElement("ReportedOn",
from dl in EL.DocumentLog.ToList()
join o in EL.Organization
on dl.OrganizationID equals o.OrganizationId
where dl.ActionDate >= stDate &
dl.ActionDate <= enDate
orderby dl.DefendantName, dl.DocumentName
select new XElement("persons",
new XAttribute("documentName", dl.DocumentName),
new XElement("defendantName", dl.DefendantName),
new XElement("actionDate", dl.ActionDate.ToString()),
new XElement("startDate", dl.StartDate.ToString()),
new XElement("endDate", dl.EndDate.ToString()),
new XElement("organizationName" , o.OrganizationName) ));
解决方案
Add an XProcessingInstruction element.
And not to your XElement (which is sloppy to use as root) but to a XDocument. So, after your code:
var doc = new XDocument(new XProcessingInstruction(
"xml-stylesheet",
"type='text/xsl' href='hello.xsl'"),
xml); // root-XElement from your Linq statement
这篇关于添加样式表引用XML文档中的LINQ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文