views:

58

answers:

1

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) ));
A: 

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 
Henk Holterman