I am looking at a way to migrate the metadata from a spreadsheet into ISO 19139 compliant XML metadata documents for a collection of shapefiles. I can parse the data out of the spreadsheet into strings without issue however I am getting lost on how to take those strings and use them to populate the elements.
This example: http://pymotw.com/2/xml/etree/ElementTree/create.html covers most of what I want to do, however I would need to generate the tree beforehand based on the ISO 19139 schema. PyXB seems to have schema bundles for OpenGIS but I would like some insight on how to connect everything.
Best Answer
One way of doing it is to generate a really simple XML tree for each record in your spreadsheet, write an XSLT stylesheet to translate from your simple XML to ISO 19139, then use lxml.etree.XSLT to transform.
The major advantage of this is it keeps the complex iso19139 XML out of your python code which makes it much easier to debug. Some more info/tutorials on xslt here and here.
Here's some example code:
The 'test.xslt' stylesheet referred to in the above code is: