Skip to content
Browse files

cleaner code

  • Loading branch information...
1 parent 233ddeb commit 3f8b0c5ad246364361879c21036266132009575b Francesco Lazzarino committed
Showing with 15 additions and 14 deletions.
  1. +15 −14 bin/validate.rb
View
29 bin/validate.rb
@@ -6,31 +6,32 @@
include LibXML
include LibXSLT
-ISO_IMPL_DIR='iso_impl'
-ISO_FILES = [ 'iso_dsdl_include.xsl',
- 'iso_abstract_expand.xsl',
- 'iso_svrl.xsl' ]
+ISO_IMPL_DIR = 'iso_impl'
+ISO_FILES = [ 'iso_dsdl_include.xsl',
+ 'iso_abstract_expand.xsl',
+ 'iso_svrl.xsl' ]
+# Tell the parse to remember the line numbers for each node
XML::Parser::default_line_numbers = true
+
+# Get sch and xml from command line
+schema_doc = XML::Document.file ARGV[0]
instance_doc = XML::Document.file ARGV[1]
# Compile schematron into xsl
-instance_doc = XML::Document.file ARGV[1]
-schema_doc = XML::Document.file ARGV[0]
+validator_xsl = Dir.chdir ISO_IMPL_DIR do
-validator = Dir.chdir ISO_IMPL_DIR do
-
- v = ISO_FILES.inject(schema_doc) do |stage,file|
+ xforms = ISO_FILES.map do |file|
doc = XML::Document.file file
- stylesheet = XSLT::Stylesheet.new doc
- stylesheet.apply stage
+ xsl = XSLT::Stylesheet.new doc
end
-
- XSLT::Stylesheet.new v
+ validator_doc = xforms.inject(schema_doc) { |xml, xsl| xsl.apply xml }
+ XSLT::Stylesheet.new validator_doc
end
-results_doc = validator.apply instance_doc
+# Validate the xml with the
+results_doc = validator_xsl.apply instance_doc
errors = []
results_doc.root.find('//svrl:failed-assert', 'svrl' => 'http://purl.oclc.org/dsdl/svrl').each do |assert|

0 comments on commit 3f8b0c5

Please sign in to comment.
Something went wrong with that request. Please try again.