加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

.net – 在Linq中添加样式表对XML文档的引用?

发布时间:2020-12-16 07:50:09 所属栏目:百科 来源:网络整理
导读:我创建了一个 XML Doc,并希望引用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 equal
我创建了一个 XML Doc,并希望引用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) ));
添加 XProcessingInstruction元素.

而不是你的XElement(可以用作文档,但有限制),而不是包围XDocument.所以,在您的代码之后:

XElement body = ...; // root XElement from your Linq statement 
 XDocument doc = new XDocument(
      new XProcessingInstruction("xml-stylesheet","type='text/xsl' ref='hello.xsl'"),body);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读