I have run into this problem a few times in the past. My solutions always seem overly complicated. How can I go from an object to an XPathDocument in the least number of steps? In the past, I created a MemoryStream, but this solution always turns out to need a lot of massaging which results in ugly code.
What do you suggest?
static void Main(string[] args)
{
itemOrder order = GenerateTestItem();
XPathDocument doc = new XPathDocument(order);//wish it took the object directly...
XslTransform transform = new XslTransform();
transform.Load("Test.xslt");
XmlTextWriter writer = new XmlTextWriter("result.html",null);
transform.Transform(doc, null, writer);
Console.Write(writer);
writer.Close();
}
You can’t do it with XPathDocument since it expects Xml document as a storage.
You can implement underlying interface IXPathNavigable and corresponding XPathNavigator classes to walk over objects. Following article covers this approach: http://msdn.microsoft.com/en-us/library/ms950764.aspx. XslTransform have corresponding Transform method that you can use later to apply Xsl: http://msdn.microsoft.com/en-us/library/ms163484.aspx