Julian Cheyssial blogs (amongst other things) on xslt and custom web controls. I have to admit my knowledge on xslt is somewhat theoretical. Two main reasons keep me from using it with asp.net. First of all it is yet another language and can look far too much like classical asp. Second is that is does not have a visual designers, it's always some kind of surprise to see what the result looks like. My way of displaying the contents of a XML document is treating the XML as a XML(data)document with a (inferred) schema (xsd). Vs.net can generate a DataSet component on that. In the webform designer I bind individual controls to individual members of the dataset. Working this way gives me far more (and easier) control over the layout. The compiler will check bindings as well as logic instead of the xslt processor bumping into an error at runtime.
When it comes to custom controls Julian mentions the bible by Nikhil Kothari and Vandana Datye (don't forget her). A very good book indeed. But it is huge and could give the impression that creating custom controls is difficult. In fact it is (almost) a piece of cake. In an article coming soon (somewhere in a dnj queue at the moment, you'll have to ask Donny when it will be up) I will describe how to build a custom datalist. Over here I will take a first shot at custom controls, hoping too inspire some of you to start building them today.
In vs.net you build a custom component by creating a new project and choosing for a Web-control library. Vs.net will create the assembly with the skeleton of the first custom control. This control has a property text and a method Render. The text property is just a demo, but the render method is the most important method of any web control. A control can do anything at all but the only thing the browser will see is the html the control writes to the web-server's response. The generated control writes the text property to the output. The FCL XML-control writes the result of an xslt transformation to the output. The pseudo code for it's render method will be something like :
protected override void Render(HtmlTextWriter output)
{
// filename for the stylesheet and xmlfile used are constants here
// the real control has properties for them.
const String filename = "mydata.xml";
const String stylesheet = "myStyleSheet.xsl";
System.Xml.Xsl.XslTransform xslt = new System.Xml.Xsl.XslTransform();
xslt.Load(stylesheet);
System.Xml.XPath.XPathDocument xpathdocument = new System.Xml.XPath.XPathDocument(filename);
xslt.Transform(xpathdocument, null, output, null);
}
And this covers the essence of a custom control which is using xsl internally. As you see building custom controls is no rocket science. It takes just a few lines to do a traditional transform. In the code you can add your own functionality at several places. How and what is up to you own analysis and imagination.
Blog on,
Peter