This blog is a great way to organize my thoughts and has some great sparring partners, special thanks to Joseph Cooney. It all started with an involuntary collision with xslt, after which I tried to get a better grab on xsl(t). After rereading my books on the subject (Dino Esposito's applied XML programming (MS-Press), and Dan Wahlin's XML for ASP.NET developers (Sams)) I'll try to summarize what I have learned.
Problem : Create an (XML) document out of an other XML-document.
Approach 1 : Use a XSL style-sheet.
An XSL stylesheet describes the layout of the output document. The stylesheet is composed of templates. When processing the input document the values of the document's nodes determine which template of the style sheet is used to transform the node. Selecting nodes is done in XPATH expressions, like MyDataSet/NortwindEmployees/Employee. The stylesheet and the the input document are processed by the XSLTransformer. To process multiple nodes XSLT has instructions like for-each, for conditional processing XSLT has instructions like if test and when. An XSLTransformer can be activated by IE which leads to a bang when it tries to transform an aspx page, which started my ramblings. According to Frans Bouma that is mainly due to the older XML engine of IE. The transformer can also be started from a .net application. The XML component uses it or you can program it using the System.Xml.Xsl.XslTransform class.
Approach 2 : Use a XMLdocument object
If you want to bypass XSLT you can approach in and output documents using the DOM (Document Object Model). The framework has the System.Xml.XmlDocument and the System.Xml.XmlDatadocument class. Objects of these classes can load an XML document, or another datasource, into memory. They provide a very rich programming interface to manipulate a document. A very interesting method is CreateNavigator(), the result of this method gives you the opportunity to use XPATH again to navigate through the (input) document.
Approach 3 : Use XQuery
This is a whole new ballgame. Xquery relates to XML as SQL relates to databases. Xquery has all the possibilities of XPATH and of XSLT, is predicted to swallow them, but is not available as an usable implementation yet.
In the first place I am an OOP programmer. In the early days of .net, coming from Delphi, I had been playing with the Delphi (t)XMLdocument wrapper class to catch XML datasets coming in over a web service. Which worked pretty well. Living in the .net world I am confronted with a lot more creatures of the xml family. Some, like xslt, scare me as they are somewhat difficult to catch. People rave about xsl(t), when specifying their delights they mainly mention the XPATH part of it. But XPATH is not limited to XSLT, in the .net framework it is also available when you're doing DOM-programing. And that's something I do understand, I'll use the second approach.
Blog on,
Peter