schematron 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/validate CHANGED
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
+ require 'optparse'
3
4
  require 'libxml'
4
5
  require 'schematron'
5
6
 
6
7
  include LibXML
7
8
 
8
- if ARGV.size != 2
9
- $stderr.puts "usage: validate [schematron] [instance]"
10
- exit 1
11
- end
9
+
10
+ puts "Usage: validate [schematron] [instance]" if ARGV.size != 2
12
11
 
13
12
  # use the line numbers
14
13
  XML.default_line_numbers = true
data/bin/validate-sh ADDED
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+
3
+ my_schema=$1
4
+ my_document=$2
5
+
6
+ xsltproc iso_impl/iso_dsdl_include.xsl $my_schema | \
7
+ xsltproc iso_impl/iso_abstract_expand.xsl - | \
8
+ xsltproc iso_impl/iso_svrl.xsl - | \
9
+ xsltproc - $my_document
data/schematron.gemspec CHANGED
@@ -1,12 +1,14 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "schematron"
3
- spec.version = '0.0.0'
4
- spec.summary = "ISO Schematron Validation in ruby"
3
+ spec.version = '0.0.1'
4
+ spec.summary = "ISO Schematron Validation"
5
5
  spec.email = "flazzarino@gmail.com"
6
6
  spec.homepage = 'http://github.com/flazz/iso-schematron'
7
- rubyforge_project = "schematron"
8
7
  spec.authors = ["Francesco Lazzarino"]
8
+
9
9
  spec.files = ["Rakefile", "schematron.gemspec",
10
- "bin/validate", "lib/schematron.rb"]
10
+ "bin/validate",
11
+ "bin/validate-sh"]
12
+
11
13
  spec.has_rdoc = true
12
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schematron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Lazzarino
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-13 00:00:00 -04:00
12
+ date: 2009-05-22 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,7 +25,7 @@ files:
25
25
  - Rakefile
26
26
  - schematron.gemspec
27
27
  - bin/validate
28
- - lib/schematron.rb
28
+ - bin/validate-sh
29
29
  has_rdoc: true
30
30
  homepage: http://github.com/flazz/iso-schematron
31
31
  post_install_message:
@@ -51,6 +51,6 @@ rubyforge_project:
51
51
  rubygems_version: 1.3.1
52
52
  signing_key:
53
53
  specification_version: 2
54
- summary: ISO Schematron Validation in ruby
54
+ summary: ISO Schematron Validation
55
55
  test_files: []
56
56
 
data/lib/schematron.rb DELETED
@@ -1,67 +0,0 @@
1
- require 'libxml'
2
- require 'libxslt'
3
-
4
- module Schematron
5
-
6
- include LibXML
7
- include LibXSLT
8
-
9
- # The location of the ISO schematron implemtation lives
10
- ISO_IMPL_DIR = 'iso_impl'
11
-
12
- # The file names of the compilation stages
13
- ISO_FILES = [ 'iso_dsdl_include.xsl',
14
- 'iso_abstract_expand.xsl',
15
- 'iso_svrl.xsl' ]
16
-
17
- # Namespace prefix declarations for use in XPaths
18
- NS_PREFIXES = {
19
- 'svrl' => 'http://purl.oclc.org/dsdl/svrl'
20
- }
21
-
22
- class Schema
23
-
24
- def initialize(doc)
25
- @schema_doc = doc
26
- end
27
-
28
- def validate(instance_doc)
29
-
30
- # Compile schematron into xsl that maps to svrl
31
- xforms = ISO_FILES.map do |file|
32
-
33
- Dir.chdir(ISO_IMPL_DIR) do
34
- doc = XML::Document.file file
35
- LibXSLT::XSLT::Stylesheet.new doc
36
- end
37
-
38
- end
39
-
40
- validator_doc = xforms.inject(@schema_doc) { |xml, xsl| xsl.apply xml }
41
- validator_xsl = LibXSLT::XSLT::Stylesheet.new validator_doc
42
-
43
- # Validate the xml
44
- results_doc = validator_xsl.apply instance_doc
45
-
46
- # compile the errors
47
- results = []
48
- results_doc.root.find('//svrl:failed-assert', NS_PREFIXES).each do |assert|
49
- context = instance_doc.root.find_first assert['location']
50
-
51
- assert.find('svrl:text/text()', NS_PREFIXES).each do |message|
52
- results << {
53
- :type => context.node_type_name,
54
- :name => context.name,
55
- :line => context.line_num,
56
- :message => message.content.strip
57
- }
58
- end
59
-
60
- end
61
-
62
- results
63
- end
64
-
65
- end
66
-
67
- end