Saturday, January 1, 2011

Taking csv turning it into xml with muenchian grouping

This task was a bit bigger than I anticipated when I offered to help a friend out with this.

First off a mate and I did the solution manually by importing the csv file into a access database then exporting it out to xml. From there the solution involved putting the xml onto a sharepoint site so it could be nicely presented and rendered with our xslt presentation file. This didn't deal with the fact that there was a lot of duplication and there needed to be some sort of grouping in the xml, as since the version of sharepoint we were working with was only capable of handling xslt 1.0 there was another set of challenges on our hands.

Mate has some experience in xslt and has added some elegant jquery into the mix as well, which makes for a very nice looking page.

Back to automating the csv to xml conversion. First I wrote a basic script to open up an access database then I created a form with three buttons on it, eventually these were automated as click events but first we had to write the code.

The first button was the import, which imported the csv file which was saved to a document store in sharepoint. Once that was retrieved it was written to a table, this was helped out with a schema file of what the headers names are and how to import the file i.e. with indexing, headers, table name etc. The second button was the exporting of the data, this was easy enough as their is an ExportXML function in vba with parameters this was fairly easy. I could of put the third button into the functionality of the second export button, but the ExportXML looks like it can accommodate the use of a transform method, but upon using this and searching the net did not find anyone who had successfully utilized this method to date. So the third button is the grouping or transforming the xml file and writing it back to the sharepoint document store so it can be rendered by the xslt file in sharepoint. You may ask why I didn't put the two xslt files together, well I tried this, but there was too much functionality already in the final xslt file, and it felt like the final xslt was more for presentation whereas the grouping should be done before it gets to this stage. So the third button imports the xml that the second button created and does a transform method using muenchian grouping, then writes this back to original xml stored in sharepoint.

No comments:

Post a Comment