Rambling thoughts and such like

Hello and welcome to the CogBlog. Here you'll find the (mostly) informative ramblings of the CogWorks staff on life, the Universe and Everything.

Subscribe to the RSS feed

Dataset to xpath

Just a quick tip for all you xslt cowboys.  I am currently working on an existing Umbraco installation. This site utilises webservices that return datasets.  The display of data has been done using .net usercontrols that make calls to the webservices, unfortunately for me alot of the layout has been done with codebehinds and stringbuilder.

The client wanted new subsites with different layout, so rather than hacking around with the existing usercontrols I decided to use xslt macros instead this gives me greater flexilbity to customise layout without having to also rebuild and deploy dlls.

As all you umbraco gurus know to use custom third party data in umbraco xslts you need to write xslt extensions and provided your method returns XPathNodeIterator it will all work.

So at first I was going to just create a method that got the dataset from the webservice then read that into and xml document then return XPathNodeIterator from the xml document.  However I did a quick google and found DataSetNavigator so instead I created an extension method that looks like

public static XPathNodeIterator CreateNavigatorOnDataSet(this DataSet ds)

{

var nav = new DataSetNavigator(ds);                  return nav.CreateNavigator().Select("/");

}

and my xslt extension method looks like

public static XPathNodeIterator GetPracticePeopleXml()

{

DataSet people = WebHelper.GetPracticePeople();

return people.CreateNavigatorOnDataSet();

}

2 comments for “Dataset to xpath”

  1. Posted 18 February 2011 at 09:56:37

    Thanks Ismail for the Tweet - that is exactly the solution for a problem I am working on today too :D and the person who was going to come and help me has cancelled :-$ so thank you for sharing

  2. Posted 18 February 2011 at 11:00:19

    Cool - very good, resulting in a clean interface. Bookmarked :-)

Post a comment

Back to top