source: TI01-discovery-Ingest/trunk/v4.3.0/ingestAutomation-upgrade/OAIBatch/schematronValidateScript.py @ 7957

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery-Ingest/trunk/v4.3.0/ingestAutomation-upgrade/OAIBatch/schematronValidateScript.py@7957
Revision 7957, 1.4 KB checked in by sdonegan, 8 years ago (diff)

This seems to work..

Line 
1from lxml import etree
2import sys,pdb
3
4#Simple script to provide XSLT transform sequence for schematron validation of NERC metadata
5
6#NOTE - uses lxml .. which extends Elementree..
7
8#assumes ISO stylesheets in same dir
9
10schematron = sys.argv[1]
11xmlToValidate = sys.argv[2]
12reportFile = sys.argv[3]
13
14#1. Transformn the sch file
15isoAbstractExpand = etree.parse('iso_abstract_expand.xsl')
16isoAbstractExpandTransform = etree.XSLT(isoAbstractExpand)
17originalSchematron = etree.parse(schematron)
18intermediate = isoAbstractExpandTransform(originalSchematron)
19
20#2. Transform the intermediate schema stylesheet with the iso svrl xslt
21isoSvrlforXslt = etree.parse('iso_svrl_for_xslt1.xsl')
22isoSvrlforXsltTransform = etree.XSLT(isoSvrlforXslt)
23theSchemaXsl = isoSvrlforXsltTransform(intermediate)
24
25#3. Transform the metadata XML using the generated schema from 2.
26xml = etree.parse(xmlToValidate)
27theSchemaXslTransform = etree.XSLT(theSchemaXsl)
28rawReport = theSchemaXslTransform(xml)
29
30
31#4. Render the result into a more human readable validation report using
32svrlReportTxt = etree.parse('SvrlReportText.xslt')
33svrlReportTxtTransform = etree.XSLT(svrlReportTxt)
34textReport = str(svrlReportTxtTransform(rawReport))
35
36#5. Write validation report
37outputFile = open(reportFile,"w")
38outputFile.write(textReport)
39outputFile.close()
40
41print "\nCompleted validation\n"
42
Note: See TracBrowser for help on using the repository browser.