Skip to content

Commit

Permalink
niceley commented
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Lazzarino committed Sep 25, 2008
1 parent 3f8b0c5 commit ebc2bfd
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions bin/validate.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,46 +6,51 @@
include LibXML include LibXML
include LibXSLT include LibXSLT


# The location of the ISO schematron implemtation lives
ISO_IMPL_DIR = 'iso_impl' ISO_IMPL_DIR = 'iso_impl'

# The file names of the compilation stages
ISO_FILES = [ 'iso_dsdl_include.xsl', ISO_FILES = [ 'iso_dsdl_include.xsl',
'iso_abstract_expand.xsl', 'iso_abstract_expand.xsl',
'iso_svrl.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 # Tell the parse to remember the line numbers for each node
XML::Parser::default_line_numbers = true XML::Parser::default_line_numbers = true


# Get sch and xml from command line # Get sch and xml from command line
schema_doc = XML::Document.file ARGV[0] schema_doc = XML::Document.file ARGV[0]
instance_doc = XML::Document.file ARGV[1] instance_doc = XML::Document.file ARGV[1]


# Compile schematron into xsl # Compile schematron into xsl that maps to svrl
validator_xsl = Dir.chdir ISO_IMPL_DIR do xforms = ISO_FILES.map do |file|


xforms = ISO_FILES.map do |file| Dir.chdir(ISO_IMPL_DIR) do
doc = XML::Document.file file doc = XML::Document.file file
xsl = XSLT::Stylesheet.new doc XSLT::Stylesheet.new doc
end end


validator_doc = xforms.inject(schema_doc) { |xml, xsl| xsl.apply xml }
XSLT::Stylesheet.new validator_doc
end 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 results_doc = validator_xsl.apply instance_doc


errors = [] # Print the errors
results_doc.root.find('//svrl:failed-assert', 'svrl' => 'http://purl.oclc.org/dsdl/svrl').each do |assert| results_doc.root.find('//svrl:failed-assert', NS_PREFIXES).each do |assert|
context = instance_doc.root.find_first assert['location'] context = instance_doc.root.find_first assert['location']


assert.find('svrl:text/text()', 'svrl' => 'http://purl.oclc.org/dsdl/svrl').each do |message| assert.find('svrl:text/text()', NS_PREFIXES).each do |message|
errors << '%s "%s" on line %d: %s' % [ context.node_type_name, puts '%s "%s" on line %d: %s' % [ context.node_type_name,
context.name, context.name,
context.line_num, context.line_num,
message.content.strip ] message.content.strip ]
end end


end end

errors.each do |error|
puts error
end

0 comments on commit ebc2bfd

Please sign in to comment.