Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Francesco Lazzarino
committed
Sep 24, 2008
1 parent
4e106a0
commit 9696b7e
Showing
2 changed files
with
44 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters