I want to transform a large xml file to sql statements with xslt. For example I have the author tag.
<author>Evans, Jim; Henderson, Mike; Coyier, Alan</author>
I have a column for last_name and first_name, so Evans, Henderson and Coyier should go to last_name and so on.
How can I pick them out of the tag and put it into sql statements!
Thanks in advance!
You can do it with xslt, but it’s not very pretty as you need to parse out the lastname/firstname pairs, and then the lastname – firstname yourself. This is done through recursion.
In the same xslt you can generate SQL statements from it, but again this is not painless as you have to escape any literal string delimiters, for example,
O'Hanlonmust become the SQL string literal'O''Hanlon'.Again, this is done with recursion.
This is an example that is fully functional:
with your input:
This gives me this output:
If you need to do a lot of XML munging and inserting it into databases, I can recommend using a tool like kettle, aka. pentaho data integration. It has many steps that you can use to process data, and out-of-the-box connectivity for more than 30 databases. It’s free, and easy to install. get it here:
http://sourceforge.net/projects/pentaho/files/Data%20Integration/