diff --git a/bin/validate2.rb b/bin/validate2.rb index b703a84..2647dba 100755 --- a/bin/validate2.rb +++ b/bin/validate2.rb @@ -1,24 +1,57 @@ #!/usr/bin/ruby require 'libxml' +require 'libxslt' include LibXML - -# TODO make the namespace prefixes transparant +include LibXSLT XML::Parser::default_line_numbers=true -results_doc = XML::Document.file('output.xml') -instance_doc = XML::Document.file('instances/Example2.xml') +def transform(stylesheet, instance) + + # Build the stylesheet + stylesheet = XSLT::Stylesheet.new case stylesheet + when LibXML::XML::Document + stylesheet + when String + XML::Document.file stylesheet + end + + # Transform the instance + stylesheet.apply case instance + when LibXML::XML::Document + instance + when String + XML::Document.file instance + end +end + +def validate(sch, instance) + p1 = transform 'iso_dsdl_include.xsl', sch + p2 = transform 'iso_abstract_expand.xsl', p1 + p3 = transform 'iso_svrl.xsl', p2 + transform p3, instance +end + +# TODO make the namespace prefixes transparant + +instance_doc = XML::Document.file '../instances/Example2.xml' +results_doc = validate '../sch/fda_sip.sch', instance_doc -locations = results_doc.root.find('//svrl:failed-assert').map do |assert| - i_node = instance_doc.root.find_first assert['location'] +errors = [] +results_doc.root.find('//svrl:failed-assert').each do |assert| + context = instance_doc.root.find_first assert['location'] assert.find('svrl:text/text()').each do |message| - puts '%s "%s" on line %d: %s' % [i_node.node_type_name, - i_node.name, - i_node.line_num, - message.content.strip] + errors << '%s "%s" on line %d: %s' % [ context.node_type_name, + context.name, + context.line_num, + message.content.strip ] end end + +errors.each do |error| + puts error +end diff --git a/instances/Example2.xml b/instances/Example2.xml index fdb343e..8df14fd 100644 --- a/instances/Example2.xml +++ b/instances/Example2.xml @@ -21,7 +21,7 @@ - +