schematron 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +21 -0
- data/README +3 -0
- data/bin/{validate → stron} +0 -0
- data/iso_impl/iso_abstract_expand.xsl +295 -0
- data/iso_impl/iso_dsdl_include.xsl +989 -0
- data/iso_impl/iso_schematron_skeleton_for_saxon.xsl +1884 -0
- data/iso_impl/iso_schematron_skeleton_for_xslt1.xsl +1749 -0
- data/iso_impl/iso_schematron_text.xsl +126 -0
- data/iso_impl/iso_svrl.xsl +583 -0
- data/lib/schematron.rb +67 -0
- data/schematron.gemspec +27 -4
- data/spec/command_spec.rb +22 -0
- data/spec/feature_requests_spec.rb +5 -0
- data/spec/instances/daitss-sip/Example1.xml +37 -0
- data/spec/instances/daitss-sip/Example2.xml +68 -0
- data/spec/instances/premis-in-mets/bad.xml +102 -0
- data/spec/instances/premis-in-mets/good.xml +103 -0
- data/spec/schema/fda_sip.sch +72 -0
- data/spec/schema/pim.sch +27 -0
- data/spec/schema_spec.rb +43 -0
- data/spec/spec_helper.rb +1 -0
- metadata +28 -6
- data/bin/validate-sh +0 -9
@@ -0,0 +1,583 @@
|
|
1
|
+
<?xml version="1.0" ?>
|
2
|
+
<!--
|
3
|
+
ISO_SVRL.xsl
|
4
|
+
|
5
|
+
Implementation of Schematron Validation Report Language from ISO Schematron
|
6
|
+
ISO/IEC 19757 Document Schema Definition Languages (DSDL)
|
7
|
+
Part 3: Rule-based validation Schematron
|
8
|
+
Annex D: Schematron Validation Report Language
|
9
|
+
|
10
|
+
This ISO Standard is available free as a Publicly Available Specification in PDF from ISO.
|
11
|
+
Also see www.schematron.com for drafts and other information.
|
12
|
+
|
13
|
+
This implementation of SVRL is designed to run with the "Skeleton" implementation
|
14
|
+
of Schematron which Oliver Becker devised. The skeleton code provides a
|
15
|
+
Schematron implementation but with named templates for handling all output;
|
16
|
+
the skeleton provides basic templates for output using this API, but client
|
17
|
+
validators can be written to import the skeleton and override the default output
|
18
|
+
templates as required. (In order to understand this, you must understand that
|
19
|
+
a named template such as "process-assert" in this XSLT stylesheet overrides and
|
20
|
+
replaces any template with the same name in the imported skeleton XSLT file.)
|
21
|
+
|
22
|
+
The other important thing to understand in this code is that there are different
|
23
|
+
versions of the Schematron skeleton. These track the development of Schematron through
|
24
|
+
Schematron 1.5, Schematron 1.6 and now ISO Schematron. One only skeleton must be
|
25
|
+
imported. The code has templates for the different skeletons commented out for
|
26
|
+
convenience. ISO Schematron has a different namespace than Schematron 1.5 and 1.6;
|
27
|
+
so the ISO Schematron skeleton has been written itself with an optional import
|
28
|
+
statement to in turn import the Schematron 1.6 skeleton. This will allow you to
|
29
|
+
validate with schemas from either namespace.
|
30
|
+
|
31
|
+
|
32
|
+
History:
|
33
|
+
2008-08-11
|
34
|
+
* RJ Fix attribute/@select which saxon allows in XSLT 1
|
35
|
+
2008-08-07
|
36
|
+
* RJ Add output-encoding attribute to specify final encoding to use
|
37
|
+
* Alter allow-foreign functionality so that Schematron span, emph and dir elements make
|
38
|
+
it to the output, for better formatting and because span can be used to mark up
|
39
|
+
semantically interesting information embedded in diagnostics, which reduces the
|
40
|
+
need to extend SVRL itself
|
41
|
+
* Diagnostic-reference had an invalid attribute @id that duplicated @diagnostic: removed
|
42
|
+
2008-08-06
|
43
|
+
* RJ Fix invalid output: svrl:diagnostic-reference is not contained in an svrl:text
|
44
|
+
* Output comment to SVRL file giving filename if available (from command-line parameter)
|
45
|
+
2008-08-04
|
46
|
+
* RJ move sch: prefix to schold: prefix to prevent confusion (we want people to
|
47
|
+
be able to switch from old namespace to new namespace without changing the
|
48
|
+
sch: prefix, so it is better to keep that prefix completely out of the XSLT)
|
49
|
+
* Extra signature fixes (PH)
|
50
|
+
2008-08-03
|
51
|
+
* Repair missing class parameter on process-p
|
52
|
+
2008-07-31
|
53
|
+
* Update skeleton names
|
54
|
+
2007-04-03
|
55
|
+
* Add option generate-fired-rule (RG)
|
56
|
+
2007-02-07
|
57
|
+
* Prefer true|false for parameters. But allow yes|no on some old for compatability
|
58
|
+
* DP Diagnostics output to svrl:text. Diagnosis put out after assertion text.
|
59
|
+
* Removed non-SVRL elements and attributes: better handled as an extra layer that invokes this one
|
60
|
+
* Add more formal parameters
|
61
|
+
* Correct confusion between $schemaVersion and $queryBinding
|
62
|
+
* Indent
|
63
|
+
* Validate against RNC schemas for XSLT 1 and 2 (with regex tests removed)
|
64
|
+
* Validate output with UniversalTest.sch against RNC schema for ISO SVRL
|
65
|
+
|
66
|
+
2007-02-01
|
67
|
+
* DP. Update formal parameters of overriding named templates to handle more attributes.
|
68
|
+
* DP. Refactor handling of rich and linkable parameters to a named template.
|
69
|
+
|
70
|
+
2007-01-22
|
71
|
+
* DP change svrl:ns to svrl:ns-in-attribute-value
|
72
|
+
* Change default when no queryBinding from "unknown" to "xslt"
|
73
|
+
|
74
|
+
2007-01-18:
|
75
|
+
* Improve documentation
|
76
|
+
* KH Add command-line options to generate paths or not
|
77
|
+
* Use axsl:attribute rather than xsl:attribute to shut XSLT2 up
|
78
|
+
* Add extra command-line options to pass to the iso_schematron_skeleton
|
79
|
+
|
80
|
+
2006-12-01: iso_svrl.xsl Rick Jelliffe,
|
81
|
+
* update namespace,
|
82
|
+
* update phase handling,
|
83
|
+
* add flag param to process-assert and process-report & @ flag on output
|
84
|
+
|
85
|
+
2001: Conformance1-5.xsl Rick Jelliffe,
|
86
|
+
* Created, using the skeleton code contributed by Oliver Becker
|
87
|
+
-->
|
88
|
+
<!--
|
89
|
+
Derived from Conformance1-5.xsl.
|
90
|
+
|
91
|
+
Copyright (c) 2001, 2006 Rick Jelliffe and Academia Sinica Computing Center, Taiwan
|
92
|
+
|
93
|
+
This software is provided 'as-is', without any express or implied warranty.
|
94
|
+
In no event will the authors be held liable for any damages arising from
|
95
|
+
the use of this software.
|
96
|
+
|
97
|
+
Permission is granted to anyone to use this software for any purpose,
|
98
|
+
including commercial applications, and to alter it and redistribute it freely,
|
99
|
+
subject to the following restrictions:
|
100
|
+
|
101
|
+
1. The origin of this software must not be misrepresented; you must not claim
|
102
|
+
that you wrote the original software. If you use this software in a product,
|
103
|
+
an acknowledgment in the product documentation would be appreciated but is
|
104
|
+
not required.
|
105
|
+
|
106
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
107
|
+
misrepresented as being the original software.
|
108
|
+
|
109
|
+
3. This notice may not be removed or altered from any source distribution.
|
110
|
+
-->
|
111
|
+
|
112
|
+
<!-- Ideas nabbed from schematrons by Francis N., Miloslav N. and David C. -->
|
113
|
+
|
114
|
+
<!-- The command-line parameters are:
|
115
|
+
phase NMTOKEN | "#ALL" (default) Select the phase for validation
|
116
|
+
allow-foreign "true" | "false" (default) Pass non-Schematron elements to the generated stylesheet
|
117
|
+
diagnose= true | false|yes|no Add the diagnostics to the assertion test in reports (yes|no are obsolete)
|
118
|
+
generate-paths=true|false|yes|no generate the @location attribute with XPaths (yes|no are obsolete)
|
119
|
+
sch.exslt.imports semi-colon delimited string of filenames for some EXSLT implementations
|
120
|
+
optimize "visit-no-attributes" Use only when the schema has no attributes as the context nodes
|
121
|
+
generate-fired-rule "true"(default) | "false" Generate fired-rule elements
|
122
|
+
|
123
|
+
-->
|
124
|
+
|
125
|
+
<xsl:stylesheet
|
126
|
+
version="1.0"
|
127
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
128
|
+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
129
|
+
xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"
|
130
|
+
xmlns:schold="http://www.ascc.net/xml/schematron"
|
131
|
+
xmlns:iso="http://purl.oclc.org/dsdl/schematron"
|
132
|
+
xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
|
133
|
+
>
|
134
|
+
|
135
|
+
<!-- Select the import statement and adjust the path as
|
136
|
+
necessary for your system.
|
137
|
+
-->
|
138
|
+
<xsl:import href="iso_schematron_skeleton_for_xslt1.xsl"/>
|
139
|
+
<!--
|
140
|
+
<xsl:import href="iso_schematron_skeleton_for_saxon.xsl"/>
|
141
|
+
|
142
|
+
<xsl:import href="iso_schematron_skeleton.xsl"/>
|
143
|
+
<xsl:import href="skeleton1-5.xsl"/>
|
144
|
+
<xsl:import href="skeleton1-6.xsl"/>
|
145
|
+
-->
|
146
|
+
|
147
|
+
<xsl:param name="diagnose" >true</xsl:param>
|
148
|
+
<xsl:param name="phase" >
|
149
|
+
<xsl:choose>
|
150
|
+
<!-- Handle Schematron 1.5 and 1.6 phases -->
|
151
|
+
<xsl:when test="//schold:schema/@defaultPhase">
|
152
|
+
<xsl:value-of select="//schold:schema/@defaultPhase"/>
|
153
|
+
</xsl:when>
|
154
|
+
<!-- Handle ISO Schematron phases -->
|
155
|
+
<xsl:when test="//iso:schema/@defaultPhase">
|
156
|
+
<xsl:value-of select="//iso:schema/@defaultPhase"/>
|
157
|
+
</xsl:when>
|
158
|
+
<xsl:otherwise>#ALL</xsl:otherwise>
|
159
|
+
</xsl:choose>
|
160
|
+
</xsl:param>
|
161
|
+
<xsl:param name="allow-foreign" >false</xsl:param>
|
162
|
+
<xsl:param name="generate-paths" >true</xsl:param>
|
163
|
+
<xsl:param name="generate-fired-rule" >true</xsl:param>
|
164
|
+
<xsl:param name="optimize"/>
|
165
|
+
|
166
|
+
<xsl:param name="output-encoding" ></xsl:param>
|
167
|
+
|
168
|
+
<!-- e.g. saxon file.xml file.xsl "sch.exslt.imports=.../string.xsl;.../math.xsl" -->
|
169
|
+
<xsl:param name="sch.exslt.imports" />
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
<!-- Experimental: If this file called, then must be generating svrl -->
|
174
|
+
<xsl:variable name="svrlTest" select="true()" />
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
<!-- ================================================================ -->
|
179
|
+
|
180
|
+
<xsl:template name="process-prolog">
|
181
|
+
<axsl:output method="xml" omit-xml-declaration="no" standalone="yes"
|
182
|
+
indent="yes">
|
183
|
+
<xsl:if test=" string-length($output-encoding) > 0">
|
184
|
+
<xsl:attribute name="encoding"><xsl:value-of select=" $output-encoding" /></xsl:attribute>
|
185
|
+
</xsl:if>
|
186
|
+
</axsl:output>
|
187
|
+
|
188
|
+
</xsl:template>
|
189
|
+
|
190
|
+
<!-- Overrides skeleton.xsl -->
|
191
|
+
<xsl:template name="process-root">
|
192
|
+
<xsl:param name="title"/>
|
193
|
+
<xsl:param name="contents" />
|
194
|
+
<xsl:param name="queryBinding" >xslt1</xsl:param>
|
195
|
+
<xsl:param name="schemaVersion" />
|
196
|
+
<xsl:param name="id" />
|
197
|
+
<xsl:param name="version"/>
|
198
|
+
<!-- "Rich" parameters -->
|
199
|
+
<xsl:param name="fpi" />
|
200
|
+
<xsl:param name="icon" />
|
201
|
+
<xsl:param name="lang" />
|
202
|
+
<xsl:param name="see" />
|
203
|
+
<xsl:param name="space" />
|
204
|
+
|
205
|
+
<svrl:schematron-output title="{$title}" schemaVersion="{$schemaVersion}" >
|
206
|
+
<xsl:if test=" string-length( normalize-space( $phase )) > 0 and
|
207
|
+
not( normalize-space( $phase ) = '#ALL') ">
|
208
|
+
<axsl:attribute name="phase">
|
209
|
+
<xsl:value-of select=" $phase " />
|
210
|
+
</axsl:attribute>
|
211
|
+
</xsl:if>
|
212
|
+
<xsl:if test=" $allow-foreign = 'true'">
|
213
|
+
</xsl:if>
|
214
|
+
<xsl:if test=" $allow-foreign = 'true'">
|
215
|
+
|
216
|
+
<xsl:call-template name='richParms'>
|
217
|
+
<xsl:with-param name="fpi" select="$fpi" />
|
218
|
+
<xsl:with-param name="icon" select="$icon"/>
|
219
|
+
<xsl:with-param name="lang" select="$lang"/>
|
220
|
+
<xsl:with-param name="see" select="$see" />
|
221
|
+
<xsl:with-param name="space" select="$space" />
|
222
|
+
</xsl:call-template>
|
223
|
+
</xsl:if>
|
224
|
+
|
225
|
+
<axsl:comment><axsl:value-of select="$archiveDirParameter"/>  
|
226
|
+
<axsl:value-of select="$archiveNameParameter"/>  
|
227
|
+
<axsl:value-of select="$fileNameParameter"/>  
|
228
|
+
<axsl:value-of select="$fileDirParameter"/></axsl:comment>
|
229
|
+
|
230
|
+
|
231
|
+
<xsl:apply-templates mode="do-schema-p" />
|
232
|
+
<xsl:copy-of select="$contents" />
|
233
|
+
</svrl:schematron-output>
|
234
|
+
</xsl:template>
|
235
|
+
|
236
|
+
|
237
|
+
<xsl:template name="process-assert">
|
238
|
+
<xsl:param name="test"/>
|
239
|
+
<xsl:param name="diagnostics" />
|
240
|
+
<xsl:param name="id" />
|
241
|
+
<xsl:param name="flag" />
|
242
|
+
<!-- "Linkable" parameters -->
|
243
|
+
<xsl:param name="role"/>
|
244
|
+
<xsl:param name="subject"/>
|
245
|
+
<!-- "Rich" parameters -->
|
246
|
+
<xsl:param name="fpi" />
|
247
|
+
<xsl:param name="icon" />
|
248
|
+
<xsl:param name="lang" />
|
249
|
+
<xsl:param name="see" />
|
250
|
+
<xsl:param name="space" />
|
251
|
+
<svrl:failed-assert test="{$test}" >
|
252
|
+
<xsl:if test="string-length( $id ) > 0">
|
253
|
+
<axsl:attribute name="id">
|
254
|
+
<xsl:value-of select=" $id " />
|
255
|
+
</axsl:attribute>
|
256
|
+
</xsl:if>
|
257
|
+
<xsl:if test=" string-length( $flag ) > 0">
|
258
|
+
<axsl:attribute name="flag">
|
259
|
+
<xsl:value-of select=" $flag " />
|
260
|
+
</axsl:attribute>
|
261
|
+
</xsl:if>
|
262
|
+
<!-- Process rich attributes. -->
|
263
|
+
<xsl:call-template name="richParms">
|
264
|
+
<xsl:with-param name="fpi" select="$fpi"/>
|
265
|
+
<xsl:with-param name="icon" select="$icon"/>
|
266
|
+
<xsl:with-param name="lang" select="$lang"/>
|
267
|
+
<xsl:with-param name="see" select="$see" />
|
268
|
+
<xsl:with-param name="space" select="$space" />
|
269
|
+
</xsl:call-template>
|
270
|
+
<xsl:call-template name='linkableParms'>
|
271
|
+
<xsl:with-param name="role" select="$role" />
|
272
|
+
<xsl:with-param name="subject" select="$subject"/>
|
273
|
+
</xsl:call-template>
|
274
|
+
<xsl:if test=" $generate-paths = 'true' or $generate-paths= 'yes' ">
|
275
|
+
<!-- true/false is the new way -->
|
276
|
+
<axsl:attribute name="location">
|
277
|
+
<axsl:apply-templates select="." mode="schematron-get-full-path"/>
|
278
|
+
</axsl:attribute>
|
279
|
+
</xsl:if>
|
280
|
+
|
281
|
+
<svrl:text>
|
282
|
+
<xsl:apply-templates mode="text" />
|
283
|
+
|
284
|
+
</svrl:text>
|
285
|
+
<xsl:if test="$diagnose = 'yes' or $diagnose= 'true' ">
|
286
|
+
<!-- true/false is the new way -->
|
287
|
+
<xsl:call-template name="diagnosticsSplit">
|
288
|
+
<xsl:with-param name="str" select="$diagnostics"/>
|
289
|
+
</xsl:call-template>
|
290
|
+
</xsl:if>
|
291
|
+
</svrl:failed-assert>
|
292
|
+
</xsl:template>
|
293
|
+
|
294
|
+
<xsl:template name="process-report">
|
295
|
+
<xsl:param name="id"/>
|
296
|
+
<xsl:param name="test"/>
|
297
|
+
<xsl:param name="diagnostics"/>
|
298
|
+
<xsl:param name="flag" />
|
299
|
+
<!-- "Linkable" parameters -->
|
300
|
+
<xsl:param name="role"/>
|
301
|
+
<xsl:param name="subject"/>
|
302
|
+
<!-- "Rich" parameters -->
|
303
|
+
<xsl:param name="fpi" />
|
304
|
+
<xsl:param name="icon" />
|
305
|
+
<xsl:param name="lang" />
|
306
|
+
<xsl:param name="see" />
|
307
|
+
<xsl:param name="space" />
|
308
|
+
<svrl:successful-report test="{$test}" >
|
309
|
+
<xsl:if test=" string-length( $id ) > 0">
|
310
|
+
<axsl:attribute name="id">
|
311
|
+
<xsl:value-of select=" $id " />
|
312
|
+
</axsl:attribute>
|
313
|
+
</xsl:if>
|
314
|
+
<xsl:if test=" string-length( $flag ) > 0">
|
315
|
+
<axsl:attribute name="flag">
|
316
|
+
<xsl:value-of select=" $flag " />
|
317
|
+
</axsl:attribute>
|
318
|
+
</xsl:if>
|
319
|
+
|
320
|
+
<!-- Process rich attributes. -->
|
321
|
+
<xsl:call-template name="richParms">
|
322
|
+
<xsl:with-param name="fpi" select="$fpi"/>
|
323
|
+
<xsl:with-param name="icon" select="$icon"/>
|
324
|
+
<xsl:with-param name="lang" select="$lang"/>
|
325
|
+
<xsl:with-param name="see" select="$see" />
|
326
|
+
<xsl:with-param name="space" select="$space" />
|
327
|
+
</xsl:call-template>
|
328
|
+
<xsl:call-template name='linkableParms'>
|
329
|
+
<xsl:with-param name="role" select="$role" />
|
330
|
+
<xsl:with-param name="subject" select="$subject"/>
|
331
|
+
</xsl:call-template>
|
332
|
+
<xsl:if test=" $generate-paths = 'yes' or $generate-paths = 'true' ">
|
333
|
+
<!-- true/false is the new way -->
|
334
|
+
<axsl:attribute name="location">
|
335
|
+
<axsl:apply-templates select="." mode="schematron-get-full-path"/>
|
336
|
+
</axsl:attribute>
|
337
|
+
</xsl:if>
|
338
|
+
|
339
|
+
<svrl:text>
|
340
|
+
<xsl:apply-templates mode="text" />
|
341
|
+
|
342
|
+
</svrl:text>
|
343
|
+
<xsl:if test="$diagnose = 'yes' or $diagnose='true' ">
|
344
|
+
<!-- true/false is the new way -->
|
345
|
+
<xsl:call-template name="diagnosticsSplit">
|
346
|
+
<xsl:with-param name="str" select="$diagnostics"/>
|
347
|
+
</xsl:call-template>
|
348
|
+
</xsl:if>
|
349
|
+
</svrl:successful-report>
|
350
|
+
</xsl:template>
|
351
|
+
|
352
|
+
|
353
|
+
<!-- Overrides skeleton -->
|
354
|
+
<xsl:template name="process-dir" >
|
355
|
+
<xsl:param name="value" />
|
356
|
+
<xsl:choose>
|
357
|
+
<xsl:when test=" $allow-foreign = 'true'">
|
358
|
+
<xsl:copy-of select="."/>
|
359
|
+
</xsl:when>
|
360
|
+
|
361
|
+
<xsl:otherwise>
|
362
|
+
<!-- We generate too much whitespace rather than risking concatenation -->
|
363
|
+
<axsl:text> </axsl:text>
|
364
|
+
<xsl:apply-templates mode="inline-text"/>
|
365
|
+
<axsl:text> </axsl:text>
|
366
|
+
</xsl:otherwise>
|
367
|
+
</xsl:choose>
|
368
|
+
</xsl:template>
|
369
|
+
|
370
|
+
<xsl:template name="process-diagnostic">
|
371
|
+
<xsl:param name="id"/>
|
372
|
+
<!-- Rich parameters -->
|
373
|
+
<xsl:param name="fpi" />
|
374
|
+
<xsl:param name="icon" />
|
375
|
+
<xsl:param name="lang" />
|
376
|
+
<xsl:param name="see" />
|
377
|
+
<xsl:param name="space" />
|
378
|
+
<svrl:diagnostic-reference diagnostic="{$id}" >
|
379
|
+
|
380
|
+
<xsl:call-template name="richParms">
|
381
|
+
<xsl:with-param name="fpi" select="$fpi"/>
|
382
|
+
<xsl:with-param name="icon" select="$icon"/>
|
383
|
+
<xsl:with-param name="lang" select="$lang"/>
|
384
|
+
<xsl:with-param name="see" select="$see" />
|
385
|
+
<xsl:with-param name="space" select="$space" />
|
386
|
+
</xsl:call-template>
|
387
|
+
<xsl:text>
|
388
|
+
</xsl:text>
|
389
|
+
|
390
|
+
<xsl:apply-templates mode="text"/>
|
391
|
+
|
392
|
+
</svrl:diagnostic-reference>
|
393
|
+
</xsl:template>
|
394
|
+
|
395
|
+
|
396
|
+
<!-- Overrides skeleton -->
|
397
|
+
<xsl:template name="process-emph" >
|
398
|
+
<xsl:param name="class" />
|
399
|
+
<xsl:choose>
|
400
|
+
<xsl:when test=" $allow-foreign = 'true'">
|
401
|
+
<xsl:copy-of select="."/>
|
402
|
+
</xsl:when>
|
403
|
+
<xsl:otherwise>
|
404
|
+
<!-- We generate too much whitespace rather than risking concatenation -->
|
405
|
+
<axsl:text> </axsl:text>
|
406
|
+
<xsl:apply-templates mode="inline-text"/>
|
407
|
+
<axsl:text> </axsl:text>
|
408
|
+
</xsl:otherwise>
|
409
|
+
</xsl:choose>
|
410
|
+
</xsl:template>
|
411
|
+
|
412
|
+
<xsl:template name="process-rule">
|
413
|
+
<xsl:param name="id"/>
|
414
|
+
<xsl:param name="context"/>
|
415
|
+
<xsl:param name="flag"/>
|
416
|
+
<!-- "Linkable" parameters -->
|
417
|
+
<xsl:param name="role"/>
|
418
|
+
<xsl:param name="subject"/>
|
419
|
+
<!-- "Rich" parameters -->
|
420
|
+
<xsl:param name="fpi" />
|
421
|
+
<xsl:param name="icon" />
|
422
|
+
<xsl:param name="lang" />
|
423
|
+
<xsl:param name="see" />
|
424
|
+
<xsl:param name="space" />
|
425
|
+
<xsl:if test=" $generate-fired-rule = 'true'">
|
426
|
+
<svrl:fired-rule context="{$context}" >
|
427
|
+
<!-- Process rich attributes. -->
|
428
|
+
<xsl:call-template name="richParms">
|
429
|
+
<xsl:with-param name="fpi" select="$fpi"/>
|
430
|
+
<xsl:with-param name="icon" select="$icon"/>
|
431
|
+
<xsl:with-param name="lang" select="$lang"/>
|
432
|
+
<xsl:with-param name="see" select="$see" />
|
433
|
+
<xsl:with-param name="space" select="$space" />
|
434
|
+
</xsl:call-template>
|
435
|
+
<xsl:if test=" string( $id )">
|
436
|
+
<xsl:attribute name="id">
|
437
|
+
<xsl:value-of select=" $id " />
|
438
|
+
</xsl:attribute>
|
439
|
+
</xsl:if>
|
440
|
+
<xsl:if test=" string-length( $role ) > 0">
|
441
|
+
<xsl:attribute name="role">
|
442
|
+
<xsl:value-of select=" $role " />
|
443
|
+
</xsl:attribute>
|
444
|
+
</xsl:if>
|
445
|
+
</svrl:fired-rule>
|
446
|
+
</xsl:if>
|
447
|
+
</xsl:template>
|
448
|
+
|
449
|
+
<xsl:template name="process-ns">
|
450
|
+
<xsl:param name="prefix"/>
|
451
|
+
<xsl:param name="uri"/>
|
452
|
+
<svrl:ns-prefix-in-attribute-values uri="{$uri}" prefix="{$prefix}" />
|
453
|
+
</xsl:template>
|
454
|
+
|
455
|
+
<xsl:template name="process-p">
|
456
|
+
<xsl:param name="icon"/>
|
457
|
+
<xsl:param name="class"/>
|
458
|
+
<xsl:param name="id"/>
|
459
|
+
<xsl:param name="lang"/>
|
460
|
+
|
461
|
+
<svrl:text>
|
462
|
+
<xsl:apply-templates mode="text"/>
|
463
|
+
</svrl:text>
|
464
|
+
</xsl:template>
|
465
|
+
|
466
|
+
<xsl:template name="process-pattern">
|
467
|
+
<xsl:param name="name"/>
|
468
|
+
<xsl:param name="id"/>
|
469
|
+
<xsl:param name="is-a"/>
|
470
|
+
|
471
|
+
<!-- "Rich" parameters -->
|
472
|
+
<xsl:param name="fpi" />
|
473
|
+
<xsl:param name="icon" />
|
474
|
+
<xsl:param name="lang" />
|
475
|
+
<xsl:param name="see" />
|
476
|
+
<xsl:param name="space" />
|
477
|
+
<svrl:active-pattern >
|
478
|
+
<xsl:if test=" string( $id )">
|
479
|
+
<axsl:attribute name="id">
|
480
|
+
<xsl:value-of select=" $id " />
|
481
|
+
</axsl:attribute>
|
482
|
+
</xsl:if>
|
483
|
+
<xsl:if test=" string( $name )">
|
484
|
+
<axsl:attribute name="name">
|
485
|
+
<xsl:value-of select=" $name " />
|
486
|
+
</axsl:attribute>
|
487
|
+
</xsl:if>
|
488
|
+
|
489
|
+
<xsl:call-template name='richParms'>
|
490
|
+
<xsl:with-param name="fpi" select="$fpi"/>
|
491
|
+
<xsl:with-param name="icon" select="$icon"/>
|
492
|
+
<xsl:with-param name="lang" select="$lang"/>
|
493
|
+
<xsl:with-param name="see" select="$see" />
|
494
|
+
<xsl:with-param name="space" select="$space" />
|
495
|
+
</xsl:call-template>
|
496
|
+
|
497
|
+
<!-- ?? report that this screws up iso:title processing -->
|
498
|
+
<xsl:apply-templates mode="do-pattern-p"/>
|
499
|
+
<!-- ?? Seems that this apply-templates is never triggered DP -->
|
500
|
+
<axsl:apply-templates />
|
501
|
+
</svrl:active-pattern>
|
502
|
+
</xsl:template>
|
503
|
+
|
504
|
+
<!-- Overrides skeleton -->
|
505
|
+
<xsl:template name="process-message" >
|
506
|
+
<xsl:param name="pattern"/>
|
507
|
+
<xsl:param name="role"/>
|
508
|
+
</xsl:template>
|
509
|
+
|
510
|
+
|
511
|
+
<!-- Overrides skeleton -->
|
512
|
+
<xsl:template name="process-span" >
|
513
|
+
<xsl:param name="class" />
|
514
|
+
<xsl:choose>
|
515
|
+
<xsl:when test=" $allow-foreign = 'true'">
|
516
|
+
<xsl:copy-of select="."/>
|
517
|
+
</xsl:when>
|
518
|
+
<xsl:otherwise>
|
519
|
+
<!-- We generate too much whitespace rather than risking concatenation -->
|
520
|
+
<axsl:text> </axsl:text>
|
521
|
+
<xsl:apply-templates mode="inline-text"/>
|
522
|
+
<axsl:text> </axsl:text>
|
523
|
+
</xsl:otherwise>
|
524
|
+
</xsl:choose>
|
525
|
+
</xsl:template>
|
526
|
+
|
527
|
+
<!-- =========================================================================== -->
|
528
|
+
<!-- processing rich parameters. -->
|
529
|
+
<xsl:template name='richParms'>
|
530
|
+
<!-- "Rich" parameters -->
|
531
|
+
<xsl:param name="fpi" />
|
532
|
+
<xsl:param name="icon" />
|
533
|
+
<xsl:param name="lang" />
|
534
|
+
<xsl:param name="see" />
|
535
|
+
<xsl:param name="space" />
|
536
|
+
<!-- Process rich attributes. -->
|
537
|
+
<xsl:if test=" $allow-foreign = 'true'">
|
538
|
+
<xsl:if test="string($fpi)">
|
539
|
+
<axsl:attribute name="fpi">
|
540
|
+
<xsl:value-of select="$fpi "/>
|
541
|
+
</axsl:attribute>
|
542
|
+
</xsl:if>
|
543
|
+
<xsl:if test="string($icon)">
|
544
|
+
<axsl:attribute name="icon">
|
545
|
+
<xsl:value-of select="$icon "/>
|
546
|
+
</axsl:attribute>
|
547
|
+
</xsl:if>
|
548
|
+
<xsl:if test="string($see)">
|
549
|
+
<axsl:attribute name="see ">
|
550
|
+
<xsl:value-of select="$see "/>
|
551
|
+
</axsl:attribute>
|
552
|
+
</xsl:if>
|
553
|
+
</xsl:if>
|
554
|
+
<xsl:if test="string($space)">
|
555
|
+
<axsl:attribute name="xml:space">
|
556
|
+
<xsl:value-of select="$space"/>
|
557
|
+
</axsl:attribute>
|
558
|
+
</xsl:if>
|
559
|
+
<xsl:if test="string($lang)">
|
560
|
+
<axsl:attribute name="xml:lang">
|
561
|
+
<xsl:value-of select="$lang"/>
|
562
|
+
</axsl:attribute>
|
563
|
+
</xsl:if>
|
564
|
+
</xsl:template>
|
565
|
+
|
566
|
+
<!-- processing linkable parameters. -->
|
567
|
+
<xsl:template name='linkableParms'>
|
568
|
+
<xsl:param name="role"/>
|
569
|
+
<xsl:param name="subject"/>
|
570
|
+
|
571
|
+
<!-- ISO SVRL has a role attribute to match the Schematron role attribute -->
|
572
|
+
<xsl:if test=" string($role )">
|
573
|
+
<axsl:attribute name="role">
|
574
|
+
<xsl:value-of select=" $role " />
|
575
|
+
</axsl:attribute>
|
576
|
+
</xsl:if>
|
577
|
+
<!-- ISO SVRL does not have a subject attribute to match the Schematron subject attribute.
|
578
|
+
Instead, the Schematron subject attribute is folded into the location attribute -->
|
579
|
+
</xsl:template>
|
580
|
+
|
581
|
+
|
582
|
+
</xsl:stylesheet>
|
583
|
+
|
data/lib/schematron.rb
ADDED
@@ -0,0 +1,67 @@
|
|
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 = File.join File.dirname(__FILE__), "..", '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
|
+
|
27
|
+
xforms = ISO_FILES.map do |file|
|
28
|
+
|
29
|
+
Dir.chdir(ISO_IMPL_DIR) do
|
30
|
+
doc = XML::Document.file file
|
31
|
+
LibXSLT::XSLT::Stylesheet.new doc
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
# Compile schematron into xsl that maps to svrl
|
37
|
+
validator_doc = xforms.inject(schema_doc) { |xml, xsl| xsl.apply xml }
|
38
|
+
@validator_xsl = LibXSLT::XSLT::Stylesheet.new validator_doc
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate(instance_doc)
|
42
|
+
|
43
|
+
# Validate the xml
|
44
|
+
results_doc = @validator_xsl.apply instance_doc
|
45
|
+
|
46
|
+
# compile the errors
|
47
|
+
results = []
|
48
|
+
|
49
|
+
results_doc.root.find('//svrl:failed-assert', NS_PREFIXES).each do |assert|
|
50
|
+
context = instance_doc.root.find_first assert['location']
|
51
|
+
|
52
|
+
assert.find('svrl:text/text()', NS_PREFIXES).each do |message|
|
53
|
+
results << {
|
54
|
+
:type => context.node_type_name,
|
55
|
+
:name => context.name,
|
56
|
+
:line => context.line_num,
|
57
|
+
:message => message.content.strip }
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
results
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
data/schematron.gemspec
CHANGED
@@ -1,14 +1,37 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "schematron"
|
3
|
-
spec.version = '0.0.
|
3
|
+
spec.version = '0.0.2'
|
4
4
|
spec.summary = "ISO Schematron Validation"
|
5
5
|
spec.email = "flazzarino@gmail.com"
|
6
6
|
spec.homepage = 'http://github.com/flazz/iso-schematron'
|
7
7
|
spec.authors = ["Francesco Lazzarino"]
|
8
|
+
spec.rubyforge_project = 'schematron'
|
8
9
|
|
9
|
-
spec.
|
10
|
-
|
11
|
-
|
10
|
+
spec.executables = ['stron']
|
11
|
+
|
12
|
+
spec.files = ["Rakefile", "schematron.gemspec", "README", "LICENSE.txt",
|
13
|
+
"bin/stron",
|
14
|
+
"lib/schematron.rb",
|
15
|
+
"iso_impl/iso_abstract_expand.xsl",
|
16
|
+
"iso_impl/iso_dsdl_include.xsl",
|
17
|
+
"iso_impl/iso_schematron_skeleton_for_saxon.xsl",
|
18
|
+
"iso_impl/iso_schematron_skeleton_for_xslt1.xsl",
|
19
|
+
"iso_impl/iso_schematron_text.xsl",
|
20
|
+
"iso_impl/iso_svrl.xsl",
|
21
|
+
"spec/command_spec.rb",
|
22
|
+
"spec/feature_requests_spec.rb",
|
23
|
+
"spec/instances",
|
24
|
+
"spec/instances/daitss-sip",
|
25
|
+
"spec/instances/daitss-sip/Example1.xml",
|
26
|
+
"spec/instances/daitss-sip/Example2.xml",
|
27
|
+
"spec/instances/premis-in-mets",
|
28
|
+
"spec/instances/premis-in-mets/bad.xml",
|
29
|
+
"spec/instances/premis-in-mets/good.xml",
|
30
|
+
"spec/schema",
|
31
|
+
"spec/schema/fda_sip.sch",
|
32
|
+
"spec/schema/pim.sch",
|
33
|
+
"spec/schema_spec.rb",
|
34
|
+
"spec/spec_helper.rb"]
|
12
35
|
|
13
36
|
spec.has_rdoc = true
|
14
37
|
end
|