C# XslCompiledTransform – output in form of POCO instead of Html

I am trying to read a xml file and insert its contents in a database. I ran into XSLT transformation and it is really fast and good. The following code works fine and the data is seen in the result.html

var settings = new XsltSettings(true, true); var xslt = new XslCompiledTransform(); xslt.Load("filename.xsl", settings, new XmlUrlResolver()); xslt.Transform("xmlfileName.xml", "result.html"); 

However I wanted to take the data from XML and insert it into a database.

Is it possible through XSLT transformation? Like rather than the output as HTML, is there a way to get this data in any other format, so that I can then pick it up and insert it into a database.

I know this can be done by xml deserialization, however I am wondering if this can be done through XSLT too. It will be really fast and cool!

Add Comment
1 Answer(s)

The main output format for XSLT 1 is XML so instead of HTML you can certainly create XML output (with the data you want). How to insert XML into a database is another topic.

XSLT 1 can also create plain text output so for some restricted uses where you have an existing API that expect CSV or a similar format you can of course also have the XSLT create that text format.

Using XSLT 3 as supported for the .NET framework by the .NET version of Saxon 9.9 or 9.8 can also create JSON as XdmMap or XdmArray and then convert it a .NET Dictionary for instance, see e.g. http://saxonica.com/html/documentation9.9/dotnetdoc/Saxon/Api/XdmMap.html and http://saxonica.com/html/documentation9.9/dotnetdoc/Saxon/Api/XdmMap.html#AsDictionary()

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.