Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

niceley commented

  • Loading branch information...
commit ebc2bfdd3e4e3a980a0c757a03bda587166fd01f 1 parent 3f8b0c5
Francesco Lazzarino authored
Showing with 23 additions and 18 deletions.
  1. +23 −18 bin/validate.rb
View
41 bin/validate.rb
@@ -6,11 +6,19 @@
include LibXML
include LibXSLT
+# The location of the ISO schematron implemtation lives
ISO_IMPL_DIR = 'iso_impl'
+
+# The file names of the compilation stages
ISO_FILES = [ 'iso_dsdl_include.xsl',
'iso_abstract_expand.xsl',
'iso_svrl.xsl' ]
+# Namespace prefix declarations for use in XPaths
+NS_PREFIXES = {
+ 'svrl' => 'http://purl.oclc.org/dsdl/svrl'
+}
+
# Tell the parse to remember the line numbers for each node
XML::Parser::default_line_numbers = true
@@ -18,34 +26,31 @@
schema_doc = XML::Document.file ARGV[0]
instance_doc = XML::Document.file ARGV[1]
-# Compile schematron into xsl
-validator_xsl = Dir.chdir ISO_IMPL_DIR do
+# Compile schematron into xsl that maps to svrl
+xforms = ISO_FILES.map do |file|
- xforms = ISO_FILES.map do |file|
+ Dir.chdir(ISO_IMPL_DIR) do
doc = XML::Document.file file
- xsl = XSLT::Stylesheet.new doc
+ XSLT::Stylesheet.new doc
end
- validator_doc = xforms.inject(schema_doc) { |xml, xsl| xsl.apply xml }
- XSLT::Stylesheet.new validator_doc
end
-# Validate the xml with the
+validator_doc = xforms.inject(schema_doc) { |xml, xsl| xsl.apply xml }
+validator_xsl = XSLT::Stylesheet.new validator_doc
+
+# Validate the xml
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|
+# Print the errors
+results_doc.root.find('//svrl:failed-assert', NS_PREFIXES).each do |assert|
context = instance_doc.root.find_first assert['location']
- assert.find('svrl:text/text()', 'svrl' => 'http://purl.oclc.org/dsdl/svrl').each do |message|
- errors << '%s "%s" on line %d: %s' % [ context.node_type_name,
- context.name,
- context.line_num,
- message.content.strip ]
+ assert.find('svrl:text/text()', NS_PREFIXES).each do |message|
+ puts '%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
Please sign in to comment.
Something went wrong with that request. Please try again.