我创建了一个 XML 文档,并希望获得对 XSLT 文件的引用。
//<?xml-stylesheet type="text/xsl" href="OBReport.xslt"?>
到此 XML 生成:
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 X处理指令 https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xprocessinginstruction?view=netframework-4.7.1元素。
不是您的 XElement(它可以用作文档,但有限制),而是一个信封X文档 https://learn.microsoft.com/en-us/dotnet/standard/linq/xdocument-class-overview。所以,在你的代码之后:
XElement body = ...; // root XElement from your Linq statement
XDocument doc = new XDocument(
new XProcessingInstruction("xml-stylesheet", "type='text/xsl' ref='hello.xsl'"),
body);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)