Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

niceley commented

  • Loading branch information...
commit ebc2bfdd3e4e3a980a0c757a03bda587166fd01f 1 parent 3f8b0c5
Francesco Lazzarino authored

Showing 1 changed file with 23 additions and 18 deletions. Show diff stats Hide diff stats

  1. +23 18 bin/validate.rb
41 bin/validate.rb
@@ -6,11 +6,19 @@
6 6 include LibXML
7 7 include LibXSLT
8 8
  9 +# The location of the ISO schematron implemtation lives
9 10 ISO_IMPL_DIR = 'iso_impl'
  11 +
  12 +# The file names of the compilation stages
10 13 ISO_FILES = [ 'iso_dsdl_include.xsl',
11 14 'iso_abstract_expand.xsl',
12 15 'iso_svrl.xsl' ]
13 16
  17 +# Namespace prefix declarations for use in XPaths
  18 +NS_PREFIXES = {
  19 + 'svrl' => 'http://purl.oclc.org/dsdl/svrl'
  20 +}
  21 +
14 22 # Tell the parse to remember the line numbers for each node
15 23 XML::Parser::default_line_numbers = true
16 24
@@ -18,34 +26,31 @@
18 26 schema_doc = XML::Document.file ARGV[0]
19 27 instance_doc = XML::Document.file ARGV[1]
20 28
21   -# Compile schematron into xsl
22   -validator_xsl = Dir.chdir ISO_IMPL_DIR do
  29 +# Compile schematron into xsl that maps to svrl
  30 +xforms = ISO_FILES.map do |file|
23 31
24   - xforms = ISO_FILES.map do |file|
  32 + Dir.chdir(ISO_IMPL_DIR) do
25 33 doc = XML::Document.file file
26   - xsl = XSLT::Stylesheet.new doc
  34 + XSLT::Stylesheet.new doc
27 35 end
28 36
29   - validator_doc = xforms.inject(schema_doc) { |xml, xsl| xsl.apply xml }
30   - XSLT::Stylesheet.new validator_doc
31 37 end
32 38
33   -# Validate the xml with the
  39 +validator_doc = xforms.inject(schema_doc) { |xml, xsl| xsl.apply xml }
  40 +validator_xsl = XSLT::Stylesheet.new validator_doc
  41 +
  42 +# Validate the xml
34 43 results_doc = validator_xsl.apply instance_doc
35 44
36   -errors = []
37   -results_doc.root.find('//svrl:failed-assert', 'svrl' => 'http://purl.oclc.org/dsdl/svrl').each do |assert|
  45 +# Print the errors
  46 +results_doc.root.find('//svrl:failed-assert', NS_PREFIXES).each do |assert|
38 47 context = instance_doc.root.find_first assert['location']
39 48
40   - assert.find('svrl:text/text()', 'svrl' => 'http://purl.oclc.org/dsdl/svrl').each do |message|
41   - errors << '%s "%s" on line %d: %s' % [ context.node_type_name,
42   - context.name,
43   - context.line_num,
44   - message.content.strip ]
  49 + assert.find('svrl:text/text()', NS_PREFIXES).each do |message|
  50 + puts '%s "%s" on line %d: %s' % [ context.node_type_name,
  51 + context.name,
  52 + context.line_num,
  53 + message.content.strip ]
45 54 end
46 55
47 56 end
48   -
49   -errors.each do |error|
50   - puts error
51   -end

0 comments on commit ebc2bfd

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