Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a more efficient way to transform an XDocument that already contains a reference to an XSLT?

I have an XML file that already contains a reference to an XSLT file.

I'm looking at converting this XML file, according to the referenced transformation rules, so that I can then create a nice PDF file.

It appears that I can perform the actual transform via System.Xml.Xsl.XslCompiledTransform, but it requires that I manually associate an XSLT before I perform the transform.

Based on what I've seen, I must now manually pull the XSLT reference from the XDocument (rough start below):

xmlDocument.Document.Nodes()
   .Where(n => n.NodeType == System.Xml.XmlNodeType.ProcessingInstruction)

However, since the XSLT is already referenced within the XML file itself, I assume I'm doing too much work, and there's a more efficient way to apply the transform.

Is there, or is this what one has to do?

like image 407
James Skemp Avatar asked Dec 01 '11 18:12

James Skemp


1 Answers

There is no more efficient way to do that. You have to retrieve href to xslt from your xml before transforming it.

Similar question here : XslTransform with xml-stylesheet

like image 61
Romain Meresse Avatar answered Sep 19 '22 13:09

Romain Meresse