flazz-schematron 0.0.0 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1884 @@
1
+ <?xml version="1.0"?><?xar XSLT?>
2
+
3
+ <!--
4
+ OVERVIEW
5
+
6
+ ASCC/Schematron.com Skeleton Module for ISO Schematron (for XSLT2 systems)
7
+
8
+ ISO Schematron is a language for making assertion about the presence or absense
9
+ of patterns in XML documents. It is typically used for as a schema language, or
10
+ to augment existing schema languages, and to check business rules. It is very
11
+ powerful, yet quite simple: a developer only need know XPath and about five other
12
+ elements.
13
+
14
+ This is an open source implementation of ISO Schematron in XSLT. Although ISO does
15
+ not allow reference implementations which might compete with the text of the
16
+ standard, this code has been compiled by Rick Jelliffe, inventor of Schematron
17
+ and editor of the ISO standard; so developers can certainly use it as an
18
+ unofficial reference implementation for clarification.
19
+
20
+ This implementation is based on one by Oliver Becker. API documentation is
21
+ available separately; try www.schematron.com for this. Funding for this
22
+ stylesheet over the years has come from Topologi Pty. Ltd., Geotempo Ltd.,
23
+ and ASCC, Tapei.
24
+
25
+ There are two versions of this skeleton: one is tailored for XSLT1 processors
26
+ and the other is tailored for XSLT2 processors. Future versions of the
27
+ XSLT2 skeleton may support more features than that the XSLT 1 skeleton.
28
+ -->
29
+ <!--
30
+ TIPS
31
+
32
+ A tip for new users of Schematron: make your assertions contain positive messages
33
+ about what is expected, rather than error messages. For example, use the form
34
+ "An X should have a Y, because Z".
35
+
36
+ Another tip is that Schematron provides an
37
+ element <iso:ns> for declaring the namespaces and prefixes used in Xpaths in
38
+ attribute values; it does not extend the XML Namespaces mechanism: if a name
39
+ in an XPath has a prefix, there must be an <iso:ns> element for that prefix; if
40
+ a name in an XPath does not have a prefix, it is always in no namespace.
41
+
42
+ A tip for implementers of Schematron, either using this API or re-implementing it:
43
+ make the value of the diagnostics, flags and richer features available if possible;
44
+ Schematron has many of the optional richer features which, if implemented, provide
45
+ a compelling alternative approach to validation and business-rules checking compared
46
+ to other schema languages and programs.
47
+
48
+ If you create your own meta-stylesheet to override this one, it is a
49
+ good idea to have both in the same directory and to run the stylesheet
50
+ from that directory, as many XSLT implementations have ideosyncratic
51
+ handling of URLs: keep it simple.
52
+ -->
53
+
54
+
55
+ <!--
56
+ INVOCATION INFORMATION
57
+
58
+ The following parameters are available
59
+
60
+ phase NMTOKEN | "#ALL" (default) Select the phase for validation
61
+ allow-foreign "true" | "false" (default) Pass non-Schematron elements to the generated stylesheet
62
+ sch.exslt.imports semi-colon delimited string of filenames for some EXSLT implementations
63
+ message-newline "true" (default) | "false" Generate an extra newline at the end of messages
64
+ debug "true" | "false" (default) Debug mode lets compilation continue despite problems
65
+ attributes "true" | "false" (Autodetecting) Use only when the schema has no attributes as the context nodes
66
+ only-child-elements "true" | "false" (Autodetecting) Use only when the schema has no comments
67
+ or PI as the context nodes
68
+
69
+ The following parameters can be specified as Schematron variables in diagnostics, assertions and so on.
70
+ fileNameParameter string
71
+ fileDirParameter string
72
+ archiveNameParameter string In case of ZIP files
73
+ archiveDirParameter string In case of ZIP files
74
+
75
+ Experimental: USE AT YOUR OWN RISK
76
+ visit-text "true" "false" Also visist text nodes for context. WARNING: NON_STARDARD.
77
+ select-contents '' | 'key' | '//' Select different implementation strategies
78
+
79
+ Conventions: Meta-stylesheets that override this may use the following parameters
80
+ generate-paths=true|false generate the @location attribute with XPaths
81
+ diagnose= yes | no Add the diagnostics to the assertion test in reports
82
+ terminate= yes | no Terminate on the first failed assertion or successful report
83
+
84
+ -->
85
+
86
+ <!--
87
+ XSLT VERSION SUPPORT
88
+
89
+ XSLT 1:
90
+ A schema using the standard XSLT 1 query binding will have a /schema/@queryBinding='xslt' or
91
+ nothing.
92
+
93
+ * Note: XT does not implement key() and will die if given it.
94
+ * Add all formal parameters to default templates
95
+ * Fix missing apply-templates from process-ns and add params back
96
+
97
+ EXSLT: Experimental support
98
+ A schema using the EXSLT query binding will have a /schema/@queryBinding='exslt'.
99
+ It is built on XSLT 1. After experience is gained, this binding is expected to be
100
+ formalized as part of ISO Schematron, which currently reserves the "exslt" name for this purpose.
101
+
102
+ Some EXSLT engines have the extra functions built-in. For these, there is no need to
103
+ provide library locations. For engines that require the functions, either hard code
104
+ them in this script or provide them on the command-line argument.
105
+
106
+ XSLT 2: Experimental support
107
+ A schema using the XSLT 2 query binding will have a /schema/@queryBinding='xslt2'.
108
+ This binding is expected to be formalized as part of ISO
109
+ Schematron, which currently reserves the "xslt2" name for this purpose.
110
+ The xsl:import-schema, xsl:key and xsl:function elements are allowed as top elements.
111
+
112
+ XPATH: Experimental support
113
+ A schema using the XPATH query binding will have a /schema/@queryBinding='xpath'.
114
+ It can run with XSLT 1 and is a strict superset of default ISO Schematron. After
115
+ experience is gained, this binding is expected to be formalized as part of ISO
116
+ Schematron, which currently reserves the "xpath" name for this purpose.
117
+
118
+ The intent of this query binding is to support minimal non-XSLT implementations of
119
+ Schematron that use simple XPath APIs. These not only have fewer functions available
120
+ than the XSLT version of XPath, but some of them do not support variables.
121
+ Consequently, in this binding, the <let> element and command-line variables passed
122
+ to the schema should not be used?
123
+ The xsl:import-schema element is not allowed.
124
+
125
+ -->
126
+ <!--
127
+ PROCESS INFORMATION
128
+
129
+ This stylesheet compiles a Schematron schema (*.sch) into XSLT code (*.xsl).
130
+ The generated XSLT code can then be run against an XML file (*.xml, etc) and
131
+ will produce validation results.
132
+
133
+ The output of validation results is performed using named templates (process-*).
134
+ These can be overridden easily by making a new XSLT stylesheet that imports this
135
+ stylesheet but has its own version of the relevant process-* templates. Several
136
+ of these invoking stylesheets are available: "iso_svrl.xsl", for example generates
137
+ ISO Schematron Validation Report Language format results.
138
+
139
+ In this version of the stylesheet, the ISO feature called "abstract patterns" is
140
+ implemented using macro processing: a prior XSLT stage to which converts uses
141
+ of abstract patterns into normal patterns. If you do not use abstract patterns,
142
+ it is not necessary to preprocess the schema.
143
+
144
+ To summarize, a basic process flow for some commandline processor is like this:
145
+ XSLT -input=xxx.sch -output=xxx.xsl -stylesheet=iso_schematron_skeleton.xsl
146
+ XSLT -input=document.xml -output=xxx-document.results -stylesheet=xxx.xsl
147
+
148
+ iso_svrl.xslt is an implementation of Schematron that can use this skeleton and
149
+ generate ISO SVRL reports. A process flow for some commandline processor would
150
+ be like this:
151
+ XSLT -input=xxx.sch -output=xxx.xsl -stylesheet=iso_svrl.xsl
152
+ XSLT -input=document.xml -output=xxx-document.results -stylesheet=xxx.xsl
153
+
154
+ It is not impossible that ultimately a third stage, to handle macro-preprocessing
155
+ and inclusion, might be necessary. (The trade-off is in making this XSLT more
156
+ complex compared to making the outer process more complex.)
157
+
158
+ This version has been developed to work with
159
+ Saxon 8
160
+ For versions for XSLT 1 processors, see www.xml.com
161
+
162
+ Please note that if you are using SAXON and JAXP, then you should use
163
+ System.setProperty("javax.xml.transform.TransformerFactory",
164
+ "net.sf.saxon.TransformerFactoryImpl");
165
+ rather than
166
+ System.setProperty("javax.xml.xpath.TransformerFactory",
167
+ "net.sf.saxon.TransformerFactoryImpl");
168
+ which is does not work, at least for the versions of SAXON we tried.
169
+ -->
170
+ <!--
171
+ LEGAL INFORMATION
172
+
173
+ Copyright (c) 2000-2008 Rick Jelliffe and Academia Sinica Computing Center, Taiwan
174
+
175
+ This software is provided 'as-is', without any express or implied warranty.
176
+ In no event will the authors be held liable for any damages arising from
177
+ the use of this software.
178
+
179
+ Permission is granted to anyone to use this software for any purpose,
180
+ including commercial applications, and to alter it and redistribute it freely,
181
+ subject to the following restrictions:
182
+
183
+ 1. The origin of this software must not be misrepresented; you must not claim
184
+ that you wrote the original software. If you use this software in a product,
185
+ an acknowledgment in the product documentation would be appreciated but is
186
+ not required.
187
+
188
+ 2. Altered source versions must be plainly marked as such, and must not be
189
+ misrepresented as being the original software.
190
+
191
+ 3. This notice may not be removed or altered from any source distribution.
192
+ -->
193
+ <!--
194
+ VERSION INFORMATION
195
+ 2008-08-11
196
+ * TT report/@flag was missing
197
+ 2008-08-06
198
+ * TT Top-level lets need to be implemented using xsl:param not xsl:variable
199
+ * TT xsl:param/@select must have XPath or not be specified
200
+
201
+ 2008-08-04
202
+ * RJ add saxon namespace to output to allow extension functions
203
+ Version: 2008-07-28
204
+ * KH schematron-get-full-path-3 has [index] even on top step
205
+ Version: 2008-07-24
206
+ * RJ clean out commented out namespace handling code
207
+ * RJ add support for experimental non-standard attribute report/@action
208
+ and assert/@action, and add parameter not in the published API
209
+ (should not break anything: marked up as a tunneling parameter)
210
+ * RJ allow schema/@queryBinding='xpath2' and warn if variables are
211
+ used
212
+
213
+ Version: 2008-07-14 update for XSLT2 and inclusion experiments
214
+ * RJ Clean up zero-length fragment test on include
215
+ * RJ Add experimental support for include containers
216
+ * RJ Add support for xsl:import-schema (request Paul Hermans)
217
+ * RJ Add support for xsl:function
218
+ * RJ For path generation, test for //iso:schema not just /iso:schema, for potential embedded Schematron support
219
+ * RJ Don't generate double error messages for old namespace elements
220
+ * RJ Experimental iso:rule/iso:title just kept as comment (bigger request Uche Ogbuji)
221
+ * RJ Fix bug that prevented including patterns in this (report Roger
222
+ Costello)
223
+ Version: 2007-10-17
224
+ Forked out version just to support SAXON 8 and potentially other XSLT2 processors.
225
+ * RJ use xsl:namespace element
226
+ * RJ use schold as namespace for old schematron, to prevent SAXON complaining
227
+ when validating the Schematron schema for Schematron
228
+ * RJ fix FULL-PATH for attributes
229
+
230
+ Version: 2007-07-19
231
+ Accept most changes in David Carlisle's fork, but continue as XSLT1 script:
232
+ http://dpcarlisle.blogspot.com/search/label/schematron
233
+ * DPC Remove "optimize" parameter
234
+ * DPC Add autodetecting optimize parameter attribute to skip checking attribute
235
+ context
236
+ * DPC Add autodetecting optimize parameter only-child-elements turn off checking for
237
+ comments and PIs
238
+ * DPC (Experimental: NON_STANDARD DANGER!) Add param visit-text to viist text
239
+ nodes too for context
240
+ * DPC Fix inclusion syntax to allow #
241
+ * DPC Priorities count up from 1000 not down from 4000 to allow more rules
242
+ * RJ Add new template for titles of schemas, with existing behaviour.
243
+ Override process-schema-title for custom processing of title
244
+
245
+
246
+ Version: 2007-04-04
247
+ * RJ debug mode param
248
+ * RJ alter mixed test to only test mixed branches, so the same document
249
+ could have old and new namespaces schemas in it, but each schema must
250
+ be distinct, just so as not to overconstrain things.
251
+ * KH zero-length include/@href is fatal error, but allow debug mode
252
+ * SB add hint on SAXON and JAXP
253
+ * DC generate-full-path-1 generates XLST1 code by default
254
+ Version: 2007-03-05
255
+ * AS Typo for EXSLT randome, improve comment
256
+ * KH get-schematron-full-path-2 needs to apply to attributes too
257
+ * DP document policy on extensions better
258
+ * DC use copy-of not copy for foreign elements
259
+ * DC add generate-path-2
260
+ * DC don't try to apply templates to attribute axis on attribute nodes, to
261
+ stop SAXON warning.
262
+ * RJ improve reporting of typos
263
+
264
+ Version: 2007-02-08
265
+ * KH Schematron fullpath implementation: @* handled twice and / missing
266
+ * KH Change stylesheetbody from named template to mode to allow implementers more flexibility.
267
+ Move process-ns to outside the stylesheet body.
268
+ * DP, FG, fix handling of xslt:key
269
+ * FG no iso:title/@class
270
+ * Experimental optimization 'visit-no-attributes'
271
+ * KH Experimental added schematron-get-full-path-2 which gives prefixed version for humans
272
+ * DC Move stylesheet/@version generation to after namespace handling
273
+ * DC, FG EXSLT namespace handling code
274
+ * FG add ref and commented code from FG's page on namespaces
275
+ * Start adding normalize-space() to parameter code
276
+ * Add a space between diagnostics
277
+
278
+ Version: 2007-01-22
279
+ * DP change = ($start) to = $start and =($phase) to =$phase
280
+ to run under Saxon 8.8j
281
+ * FG better title section using ( @id | iso:title)[last()]
282
+ * Default query language binding is "xslt" not "xslt1"
283
+
284
+ Version: 2007-01-19
285
+ * Simplify message newline code
286
+ * Remove termination and xpath appending to message options:
287
+ factor out as iso_schematron_terminator.xsl
288
+ * Comment out XSLT2 namespace fix temporarily
289
+
290
+ Version: 2007-01-18 (First beta candidate for comment)
291
+ * DC remove xml:space="preserve"
292
+ * FG improve comment on import statement
293
+ * DC improve comments on invocation section
294
+ * Add exploratory support for iso:schema[@queryBinding='xpath']
295
+ by allowing it and warning as lets are found
296
+ * Be strict about queryBinding spelling errors
297
+ * Extra comments on the different queryBindings
298
+ * KH Add option "message-paths" to generate XPath from output
299
+ * KH Add option "terminate" to halt with an error after the first assertion
300
+ * KH refactor paths in schematron-full-path
301
+ * Improve (?) namespace handling: no dummy attributes for prefix "xsl" generated
302
+
303
+ Version: 2007-01-15
304
+ * FG fix for calling templates
305
+ * Add formal parameters to default templates: may help XSLT 2
306
+ * Fix get-schematron-full-path
307
+ * Include skeleton1-6 is commented out by default
308
+
309
+ Version:2007-01-12 (Pre-beta release to Schematron-love-in maillist)
310
+ * Add many extra parameters to the process-* calls, so that almost
311
+ all the information in the schema can be provided to client programs.
312
+ Also, rearrange the parameters to fit in with the ISO schema, which
313
+ has "rich" and "linkable" attribute groups.
314
+ * Warn on diagnostics with no ID once only
315
+ * Improved path reporting, to handle for namespaces
316
+ * Add process-title dummy template for API
317
+ * Add command-line parameter allow-foreign (true|false) to suppress
318
+ warnings one foreign elements and pass them through to the generated
319
+ stylesheet
320
+ * remove legacy templates for the old ASCC namespace and no namespace,
321
+ and use an import statement instead. Much cleaner now!
322
+ * patterns use @id not @name
323
+ * titles can contain sub-elements
324
+ * start change iso:rule to allow attributes, PIs and comments
325
+ * the default process-* for inline elements add a leading and trailing
326
+ space, to reduce the chance of concatenation.
327
+ * add comments to make the generated code clearer
328
+
329
+ Version:2006-11-07 (ISO: first release private to schematron-love-in maillist for review)
330
+ * Duplicate pattern templates, for handling ISO namespace
331
+ * Add priority onto default and paragraph templates
332
+ * Add namespace checks
333
+ * Handle key in xsl namespace not iso
334
+ * Add include
335
+ * Improve namespace handling
336
+ * Preliminary XSLT2 and EXSLT support
337
+ * Refactor iso:schema for clarity
338
+
339
+ Version: 2003-05-26
340
+ * Fix bug with key
341
+ Version: 2003-04-16
342
+ * handle 1.6 let expressions
343
+ * make key use XSLT names, and allow anywhere
344
+ Version: 2001-06-13
345
+ * same skeleton now supports namespace or no namespace
346
+ * parameters to handlers updated for all 1.5 attributes
347
+ * diagnostic hints supported: command-line option diagnose=yes|no
348
+ * phases supported: command-line option phase=#ALL|...
349
+ * abstract rules
350
+ * compile-time error messages
351
+ * add utility routine generate-id-from-path
352
+
353
+ Contributors: Rick Jelliffe (original), Oliver Becker (architecture, XSLT2),
354
+ Miloslav Nic (diagnostic, phase, options), Ludwig Svenonius (abstract)
355
+ Uche Ogbuji (misc. bug fixes), Jim Ancona (SAXON workaround),
356
+ Francis Norton (generate-id-from-path), Robert Leftwich, Bryan Rasmussen,
357
+ Dave Pawson (include, fallback), Florent Georges (namespaces, exslt, attribute
358
+ context), Benoit Maisonny (attribute context), John Dumps (process-message newline),
359
+ Cliff Stanford (diagnostics and other newlines)
360
+
361
+
362
+
363
+
364
+ KNOWN TYPICAL LIMITATIONS:
365
+ * Don't use <iso:ns prefix="xsl" .../> with a namespace other than the standard
366
+ XSLT one. This would be a bizarre thing to do anyway.
367
+ * Don't use other prefixes for the XSLT namespace either; some implementations will
368
+ not handle it correctly.
369
+
370
+ EXTENSIONS:
371
+ ISO Schematron is designed as a framework with some standard query language
372
+ bindings. If you need to support other features, please do so safely by making
373
+ up your own @queryLanguage name: this makes it clear that your schema requires
374
+ special features. For example, default ISO Schematron does not support user
375
+ defined functions; so if you want to use the user defined function feature
376
+ in XSLT, you need to have a schema with some queryBinding attribute name like
377
+ "XSLT-with-my-functions" or whatever.
378
+ -->
379
+
380
+
381
+
382
+
383
+ <xsl:stylesheet
384
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
385
+ xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"
386
+ xmlns:schold="http://www.ascc.net/xml/schematron"
387
+ xmlns:iso="http://purl.oclc.org/dsdl/schematron"
388
+ xmlns:exsl="http://exslt.org/common"
389
+ extension-element-prefixes="exsl"
390
+ version="2.0"
391
+ >
392
+ <!-- This program implements ISO Schematron, except for abstract patterns
393
+ which require a preprocess.
394
+ -->
395
+
396
+
397
+ <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
398
+
399
+
400
+ <!-- Category: top-level-element -->
401
+ <xsl:output method="xml" omit-xml-declaration="no" standalone="yes" indent="yes"/>
402
+
403
+
404
+
405
+ <xsl:param name="phase">
406
+ <xsl:choose>
407
+ <xsl:when test="//iso:schema/@defaultPhase">
408
+ <xsl:value-of select="//iso:schema/@defaultPhase"/>
409
+ </xsl:when>
410
+ <xsl:otherwise>#ALL</xsl:otherwise>
411
+ </xsl:choose>
412
+ </xsl:param>
413
+
414
+ <xsl:param name="allow-foreign">false</xsl:param>
415
+
416
+ <xsl:param name="message-newline">true</xsl:param>
417
+
418
+ <!-- DPC set to true if contexts should be checked on attribute nodes
419
+ defaults to true if there is any possibility that a context could match an attribute,
420
+ err on the side if caution, a context of *[.='@'] would cause this param to defualt to true
421
+ even though @ is in a string
422
+ -->
423
+ <xsl:param name="attributes">
424
+ <xsl:choose>
425
+ <xsl:when test="//iso:rule[contains(@context,'@') or contains(@context,'attribute')]">true</xsl:when>
426
+ <xsl:otherwise>false</xsl:otherwise>
427
+ </xsl:choose>
428
+ </xsl:param>
429
+
430
+ <!-- DPC set to true if contexts should be checked on just elements in the child axis
431
+ defaults to true if there is any possibility that a context could match an comment or PI
432
+ err on the side if caution, a context of *[.='('] would cause this param to defualt to true
433
+ even though ( is in a string, but node() comment() and processing-instruction() all have a (
434
+ -->
435
+ <xsl:param name="only-child-elements">
436
+ <xsl:choose>
437
+ <xsl:when test="//iso:rule[contains(@context,'(')]">true</xsl:when>
438
+ <xsl:otherwise>false</xsl:otherwise>
439
+ </xsl:choose>
440
+ </xsl:param>
441
+
442
+ <!-- DPC set to true if contexts should be checked on text nodes nodes (if only-child-elements is false)
443
+ THIS IS NON CONFORMANT BEHAVIOUR JUST FOR DISCUSSION OF A POSSIBLE CHANGE TO THE
444
+ SPECIFICATION. THIS PARAM SHOULD GO IF THE FINAL DECISION IS THAT THE SPEC DOES NOT CHANGE.
445
+ Always defaults to false
446
+ -->
447
+ <xsl:param name="visit-text" select="'false'"/>
448
+
449
+ <!-- DPC
450
+ When selecting contexts the specified behaviour is
451
+ @*|node()[not(self::text())]
452
+ The automatic settings may use
453
+ node()[not(self::text())]
454
+ @*|*
455
+ *
456
+ instead for schema for which they are equivalent.
457
+ If the params are set explictly the above may be used, and also either if
458
+ @*
459
+ @*|node()
460
+ in all cases the result may not be equivalent, for example if you specify no attributes and the schema
461
+ does have attribute contexts they will be silently ignored.
462
+
463
+ after testing it turns out that
464
+ node()[not(self::text())] is slower in saxon than *|comment()|processing-instruction()
465
+ which I find a bit surprising but anyway I'll use the longr faster version.
466
+ -->
467
+ <xsl:variable name="context-xpath">
468
+ <xsl:if test="$attributes='true'">@*|</xsl:if>
469
+ <xsl:choose>
470
+ <xsl:when test="$only-child-elements='true'">*</xsl:when>
471
+ <xsl:when test="$visit-text='true'">node()</xsl:when>
472
+ <xsl:otherwise>*|comment()|processing-instruction()</xsl:otherwise>
473
+ </xsl:choose>
474
+ </xsl:variable>
475
+
476
+ <!-- DPC if this is set to
477
+ '' use recursive templates to iterate over document tree,
478
+ 'key' select all contexts with a key rather than walking the tree explictly in each mode
479
+ '//' select all contexts with // a key rather than walking the tree explictly in each mode (XSLT2 only)
480
+ -->
481
+ <xsl:param name="select-contexts" select="''"/>
482
+
483
+
484
+ <!-- e.g. saxon file.xml file.xsl "sch.exslt.imports=.../string.xsl;.../math.xsl" -->
485
+ <xsl:param name="sch.exslt.imports"/>
486
+
487
+ <xsl:param name="debug">false</xsl:param>
488
+
489
+ <!-- Simple namespace check -->
490
+ <xsl:template match="/">
491
+ <xsl:if test="//schold:*[ancestor::iso:* or descendant::iso:*]">
492
+ <xsl:message>Schema error: Schematron elements in old and new namespaces found</xsl:message>
493
+
494
+ </xsl:if>
495
+
496
+ <xsl:apply-templates />
497
+ </xsl:template>
498
+
499
+
500
+ <!-- ============================================================== -->
501
+ <!-- ISO SCHEMATRON SCHEMA ELEMENT -->
502
+ <!-- Not handled: Abstract patterns. A pre-processor is assumed. -->
503
+ <!-- ============================================================== -->
504
+
505
+ <!-- SCHEMA -->
506
+ <!-- Default uses XSLT 1 -->
507
+ <xsl:template match="iso:schema[not(@queryBinding) or @queryBinding='xslt'
508
+ or @queryBinding='xslt1' or @queryBinding='XSLT' or @queryBinding='XSLT1'
509
+ or @queryBinding='xpath']">
510
+ <xsl:if test="
511
+ @queryBinding='xslt1' or @queryBinding='XSLT' or @queryBinding='XSLT1'">
512
+ <xsl:message>Schema error: in the queryBinding attribute, use 'xslt'</xsl:message>
513
+ </xsl:if>
514
+ <axsl:stylesheet>
515
+ <xsl:apply-templates
516
+ select="iso:ns" />
517
+
518
+ <!-- Handle the namespaces before the version attribute: reported to help SAXON -->
519
+ <xsl:attribute name="version">1.0</xsl:attribute>
520
+
521
+ <xsl:apply-templates select="." mode="stylesheetbody"/>
522
+ <!-- was xsl:call-template name="stylesheetbody"/ -->
523
+ </axsl:stylesheet>
524
+ </xsl:template>
525
+
526
+ <!-- Using EXSLT with all modeles (except function module: not applicable) -->
527
+ <xsl:template match="iso:schema[@queryBinding='exslt']" priority="10">
528
+ <xsl:comment>This XSLT was automatically generated from a Schematron schema.</xsl:comment>
529
+ <axsl:stylesheet
530
+ xmlns:date="http://exslt.org/dates-and-times"
531
+ xmlns:dyn="http://exslt.org/dynamic"
532
+ xmlns:exsl="http://exslt.org/common"
533
+ xmlns:math="http://exslt.org/math"
534
+ xmlns:random="http://exslt.org/random"
535
+ xmlns:regexp="http://exslt.org/regular-expressions"
536
+ xmlns:set="http://exslt.org/sets"
537
+ xmlns:str="http://exslt.org/strings"
538
+ extension-element-prefixes="date dyn exsl math random regexp set str" >
539
+
540
+ <xsl:apply-templates
541
+ select="iso:ns" />
542
+ <!-- Handle the namespaces before the version attribute: reported to help SAXON -->
543
+ <xsl:attribute name="version">1.0</xsl:attribute>
544
+
545
+ <xsl:apply-templates select="." mode="stylesheetbody"/>
546
+ <!-- was xsl:call-template name="stylesheetbody"/ -->
547
+ </axsl:stylesheet>
548
+ </xsl:template>
549
+
550
+ <!-- Using XSLT 2 -->
551
+ <xsl:template
552
+ match="iso:schema[@queryBinding='xslt2' or @queryBinding ='xpath2']"
553
+ priority="10">
554
+ <axsl:stylesheet
555
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
556
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
557
+ xmlns:saxon="http://saxon.sf.net/"
558
+ >
559
+ <xsl:apply-templates
560
+ select="iso:ns" />
561
+ <!-- Handle the namespaces before the version attribute: reported to help SAXON -->
562
+ <xsl:attribute name="version">2.0</xsl:attribute>
563
+
564
+ <xsl:apply-templates select="." mode="stylesheetbody"/>
565
+ <!-- was xsl:call-template name="stylesheetbody"/ -->
566
+ </axsl:stylesheet>
567
+ </xsl:template>
568
+
569
+
570
+ <!-- Default uses XSLT 1 -->
571
+ <xsl:template match="iso:schema" priority="-1">
572
+ <xsl:message terminate="yes" >Fail: This implementation of ISO Schematron does not work with
573
+ schemas using the "<xsl:value-of select="@queryBinding"/>" query language.</xsl:message>
574
+ </xsl:template>
575
+
576
+ <xsl:template match="*" mode="stylesheetbody">
577
+ <!--xsl:template name="stylesheetbody"-->
578
+ <xsl:comment>Implementers: please note that overriding process-prolog or process-root is
579
+ the preferred method for meta-stylesheets to use where possible. </xsl:comment><xsl:text>&#10;</xsl:text>
580
+
581
+ <!-- These parameters may contain strings with the name and directory of the file being
582
+ validated. For convenience, if the caller only has the information in a single string,
583
+ that string could be put in fileDirParameter. The archives parameters are available
584
+ for ZIP archives.
585
+ -->
586
+
587
+ <axsl:param name="archiveDirParameter" tunnel="yes"/>
588
+ <axsl:param name="archiveNameParameter" tunnel="yes"/>
589
+ <axsl:param name="fileNameParameter" tunnel="yes"/>
590
+ <axsl:param name="fileDirParameter" tunnel="yes"/>
591
+ <xsl:call-template name="iso:exslt.add.imports" />
592
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>PHASES</xsl:comment><xsl:text>&#10;</xsl:text>
593
+ <xsl:call-template name="handle-phase"/>
594
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>PROLOG</xsl:comment><xsl:text>&#10;</xsl:text>
595
+ <xsl:call-template name="process-prolog"/>
596
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>XSD TYPES</xsl:comment><xsl:text>&#10;</xsl:text>
597
+ <xsl:apply-templates mode="do-types" select="xsl:import-schema"/>
598
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>KEYS AND FUCNTIONS</xsl:comment><xsl:text>&#10;</xsl:text>
599
+ <xsl:apply-templates mode="do-keys" select="xsl:key | xsl:function "/>
600
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>DEFAULT RULES</xsl:comment><xsl:text>&#10;</xsl:text>
601
+ <xsl:call-template name="generate-default-rules" />
602
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>SCHEMA METADATA</xsl:comment><xsl:text>&#10;</xsl:text>
603
+ <xsl:call-template name="handle-root"/>
604
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>SCHEMATRON PATTERNS</xsl:comment><xsl:text>&#10;</xsl:text>
605
+
606
+ <xsl:apply-templates select="*[not(self::iso:ns)] " />
607
+ </xsl:template>
608
+
609
+ <xsl:template name="iso:exslt.add.imports">
610
+ <xsl:param name="imports" select="$sch.exslt.imports"/>
611
+ <xsl:choose>
612
+ <xsl:when test="contains($imports, ';')">
613
+ <axsl:import href="{ substring-before($imports, ';') }"/>
614
+ <xsl:call-template name="iso:exslt.add.imports">
615
+ <xsl:with-param name="imports" select="substring-after($imports, ';')"/>
616
+ </xsl:call-template>
617
+ </xsl:when>
618
+ <xsl:when test="$imports">
619
+ <axsl:import href="{ $imports }"/>
620
+ </xsl:when>
621
+ </xsl:choose>
622
+ </xsl:template>
623
+
624
+ <xsl:template name="handle-phase" >
625
+ <xsl:if test="not(normalize-space( $phase ) = '#ALL')">
626
+ <xsl:if test="not(iso:phase[@id = normalize-space( $phase )])">
627
+ <xsl:message>Phase Error: no phase with name <xsl:value-of select="normalize-space( $phase )"
628
+ /> has been defined.</xsl:message>
629
+ </xsl:if>
630
+ </xsl:if>
631
+ </xsl:template>
632
+
633
+ <xsl:template name="generate-default-rules">
634
+ <xsl:text>&#10;&#10;</xsl:text>
635
+ <xsl:comment>MODE: SCHEMATRON-FULL-PATH</xsl:comment><xsl:text>&#10;</xsl:text>
636
+ <xsl:comment>This mode can be used to generate an ugly though full XPath for locators</xsl:comment><xsl:text>&#10;</xsl:text>
637
+ <axsl:template match="*" mode="schematron-get-full-path">
638
+ <axsl:apply-templates select="parent::*" mode="schematron-get-full-path"/>
639
+ <xsl:choose>
640
+ <xsl:when test="//iso:schema[@queryBinding='xslt2']">
641
+ <!-- XSLT2 syntax -->
642
+ <axsl:text>/</axsl:text>
643
+ <axsl:choose>
644
+ <axsl:when test="namespace-uri()=''"><axsl:value-of select="name()"/></axsl:when>
645
+ <axsl:otherwise>
646
+ <axsl:text>*:</axsl:text>
647
+ <axsl:value-of select="local-name()"/>
648
+ <axsl:text>[namespace-uri()='</axsl:text>
649
+ <axsl:value-of select="namespace-uri()"/>
650
+ <axsl:text>']</axsl:text>
651
+ </axsl:otherwise>
652
+ </axsl:choose>
653
+ <axsl:variable name="preceding" select=
654
+ "count(preceding-sibling::*[local-name()=local-name(current())
655
+ and namespace-uri() = namespace-uri(current())])" />
656
+ <axsl:text>[</axsl:text>
657
+ <axsl:value-of select="1+ $preceding"/>
658
+ <axsl:text>]</axsl:text>
659
+ </xsl:when>
660
+
661
+ <xsl:otherwise>
662
+ <!-- XSLT1 syntax -->
663
+
664
+ <axsl:text>/</axsl:text>
665
+ <axsl:choose>
666
+ <axsl:when test="namespace-uri()=''">
667
+ <axsl:value-of select="name()"/>
668
+ <axsl:variable name="p" select="1+
669
+ count(preceding-sibling::*[name()=name(current())])" />
670
+ <axsl:if test="$p&gt;1 or following-sibling::*[name()=name(current())]">
671
+ <xsl:text/>[<axsl:value-of select="$p"/>]<xsl:text/>
672
+ </axsl:if>
673
+ </axsl:when>
674
+ <axsl:otherwise>
675
+ <axsl:text>*[local-name()='</axsl:text>
676
+ <axsl:value-of select="local-name()"/>
677
+ <axsl:text>']</axsl:text>
678
+ <axsl:variable name="p" select="1+
679
+ count(preceding-sibling::*[local-name()=local-name(current())])" />
680
+ <axsl:if test="$p&gt;1 or following-sibling::*[local-name()=local-name(current())]">
681
+ <xsl:text/>[<axsl:value-of select="$p"/>]<xsl:text/>
682
+ </axsl:if>
683
+ </axsl:otherwise>
684
+ </axsl:choose>
685
+ </xsl:otherwise>
686
+
687
+ </xsl:choose>
688
+ </axsl:template>
689
+
690
+
691
+ <axsl:template match="@*" mode="schematron-get-full-path">
692
+ <xsl:choose>
693
+ <xsl:when test="//iso:schema[@queryBinding='xslt2']">
694
+ <!-- XSLT2 syntax -->
695
+ <axsl:apply-templates select="parent::*" mode="schematron-get-full-path"/>
696
+ <axsl:text>/</axsl:text>
697
+ <axsl:choose>
698
+ <axsl:when test="namespace-uri()=''">@<axsl:value-of select="name()"/></axsl:when>
699
+ <axsl:otherwise>
700
+ <axsl:text>@*[local-name()='</axsl:text>
701
+ <axsl:value-of select="local-name()"/>
702
+ <axsl:text>' and namespace-uri()='</axsl:text>
703
+ <axsl:value-of select="namespace-uri()"/>
704
+ <axsl:text>']</axsl:text>
705
+ </axsl:otherwise>
706
+ </axsl:choose>
707
+ </xsl:when>
708
+
709
+ <xsl:otherwise>
710
+ <!-- XSLT1 syntax -->
711
+ <axsl:text>/</axsl:text>
712
+ <axsl:choose>
713
+ <axsl:when test="namespace-uri()=''">@<axsl:value-of
714
+ select="name()"/></axsl:when>
715
+ <axsl:otherwise>
716
+ <axsl:text>@*[local-name()='</axsl:text>
717
+ <axsl:value-of select="local-name()"/>
718
+ <axsl:text>' and namespace-uri()='</axsl:text>
719
+ <axsl:value-of select="namespace-uri()"/>
720
+ <axsl:text>']</axsl:text>
721
+ </axsl:otherwise>
722
+ </axsl:choose>
723
+
724
+ </xsl:otherwise>
725
+ </xsl:choose>
726
+ </axsl:template>
727
+
728
+ <xsl:text>&#10;&#10;</xsl:text>
729
+
730
+ <xsl:comment>MODE: SCHEMATRON-FULL-PATH-2</xsl:comment>
731
+ <xsl:text>&#10;</xsl:text>
732
+ <xsl:comment>This mode can be used to generate prefixed XPath for humans</xsl:comment>
733
+ <xsl:text>&#10;</xsl:text>
734
+ <!--simplify the error messages by using the namespace prefixes of the
735
+ instance rather than the generic namespace-uri-styled qualification-->
736
+ <axsl:template match="node() | @*" mode="schematron-get-full-path-2">
737
+ <!--report the element hierarchy-->
738
+ <axsl:for-each select="ancestor-or-self::*">
739
+ <axsl:text>/</axsl:text>
740
+ <axsl:value-of select="name(.)"/>
741
+ <axsl:if test="preceding-sibling::*[name(.)=name(current())]">
742
+ <axsl:text>[</axsl:text>
743
+ <axsl:value-of
744
+ select="count(preceding-sibling::*[name(.)=name(current())])+1"/>
745
+ <axsl:text>]</axsl:text>
746
+ </axsl:if>
747
+ </axsl:for-each>
748
+ <!--report the attribute-->
749
+ <axsl:if test="not(self::*)">
750
+ <axsl:text/>/@<axsl:value-of select="name(.)"/>
751
+ </axsl:if>
752
+ </axsl:template>
753
+
754
+
755
+ <xsl:comment>MODE: SCHEMATRON-FULL-PATH-3</xsl:comment>
756
+
757
+ <xsl:text>&#10;</xsl:text>
758
+ <xsl:comment>This mode can be used to generate prefixed XPath for humans
759
+ (Top-level element has index)</xsl:comment>
760
+ <xsl:text>&#10;</xsl:text>
761
+ <!--simplify the error messages by using the namespace prefixes of the
762
+ instance rather than the generic namespace-uri-styled qualification-->
763
+ <axsl:template match="node() | @*" mode="schematron-get-full-path-3">
764
+ <!--report the element hierarchy-->
765
+ <axsl:for-each select="ancestor-or-self::*">
766
+ <axsl:text>/</axsl:text>
767
+ <axsl:value-of select="name(.)"/>
768
+ <axsl:if test="parent::*">
769
+ <axsl:text>[</axsl:text>
770
+ <axsl:value-of
771
+ select="count(preceding-sibling::*[name(.)=name(current())])+1"/>
772
+ <axsl:text>]</axsl:text>
773
+ </axsl:if>
774
+ </axsl:for-each>
775
+ <!--report the attribute-->
776
+ <axsl:if test="not(self::*)">
777
+ <axsl:text/>/@<axsl:value-of select="name(.)"/>
778
+ </axsl:if>
779
+ </axsl:template>
780
+
781
+ <xsl:text>&#10;&#10;</xsl:text>
782
+ <xsl:comment>MODE: GENERATE-ID-FROM-PATH </xsl:comment><xsl:text>&#10;</xsl:text>
783
+ <!-- repeatable-id maker derived from Francis Norton's. -->
784
+ <!-- use this if you need generate ids in separate passes,
785
+ because generate-id() is not guaranteed to produce the same
786
+ results each time. These ids are not XML names but closer to paths. -->
787
+ <axsl:template match="/" mode="generate-id-from-path"/>
788
+ <axsl:template match="text()" mode="generate-id-from-path">
789
+ <axsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
790
+ <axsl:value-of select="concat('.text-', 1+count(preceding-sibling::text()), '-')"/>
791
+ </axsl:template>
792
+ <axsl:template match="comment()" mode="generate-id-from-path">
793
+ <axsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
794
+ <axsl:value-of select="concat('.comment-', 1+count(preceding-sibling::comment()), '-')"/>
795
+ </axsl:template>
796
+ <axsl:template match="processing-instruction()" mode="generate-id-from-path">
797
+ <axsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
798
+ <axsl:value-of
799
+ select="concat('.processing-instruction-', 1+count(preceding-sibling::processing-instruction()), '-')"/>
800
+ </axsl:template>
801
+ <axsl:template match="@*" mode="generate-id-from-path">
802
+ <axsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
803
+ <axsl:value-of select="concat('.@', name())"/>
804
+ </axsl:template>
805
+ <axsl:template match="*" mode="generate-id-from-path" priority="-0.5">
806
+ <axsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
807
+ <axsl:text>.</axsl:text>
808
+ <!--
809
+ <axsl:choose>
810
+ <axsl:when test="count(. | ../namespace::*) = count(../namespace::*)">
811
+ <axsl:value-of select="concat('.namespace::-',1+count(namespace::*),'-')"/>
812
+ </axsl:when>
813
+ <axsl:otherwise>
814
+ -->
815
+ <axsl:value-of
816
+ select="concat('.',name(),'-',1+count(preceding-sibling::*[name()=name(current())]),'-')"/>
817
+ <!--
818
+ </axsl:otherwise>
819
+ </axsl:choose>
820
+ -->
821
+ </axsl:template>
822
+
823
+
824
+ <xsl:text>&#10;&#10;</xsl:text>
825
+ <xsl:comment>MODE: GENERATE-ID-2 </xsl:comment><xsl:text>&#10;</xsl:text>
826
+ <!-- repeatable-id maker from David Carlisle. -->
827
+ <!-- use this if you need generate IDs in separate passes,
828
+ because generate-id() is not guaranteed to produce the same
829
+ results each time. These IDs are well-formed XML NMTOKENS -->
830
+ <axsl:template match="/" mode="generate-id-2">U</axsl:template>
831
+
832
+ <axsl:template match="*" mode="generate-id-2" priority="2">
833
+ <axsl:text>U</axsl:text>
834
+ <axsl:number level="multiple" count="*"/>
835
+ </axsl:template>
836
+
837
+ <axsl:template match="node()" mode="generate-id-2">
838
+ <axsl:text>U.</axsl:text>
839
+ <axsl:number level="multiple" count="*"/>
840
+ <axsl:text>n</axsl:text>
841
+ <axsl:number count="node()"/>
842
+ </axsl:template>
843
+
844
+ <axsl:template match="@*" mode="generate-id-2">
845
+ <axsl:text>U.</axsl:text>
846
+ <axsl:number level="multiple" count="*"/>
847
+ <axsl:text>_</axsl:text>
848
+ <axsl:value-of select="string-length(local-name(.))"/>
849
+ <axsl:text>_</axsl:text>
850
+ <axsl:value-of select="translate(name(),':','.')"/>
851
+ </axsl:template>
852
+
853
+
854
+ <xsl:comment>Strip characters</xsl:comment>
855
+ <axsl:template match="text()" priority="-1" />
856
+
857
+ </xsl:template>
858
+
859
+ <xsl:template name="handle-root">
860
+ <!-- Process the top-level element -->
861
+ <axsl:template match="/">
862
+ <xsl:call-template name="process-root">
863
+ <xsl:with-param
864
+ name="title" select="(@id | iso:title)[last()]"/>
865
+ <xsl:with-param name="version" select="'iso'" />
866
+ <xsl:with-param name="schemaVersion" select="@schemaVersion" />
867
+ <xsl:with-param name="queryBinding" select="@queryBinding" />
868
+ <xsl:with-param name="contents">
869
+ <xsl:apply-templates mode="do-all-patterns"/>
870
+ </xsl:with-param>
871
+
872
+ <!-- "Rich" properties -->
873
+ <xsl:with-param name="fpi" select="@fpi"/>
874
+ <xsl:with-param name="icon" select="@icon"/>
875
+ <xsl:with-param name="id" select="@id"/>
876
+ <xsl:with-param name="lang" select="@xml:lang"/>
877
+ <xsl:with-param name="see" select="@see" />
878
+ <xsl:with-param name="space" select="@xml:space" />
879
+ </xsl:call-template>
880
+ </axsl:template>
881
+
882
+
883
+ </xsl:template>
884
+
885
+ <!-- ============================================================== -->
886
+ <!-- ISO SCHEMATRON ELEMENTS -->
887
+ <!-- ============================================================== -->
888
+
889
+ <!-- ISO ACTIVE -->
890
+ <xsl:template match="iso:active">
891
+ <xsl:if test="not(@pattern)">
892
+ <xsl:message>Markup Error: no pattern attribute in &lt;active></xsl:message>
893
+ </xsl:if>
894
+
895
+ <xsl:if test="not(../../iso:pattern[@id = current()/@pattern])
896
+ and not(../../iso:include)">
897
+ <xsl:message>Reference Error: the pattern "<xsl:value-of select="@pattern"
898
+ />" has been activated but is not declared</xsl:message>
899
+ </xsl:if>
900
+ </xsl:template>
901
+
902
+ <!-- ISO ASSERT and REPORT -->
903
+ <xsl:template match="iso:assert">
904
+
905
+ <xsl:if test="not(@test)">
906
+ <xsl:message>Markup Error: no test attribute in &lt;assert</xsl:message>
907
+ </xsl:if>
908
+ <xsl:text>&#10;&#10; </xsl:text>
909
+ <xsl:comment>ASSERT <xsl:value-of select="@role" /> </xsl:comment><xsl:text>&#10;</xsl:text>
910
+
911
+ <axsl:choose>
912
+ <axsl:when test="{@test}"/>
913
+ <axsl:otherwise>
914
+ <xsl:call-template name="process-assert">
915
+ <xsl:with-param name="test" select="normalize-space(@test)" />
916
+ <xsl:with-param name="diagnostics" select="@diagnostics"/>
917
+ <xsl:with-param name="flag" select="@flag"/>
918
+
919
+ <!-- "Rich" properties -->
920
+ <xsl:with-param name="fpi" select="@fpi"/>
921
+ <xsl:with-param name="icon" select="@icon"/>
922
+ <xsl:with-param name="id" select="@id"/>
923
+ <xsl:with-param name="lang" select="@xml:lang"/>
924
+ <xsl:with-param name="see" select="@see" />
925
+ <xsl:with-param name="space" select="@xml:space" />
926
+
927
+ <!-- "Linking" properties -->
928
+ <xsl:with-param name="role" select="@role" />
929
+ <xsl:with-param name="subject" select="@subject" />
930
+
931
+ <!-- Non-standard extensions not part of the API yet -->
932
+ <xsl:with-param name="action" select="@action" tunnel="yes" />
933
+ </xsl:call-template>
934
+
935
+ </axsl:otherwise>
936
+ </axsl:choose>
937
+ </xsl:template>
938
+ <xsl:template match="iso:report">
939
+
940
+ <xsl:if test="not(@test)">
941
+ <xsl:message>Markup Error: no test attribute in &lt;report></xsl:message>
942
+ </xsl:if>
943
+
944
+ <xsl:text>&#10;&#10; </xsl:text>
945
+ <xsl:comment>REPORT <xsl:value-of select="@role" /> </xsl:comment><xsl:text>&#10;</xsl:text>
946
+
947
+ <axsl:if test="{@test}">
948
+
949
+ <xsl:call-template name="process-report">
950
+ <xsl:with-param name="test" select="normalize-space(@test)" />
951
+ <xsl:with-param name="diagnostics" select="@diagnostics"/>
952
+ <xsl:with-param name="flag" select="@flag"/>
953
+
954
+ <!-- "Rich" properties -->
955
+ <xsl:with-param name="fpi" select="@fpi"/>
956
+ <xsl:with-param name="icon" select="@icon"/>
957
+ <xsl:with-param name="id" select="@id"/>
958
+ <xsl:with-param name="lang" select="@xml:lang"/>
959
+ <xsl:with-param name="see" select="@see" />
960
+ <xsl:with-param name="space" select="@xml:space" />
961
+
962
+ <!-- "Linking" properties -->
963
+ <xsl:with-param name="role" select="@role" />
964
+ <xsl:with-param name="subject" select="@subject" />
965
+ </xsl:call-template>
966
+
967
+ </axsl:if>
968
+ </xsl:template>
969
+
970
+
971
+ <!-- ISO DIAGNOSTIC -->
972
+ <!-- We use a mode here to maintain backwards compatability, instead of adding it
973
+ to the other mode.
974
+ -->
975
+ <xsl:template match="iso:diagnostic" mode="check-diagnostics">
976
+ <xsl:if test="not(@id)">
977
+ <xsl:message>Markup Error: no id attribute in &lt;diagnostic></xsl:message>
978
+ </xsl:if>
979
+ </xsl:template>
980
+
981
+ <xsl:template match="iso:diagnostic" >
982
+ <xsl:call-template name="process-diagnostic">
983
+
984
+ <!-- "Rich" properties -->
985
+ <xsl:with-param name="fpi" select="@fpi"/>
986
+ <xsl:with-param name="icon" select="@icon"/>
987
+ <xsl:with-param name="id" select="@id"/>
988
+ <xsl:with-param name="lang" select="@xml:lang"/>
989
+ <xsl:with-param name="see" select="@see" />
990
+ <xsl:with-param name="space" select="@xml:space" />
991
+ </xsl:call-template>
992
+ </xsl:template>
993
+
994
+ <!-- ISO DIAGNOSTICS -->
995
+ <xsl:template match="iso:diagnostics" >
996
+ <xsl:apply-templates mode="check-diagnostics" select="*" />
997
+ </xsl:template>
998
+
999
+ <!-- ISO DIR -->
1000
+ <xsl:template match="iso:dir" mode="text" >
1001
+ <xsl:call-template name="process-dir">
1002
+ <xsl:with-param name="value" select="@value"/>
1003
+ </xsl:call-template>
1004
+ </xsl:template>
1005
+
1006
+ <!-- ISO EMPH -->
1007
+ <xsl:template match="iso:emph" mode="text">
1008
+
1009
+ <xsl:call-template name="process-emph"/>
1010
+
1011
+ </xsl:template>
1012
+
1013
+ <!-- ISO EXTENDS -->
1014
+ <xsl:template match="iso:extends">
1015
+ <xsl:if test="not(@rule)">
1016
+ <xsl:message>Markup Error: no rule attribute in &lt;extends></xsl:message>
1017
+ </xsl:if>
1018
+ <xsl:if test="not(//iso:rule[@abstract='true'][@id= current()/@rule] )">
1019
+ <xsl:message>Reference Error: the abstract rule "<xsl:value-of select="@rule"
1020
+ />" has been referenced but is not declared</xsl:message>
1021
+ </xsl:if>
1022
+ <xsl:call-template name="IamEmpty" />
1023
+
1024
+ <xsl:if test="//iso:rule[@id=current()/@rule]">
1025
+ <xsl:apply-templates select="//iso:rule[@id=current()/@rule]"
1026
+ mode="extends"/>
1027
+ </xsl:if>
1028
+
1029
+ </xsl:template>
1030
+
1031
+ <!-- KEY: ISO has no KEY -->
1032
+ <!-- NOTE:
1033
+ Key has had a checkered history. Schematron 1.0 allowed it in certain places, but
1034
+ users came up with a different location, which has now been adopted.
1035
+
1036
+ XT, the early XSLT processor, did not implement key and died when it was present.
1037
+ So there are some versions of the Schematron skeleton for XT that strip out all
1038
+ key elements.
1039
+
1040
+ Xalan (e.g. Xalan4C 1.0 and a Xalan4J) also had a funny. A fix involved making
1041
+ a top-level parameter called $hiddenKey and then using that instead of matching
1042
+ "key". This has been removed.
1043
+
1044
+ Keys and functions are the same mode, to allow their declaration to be mixed up.
1045
+ -->
1046
+ <xsl:template match="xsl:key" mode="do-keys" >
1047
+ <xsl:if test="not(@name)">
1048
+ <xsl:message>Markup Error: no name attribute in &lt;key></xsl:message>
1049
+ </xsl:if>
1050
+ <xsl:if test="not(@path) and not(@use)">
1051
+ <xsl:message>Markup Error: no path or use attribute in &lt;key></xsl:message>
1052
+ </xsl:if>
1053
+ <xsl:choose>
1054
+ <xsl:when test="parent::iso:rule ">
1055
+ <xsl:call-template name="IamEmpty" />
1056
+ <xsl:choose>
1057
+ <xsl:when test="@path">
1058
+ <axsl:key match="{../@context}" name="{@name}" use="{@path}"/>
1059
+ </xsl:when>
1060
+ <xsl:otherwise>
1061
+ <axsl:key match="{../@context}" name="{@name}" use="{@use}"/>
1062
+ </xsl:otherwise>
1063
+ </xsl:choose>
1064
+ </xsl:when>
1065
+ <xsl:otherwise>
1066
+ <xsl:if test="not(@match) ">
1067
+ <xsl:message>Markup Error: no path or use attribute in &lt;key></xsl:message>
1068
+ </xsl:if>
1069
+ <axsl:key>
1070
+ <xsl:copy-of select="@*"/>
1071
+ </axsl:key>
1072
+ </xsl:otherwise>
1073
+ </xsl:choose>
1074
+ </xsl:template>
1075
+
1076
+ <xsl:template match="xsl:key " /><!-- swallow -->
1077
+
1078
+ <xsl:template match="iso:key " >
1079
+ <xsl:message>Schema error: The key element is not in the ISO Schematron namespace. Use the XSLT namespace.</xsl:message>
1080
+ </xsl:template>
1081
+
1082
+ <!-- XSL FUNCTION -->
1083
+ <xsl:template match="xsl:function" mode="do-keys" >
1084
+ <xsl:if test="not(@name)">
1085
+ <xsl:message>Markup Error: no name attribute in &lt;function></xsl:message>
1086
+ </xsl:if>
1087
+ <xsl:copy-of select="."/>
1088
+ </xsl:template>
1089
+
1090
+ <xsl:template match="xsl:function " /><!-- swallow -->
1091
+
1092
+ <xsl:template match="iso:function " >
1093
+ <xsl:message>Schema error: The function element is not in the ISO Schematron namespace. Use the XSLT namespace.</xsl:message>
1094
+ </xsl:template>
1095
+
1096
+
1097
+ <!-- ISO INCLUDE -->
1098
+ <!-- This is only a fallback. Include really needs to have been done before this as a separate pass.-->
1099
+
1100
+ <xsl:template match="iso:include[not(normalize-space(@href))]"
1101
+ priority="1">
1102
+ <xsl:if test=" $debug = 'false' ">
1103
+ <xsl:message terminate="yes">Schema error: Empty href= attribute for include directive.</xsl:message>
1104
+ </xsl:if>
1105
+
1106
+ </xsl:template>
1107
+
1108
+ <!-- Extend the URI syntax to allow # refererences -->
1109
+ <!-- Note that XSLT2 actually already allows # references, but we override them because it
1110
+ looks unreliable -->
1111
+ <xsl:template match="iso:include">
1112
+ <xsl:variable name="document-uri" select="substring-before(concat(@href,'#'), '#')"/>
1113
+ <xsl:variable name="fragment-id" select="substring-after(@href, '#')"/>
1114
+
1115
+ <xsl:choose>
1116
+
1117
+ <xsl:when test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0" >
1118
+ <xsl:message>Error: Impossible URL in Schematron include</xsl:message>
1119
+ </xsl:when>
1120
+
1121
+ <xsl:when test="string-length( $fragment-id ) &gt; 0">
1122
+ <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
1123
+ <xsl:variable name="theFragment" select="$theDocument//iso:*[@id= $fragment-id]" />
1124
+ <xsl:if test="not($theDocument)">
1125
+ <xsl:message terminate="no">
1126
+ <xsl:text>Unable to open referenced included file: </xsl:text>
1127
+ <xsl:value-of select="@href"/>
1128
+ </xsl:message>
1129
+ </xsl:if>
1130
+ <xsl:if test=" $theFragment/self::iso:schema ">
1131
+ <xsl:message>Schema error: Use include to include fragments, not a whole schema</xsl:message>
1132
+ </xsl:if>
1133
+ <xsl:apply-templates select=" $theFragment"/>
1134
+ </xsl:when>
1135
+
1136
+ <xsl:otherwise>
1137
+ <!-- Import the top-level element if it is in schematron namespace,
1138
+ or its children otherwise, to allow a simple containment mechanism. -->
1139
+ <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
1140
+ <xsl:variable name="theFragment" select="$theDocument/iso:*" />
1141
+ <xsl:variable name="theContainedFragments" select="$theDocument/*/iso:*" />
1142
+ <xsl:if test="not($theDocument)">
1143
+ <xsl:message terminate="no">
1144
+ <xsl:text>Unable to open referenced included file: </xsl:text>
1145
+ <xsl:value-of select="@href"/>
1146
+ </xsl:message>
1147
+ </xsl:if>
1148
+ <xsl:if test=" $theFragment/self::iso:schema or $theContainedFragments/self::iso:schema">
1149
+ <xsl:message>Schema error: Use include to include fragments, not a whole schema</xsl:message>
1150
+ </xsl:if>
1151
+ <xsl:apply-templates select="$theFragment | $theContainedFragments "/>
1152
+ </xsl:otherwise>
1153
+ </xsl:choose>
1154
+ </xsl:template>
1155
+
1156
+ <!-- This is to handle the particular case of including patterns -->
1157
+ <xsl:template match="iso:include" mode="do-all-patterns">
1158
+ <xsl:variable name="document-uri" select="substring-before(concat(@href,'#'), '#')"/>
1159
+ <xsl:variable name="fragment-id" select="substring-after(@href, '#')"/>
1160
+
1161
+ <xsl:choose>
1162
+
1163
+ <xsl:when test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0" >
1164
+ <xsl:message>Error: Impossible URL in Schematron include</xsl:message>
1165
+ </xsl:when>
1166
+
1167
+ <xsl:when test="string-length( $fragment-id ) &gt; 0">
1168
+ <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
1169
+ <xsl:variable name="theFragment" select="$theDocument//iso:*[@id= $fragment-id ]" />
1170
+ <xsl:if test=" $theFragment/self::iso:schema ">
1171
+ <xsl:message>Schema error: Use include to include fragments, not a whole schema</xsl:message>
1172
+ </xsl:if>
1173
+ <xsl:apply-templates select=" $theFragment" mode="do-all-patterns"/>
1174
+ </xsl:when>
1175
+
1176
+ <xsl:otherwise>
1177
+ <!-- Import the top-level element if it is in schematron namespace,
1178
+ or its children otherwise, to allow a simple containment mechanism. -->
1179
+ <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
1180
+ <xsl:variable name="theFragment" select="$theDocument/iso:*" />
1181
+ <xsl:variable name="theContainedFragments" select="$theDocument/*/iso:*" />
1182
+ <xsl:if test=" $theFragment/self::iso:schema or $theContainedFragments/self::iso:schema">
1183
+ <xsl:message>Schema error: Use include to include fragments, not a whole schema</xsl:message>
1184
+ </xsl:if>
1185
+ <xsl:apply-templates select="$theFragment | $theContainedFragments "
1186
+ mode="do-all-patterns" />
1187
+ </xsl:otherwise>
1188
+ </xsl:choose>
1189
+ </xsl:template>
1190
+
1191
+
1192
+ <!-- XSL IMPORT-SCHEMA -->
1193
+ <!-- Importing an XSD schema allows the variour type operations to be available. -->
1194
+ <xsl:template match="xsl:import-schema" mode="do-types" >
1195
+ <xsl:choose>
1196
+ <xsl:when test="ancestor::iso:schema[@queryBinding='xslt2']">
1197
+ <xsl:copy-of select="." />
1198
+ </xsl:when>
1199
+ <xsl:otherwise>
1200
+ <xsl:message>Schema error: XSD schemas may only be imported if you are using the 'xslt2' query language binding</xsl:message>
1201
+ </xsl:otherwise>
1202
+ </xsl:choose>
1203
+ </xsl:template>
1204
+
1205
+ <!-- swallow -->
1206
+ <xsl:template match="xsl:import-schema" />
1207
+
1208
+ <xsl:template match="iso:import-schema " >
1209
+ <xsl:message>Schema error: The import-schema element is not available
1210
+ in the ISO Schematron namespace. Use the XSLT namespace.</xsl:message>
1211
+ </xsl:template>
1212
+
1213
+ <!-- ISO LET -->
1214
+ <xsl:template match="iso:let" >
1215
+ <xsl:if test="ancestor::iso:schema[@queryBinding='xpath']">
1216
+ <xsl:message>Warning: Variables should not be used with the "xpath" query language binding.</xsl:message>
1217
+ </xsl:if>
1218
+ <xsl:if test="ancestor::iso:schema[@queryBinding='xpath2']">
1219
+ <xsl:message>Warning: Variables should not be used with the "xpath2" query language binding.</xsl:message>
1220
+ </xsl:if>
1221
+
1222
+ <!-- lets at the top-level are implemented as parameters -->
1223
+ <xsl:choose>
1224
+ <xsl:when test="parent::iso:schema">
1225
+ <!-- it is an error to have an empty param/@select because an XPath is expected -->
1226
+ <axsl:param name="{@name}" select="{@value}">
1227
+ <xsl:if test="string-length(@value) &gt; 0">
1228
+ <xsl:attribute name="select"><xsl:value-of select="@value"/></xsl:attribute>
1229
+ </xsl:if>
1230
+ </axsl:param>
1231
+ </xsl:when>
1232
+ <xsl:otherwise>
1233
+ <axsl:variable name="{@name}" select="{@value}"/>
1234
+ </xsl:otherwise>
1235
+ </xsl:choose>
1236
+ </xsl:template>
1237
+
1238
+ <!-- ISO NAME -->
1239
+ <xsl:template match="iso:name" mode="text">
1240
+
1241
+ <xsl:if test="@path">
1242
+ <xsl:call-template name="process-name">
1243
+ <xsl:with-param name="name" select="concat('name(',@path,')')"/>
1244
+ </xsl:call-template>
1245
+ </xsl:if>
1246
+ <xsl:if test="not(@path)">
1247
+ <xsl:call-template name="process-name">
1248
+ <xsl:with-param name="name" select="'name(.)'"/>
1249
+ </xsl:call-template>
1250
+ </xsl:if>
1251
+ <xsl:call-template name="IamEmpty" />
1252
+ </xsl:template>
1253
+
1254
+ <!-- ISO NS -->
1255
+ <!-- Namespace handling is XSLT is quite tricky and implementation dependent -->
1256
+ <xsl:template match="iso:ns">
1257
+ <xsl:call-template name="handle-namespace" />
1258
+ </xsl:template>
1259
+
1260
+ <!-- This template is just to provide the API hook -->
1261
+ <xsl:template match="iso:ns" mode="do-all-patterns" >
1262
+ <xsl:if test="not(@uri)">
1263
+ <xsl:message>Markup Error: no uri attribute in &lt;ns></xsl:message>
1264
+ </xsl:if>
1265
+ <xsl:if test="not(@prefix)">
1266
+ <xsl:message>Markup Error: no prefix attribute in &lt;ns></xsl:message>
1267
+ </xsl:if>
1268
+ <xsl:call-template name="IamEmpty" />
1269
+ <xsl:call-template name="process-ns" >
1270
+ <xsl:with-param name="prefix" select="@prefix"/>
1271
+ <xsl:with-param name="uri" select="@uri"/>
1272
+ </xsl:call-template>
1273
+ </xsl:template>
1274
+
1275
+ <!-- ISO P -->
1276
+ <xsl:template match="iso:schema/iso:p " mode="do-schema-p" >
1277
+ <xsl:call-template name="process-p">
1278
+ <xsl:with-param name="class" select="@class"/>
1279
+ <xsl:with-param name="icon" select="@icon"/>
1280
+ <xsl:with-param name="id" select="@id"/>
1281
+ <xsl:with-param name="lang" select="@xml:lang"/>
1282
+ </xsl:call-template>
1283
+ </xsl:template>
1284
+ <xsl:template match="iso:pattern/iso:p " mode="do-pattern-p" >
1285
+ <xsl:call-template name="process-p">
1286
+ <xsl:with-param name="class" select="@class"/>
1287
+ <xsl:with-param name="icon" select="@icon"/>
1288
+ <xsl:with-param name="id" select="@id"/>
1289
+ <xsl:with-param name="lang" select="@xml:lang"/>
1290
+ </xsl:call-template>
1291
+ </xsl:template>
1292
+
1293
+ <!-- Currently, iso:p in other position are not passed through to the API -->
1294
+ <xsl:template match="iso:phase/iso:p" />
1295
+ <xsl:template match="iso:p " priority="-1" />
1296
+
1297
+ <!-- ISO PATTERN -->
1298
+ <xsl:template match="iso:pattern" mode="do-all-patterns">
1299
+ <xsl:if test="($phase = '#ALL')
1300
+ or (../iso:phase[@id= $phase]/iso:active[@pattern= current()/@id])">
1301
+
1302
+ <xsl:call-template name="process-pattern">
1303
+ <!-- the following select statement assumes that
1304
+ @id | iso:title returns node-set in document order:
1305
+ we want the title if it is there, otherwise the @id attribute -->
1306
+ <xsl:with-param name="name" select="(@id | iso:title )[last()]"/>
1307
+ <xsl:with-param name="is-a" select="''"/>
1308
+
1309
+ <!-- "Rich" properties -->
1310
+ <xsl:with-param name="fpi" select="@fpi"/>
1311
+ <xsl:with-param name="icon" select="@icon"/>
1312
+ <xsl:with-param name="id" select="@id"/>
1313
+ <xsl:with-param name="lang" select="@xml:lang"/>
1314
+ <xsl:with-param name="see" select="@see" />
1315
+ <xsl:with-param name="space" select="@xml:space" />
1316
+ </xsl:call-template>
1317
+ <xsl:choose>
1318
+ <xsl:when test="$select-contexts='key'">
1319
+ <axsl:apply-templates select="key('M','M{count(preceding-sibling::*)}')" mode="M{count(preceding-sibling::*)}"/>
1320
+ </xsl:when>
1321
+ <xsl:when test="$select-contexts='//'">
1322
+ <axsl:apply-templates mode="M{count(preceding-sibling::*)}">
1323
+ <xsl:attribute name="select">
1324
+ <xsl:text>//(</xsl:text>
1325
+ <xsl:for-each select="iso:rule/@context">
1326
+ <xsl:text>(</xsl:text>
1327
+ <xsl:value-of select="."/>
1328
+ <xsl:text>)</xsl:text>
1329
+ <xsl:if test="position()!=last()">|</xsl:if>
1330
+ </xsl:for-each>
1331
+ <xsl:text>)</xsl:text>
1332
+ <xsl:if test="$visit-text='false'">[not(self::text())]</xsl:if>
1333
+ </xsl:attribute>
1334
+ </axsl:apply-templates>
1335
+ </xsl:when>
1336
+ <xsl:otherwise>
1337
+ <axsl:apply-templates select="/" mode="M{count(preceding-sibling::*)}"/>
1338
+ </xsl:otherwise>
1339
+ </xsl:choose>
1340
+ </xsl:if>
1341
+ </xsl:template>
1342
+
1343
+ <xsl:template match="iso:pattern[@abstract='true']">
1344
+
1345
+ <xsl:message>Schema implementation error: This schema has abstract patterns, yet they are supposed to be preprocessed out already
1346
+ </xsl:message>
1347
+ </xsl:template>
1348
+
1349
+ <!-- Here is the template for the normal case of patterns -->
1350
+ <xsl:template match="iso:pattern[not(@abstract='true')]">
1351
+
1352
+ <xsl:if test="($phase = '#ALL')
1353
+ or (../iso:phase[@id= $phase]/iso:active[@pattern= current()/@id])">
1354
+ <xsl:text>&#10;&#10;</xsl:text>
1355
+ <xsl:comment>PATTERN <xsl:value-of select="@id" /> <xsl:value-of select="iso:title" /> </xsl:comment><xsl:text>&#10;</xsl:text>
1356
+ <xsl:apply-templates />
1357
+
1358
+ <!-- DPC select-contexts test -->
1359
+ <xsl:if test="not($select-contexts)">
1360
+ <axsl:template match="text()" priority="-1" mode="M{count(preceding-sibling::*)}">
1361
+ <!-- strip characters -->
1362
+ </axsl:template>
1363
+
1364
+ <!-- DPC introduce context-xpath variable -->
1365
+ <axsl:template match="@*|node()"
1366
+ priority="-2"
1367
+ mode="M{ count(preceding-sibling::*) }">
1368
+ <axsl:apply-templates select="{$context-xpath}" mode="M{count(preceding-sibling::*)}"/>
1369
+ </axsl:template>
1370
+ </xsl:if>
1371
+ </xsl:if>
1372
+ </xsl:template>
1373
+
1374
+ <!-- ISO PHASE -->
1375
+ <xsl:template match="iso:phase" >
1376
+ <xsl:if test="not(@id)">
1377
+ <xsl:message>Markup Error: no id attribute in &lt;phase></xsl:message>
1378
+ </xsl:if>
1379
+ <xsl:apply-templates/>
1380
+ </xsl:template>
1381
+
1382
+ <!-- ISO RULE -->
1383
+ <xsl:template match="iso:rule[not(@abstract='true')] ">
1384
+ <xsl:if test="not(@context)">
1385
+ <xsl:message>Markup Error: no context attribute in &lt;rule></xsl:message>
1386
+ </xsl:if>
1387
+ <xsl:text>&#10;&#10; </xsl:text>
1388
+ <xsl:comment>RULE <xsl:value-of select="@id" /> </xsl:comment><xsl:text>&#10;</xsl:text>
1389
+ <xsl:if test="iso:title">
1390
+ <xsl:comment><xsl:value-of select="iso:title" /></xsl:comment>
1391
+ </xsl:if>
1392
+ <!-- DPC select-contexts -->
1393
+ <xsl:if test="$select-contexts='key'">
1394
+ <axsl:key name="M"
1395
+ match="{@context}"
1396
+ use="'M{count(../preceding-sibling::*)}'"/>
1397
+ </xsl:if>
1398
+
1399
+
1400
+ <!-- DPC priorities count up from 1000 not down from 4000 (templates in same priority order as before) -->
1401
+ <axsl:template match="{@context}"
1402
+ priority="{1000 + count(following-sibling::*)}" mode="M{count(../preceding-sibling::*)}">
1403
+
1404
+ <xsl:call-template name="process-rule">
1405
+ <xsl:with-param name="context" select="@context"/>
1406
+
1407
+ <!-- "Rich" properties -->
1408
+ <xsl:with-param name="fpi" select="@fpi"/>
1409
+ <xsl:with-param name="icon" select="@icon"/>
1410
+ <xsl:with-param name="id" select="@id"/>
1411
+ <xsl:with-param name="lang" select="@xml:lang"/>
1412
+ <xsl:with-param name="see" select="@see" />
1413
+ <xsl:with-param name="space" select="@xml:space" />
1414
+
1415
+ <!-- "Linking" properties -->
1416
+ <xsl:with-param name="role" select="@role" />
1417
+ <xsl:with-param name="subject" select="@subject" />
1418
+ </xsl:call-template>
1419
+ <xsl:apply-templates/>
1420
+ <!-- DPC introduce context-xpath and select-contexts variables -->
1421
+ <xsl:if test="not($select-contexts)">
1422
+ <axsl:apply-templates select="{$context-xpath}" mode="M{count(../preceding-sibling::*)}"/>
1423
+ </xsl:if>
1424
+ </axsl:template>
1425
+ </xsl:template>
1426
+
1427
+
1428
+ <!-- ISO ABSTRACT RULE -->
1429
+ <xsl:template match="iso:rule[@abstract='true'] " >
1430
+ <xsl:if test=" not(@id)">
1431
+ <xsl:message>Markup Error: no id attribute on abstract &lt;rule></xsl:message>
1432
+ </xsl:if>
1433
+ <xsl:if test="@context">
1434
+ <xsl:message>Markup Error: (2) context attribute on abstract &lt;rule></xsl:message>
1435
+ </xsl:if>
1436
+ </xsl:template>
1437
+
1438
+ <xsl:template match="iso:rule[@abstract='true']"
1439
+ mode="extends" >
1440
+ <xsl:if test="@context">
1441
+ <xsl:message>Markup Error: context attribute on abstract &lt;rule></xsl:message>
1442
+ </xsl:if>
1443
+ <xsl:apply-templates/>
1444
+ </xsl:template>
1445
+
1446
+ <!-- ISO SPAN -->
1447
+ <xsl:template match="iso:span" mode="text">
1448
+ <xsl:call-template name="process-span">
1449
+ <xsl:with-param name="class" select="@class"/>
1450
+ </xsl:call-template>
1451
+ </xsl:template>
1452
+
1453
+ <!-- ISO TITLE -->
1454
+
1455
+ <xsl:template match="iso:schema/iso:title" priority="1">
1456
+ <xsl:call-template name="process-schema-title" />
1457
+ </xsl:template>
1458
+
1459
+
1460
+ <xsl:template match="iso:title" >
1461
+ <xsl:call-template name="process-title" />
1462
+ </xsl:template>
1463
+
1464
+
1465
+ <!-- ISO VALUE-OF -->
1466
+ <xsl:template match="iso:value-of" mode="text" >
1467
+ <xsl:if test="not(@select)">
1468
+ <xsl:message>Markup Error: no select attribute in &lt;value-of></xsl:message>
1469
+ </xsl:if>
1470
+ <xsl:call-template name="IamEmpty" />
1471
+
1472
+ <xsl:choose>
1473
+ <xsl:when test="@select">
1474
+ <xsl:call-template name="process-value-of">
1475
+ <xsl:with-param name="select" select="@select"/>
1476
+ </xsl:call-template>
1477
+ </xsl:when>
1478
+ <xsl:otherwise >
1479
+ <xsl:call-template name="process-value-of">
1480
+ <xsl:with-param name="select" select="'.'"/>
1481
+ </xsl:call-template>
1482
+ </xsl:otherwise>
1483
+ </xsl:choose>
1484
+
1485
+ </xsl:template>
1486
+
1487
+
1488
+ <!-- ============================================================== -->
1489
+ <!-- DEFAULT TEXT HANDLING -->
1490
+ <!-- ============================================================== -->
1491
+ <xsl:template match="text()" priority="-1" mode="do-keys">
1492
+ <!-- strip characters -->
1493
+ </xsl:template>
1494
+ <xsl:template match="text()" priority="-1" mode="do-all-patterns">
1495
+ <!-- strip characters -->
1496
+ </xsl:template>
1497
+ <xsl:template match="text()" priority="-1" mode="do-schema-p">
1498
+ <!-- strip characters -->
1499
+ </xsl:template>
1500
+ <xsl:template match="text()" priority="-1" mode="do-pattern-p">
1501
+ <!-- strip characters -->
1502
+ </xsl:template>
1503
+
1504
+ <xsl:template match="text()" priority="-1">
1505
+ <!-- Strip characters -->
1506
+ </xsl:template>
1507
+
1508
+ <xsl:template match="text()" mode="text">
1509
+ <xsl:value-of select="."/>
1510
+ </xsl:template>
1511
+
1512
+ <xsl:template match="text()" mode="inline-text">
1513
+ <xsl:value-of select="."/>
1514
+ </xsl:template>
1515
+
1516
+ <!-- ============================================================== -->
1517
+ <!-- UTILITY TEMPLATES -->
1518
+ <!-- ============================================================== -->
1519
+ <xsl:template name="IamEmpty">
1520
+ <xsl:if test="count( * )">
1521
+ <xsl:message>
1522
+ <xsl:text>Warning: </xsl:text>
1523
+ <xsl:value-of select="name(.)"/>
1524
+ <xsl:text> must not contain any child elements</xsl:text>
1525
+ </xsl:message>
1526
+ </xsl:if>
1527
+ </xsl:template>
1528
+
1529
+ <xsl:template name="diagnosticsSplit">
1530
+ <!-- Process at the current point the first of the <diagnostic> elements
1531
+ referred to parameter str, and then recurse -->
1532
+ <xsl:param name="str"/>
1533
+ <xsl:variable name="start">
1534
+ <xsl:choose>
1535
+ <xsl:when test="contains($str,' ')">
1536
+ <xsl:value-of select="substring-before($str,' ')"/>
1537
+ </xsl:when>
1538
+ <xsl:otherwise><xsl:value-of select="$str"/></xsl:otherwise>
1539
+ </xsl:choose>
1540
+ </xsl:variable>
1541
+
1542
+ <xsl:variable name="end">
1543
+ <xsl:if test="contains($str,' ')">
1544
+ <xsl:value-of select="substring-after($str,' ')"/>
1545
+ </xsl:if>
1546
+ </xsl:variable>
1547
+
1548
+ <!-- This works with all namespaces -->
1549
+ <xsl:if test="not(string-length(normalize-space($start)) = 0)
1550
+ and not(//iso:diagnostic[@id = $start])
1551
+ and not(//schold:diagnostic[@id = $start])
1552
+ and not(//diagnostic[@id = $start])">
1553
+ <xsl:message>Reference error: A diagnostic "<xsl:value-of select="string($start)"
1554
+ />" has been referenced but is not declared</xsl:message>
1555
+ </xsl:if>
1556
+
1557
+ <xsl:if test="string-length(normalize-space($start)) > 0">
1558
+ <xsl:text> </xsl:text>
1559
+ <xsl:apply-templates
1560
+ select="//iso:diagnostic[@id = $start ]
1561
+ | //schold:diagnostic[@id = $start ]
1562
+ | //diagnostic[@id= $start ]"/>
1563
+ </xsl:if>
1564
+
1565
+ <xsl:if test="not($end='')">
1566
+ <xsl:call-template name="diagnosticsSplit">
1567
+ <xsl:with-param name="str" select="$end"/>
1568
+ </xsl:call-template>
1569
+ </xsl:if>
1570
+ </xsl:template>
1571
+
1572
+ <!-- It would be nice to use this but xsl:namespace does not
1573
+ allow a fallback -->
1574
+ <!--xsl:template name="handle-namespace" version="2.0">
1575
+ <xsl:namespace name="{@prefix}" select="@uri">
1576
+ </xsl:template-->
1577
+
1578
+ <xsl:template name="handle-namespace">
1579
+ <!-- experimental code from http://eccnet.eccnet.com/pipermail/schematron-love-in/2006-June/000104.html -->
1580
+ <!-- Handle namespaces differently for exslt systems, and default, only using XSLT1 syntax -->
1581
+ <!-- For more info see http://fgeorges.blogspot.com/2007/01/creating-namespace-nodes-in-xslt-10.html -->
1582
+ <xsl:choose>
1583
+ <!-- The following code workds for XSLT2 -->
1584
+ <xsl:when test="element-available('xsl:namespace')">
1585
+ <xsl:namespace name="{@prefix}" select="@uri" />
1586
+ </xsl:when>
1587
+
1588
+ <xsl:when use-when="not(element-available('xsl:namespace'))"
1589
+ test="function-available('exsl:node-set')">
1590
+ <xsl:variable name="ns-dummy-elements">
1591
+ <xsl:element name="{@prefix}:dummy" namespace="{@uri}"/>
1592
+ </xsl:variable>
1593
+ <xsl:variable name="p" select="@prefix"/>
1594
+ <xsl:copy-of select="exsl:node-set($ns-dummy-elements)
1595
+ /*/namespace::*[local-name()=$p]"/>
1596
+ </xsl:when>
1597
+
1598
+ <!-- end XSLT2 code -->
1599
+
1600
+
1601
+ <xsl:when test="@prefix = 'xsl' ">
1602
+ <!-- Do not generate dummy attributes with the xsl: prefix, as these
1603
+ are errors against XSLT, because we presume that the output
1604
+ stylesheet uses the xsl prefix. In any case, there would already
1605
+ be a namespace declaration for the XSLT namespace generated
1606
+ automatically, presumably using "xsl:".
1607
+ -->
1608
+ </xsl:when>
1609
+
1610
+ <xsl:when test="@uri = 'http://www.w3.org/1999/XSL/Transform'">
1611
+ <xsl:message terminate="yes">
1612
+ <xsl:text>Using the XSLT namespace with a prefix other than "xsl" in </xsl:text>
1613
+ <xsl:text>Schematron rules is not supported </xsl:text>
1614
+ <xsl:text>in this processor: </xsl:text>
1615
+ <xsl:value-of select="system-property('xsl:vendor')"/>
1616
+ </xsl:message>
1617
+ </xsl:when>
1618
+
1619
+ <xsl:otherwise>
1620
+ <xsl:attribute name="{concat(@prefix,':dummy-for-xmlns')}" namespace="{@uri}" />
1621
+
1622
+ </xsl:otherwise>
1623
+ </xsl:choose>
1624
+
1625
+
1626
+ </xsl:template>
1627
+
1628
+ <!-- ============================================================== -->
1629
+ <!-- UNEXPECTED ELEMENTS -->
1630
+ <!-- ============================================================== -->
1631
+
1632
+ <xsl:template match="iso:*" priority="-2">
1633
+ <xsl:message>
1634
+ <xsl:text>Error: unrecognized element in ISO Schematron namespace: check spelling
1635
+ and capitalization</xsl:text>
1636
+ <xsl:value-of select="name(.)"/>
1637
+ </xsl:message>
1638
+ </xsl:template>
1639
+
1640
+
1641
+ <!-- Swallow old namespace elements: there is an upfront test for them elsewhere -->
1642
+ <xsl:template match="schold:*" priority="-2" />
1643
+
1644
+ <xsl:template match="*" priority="-3">
1645
+ <xsl:choose>
1646
+ <xsl:when test=" $allow-foreign = 'false' ">
1647
+ <xsl:message>
1648
+ <xsl:text>Warning: unrecognized element </xsl:text>
1649
+ <xsl:value-of select="name(.)"/>
1650
+ </xsl:message>
1651
+ </xsl:when>
1652
+ <xsl:otherwise>
1653
+ <xsl:copy-of select="." />
1654
+ </xsl:otherwise>
1655
+ </xsl:choose>
1656
+ </xsl:template>
1657
+
1658
+ <xsl:template match="iso:*" mode="text" priority="-2" />
1659
+ <xsl:template match="*" mode="text" priority="-3">
1660
+ <xsl:choose>
1661
+ <xsl:when test=" $allow-foreign = 'false' ">
1662
+ <xsl:message>
1663
+ <xsl:text>Warning: unrecognized element </xsl:text>
1664
+ <xsl:value-of select="name(.)"/>
1665
+ </xsl:message>
1666
+ </xsl:when>
1667
+ <xsl:otherwise>
1668
+ <xsl:copy-of select="." />
1669
+ </xsl:otherwise>
1670
+ </xsl:choose>
1671
+ </xsl:template>
1672
+
1673
+ <!-- ============================================================== -->
1674
+ <!-- DEFAULT NAMED TEMPLATES -->
1675
+ <!-- These are the actions that are performed unless overridden -->
1676
+ <!-- ============================================================== -->
1677
+
1678
+ <xsl:template name="process-prolog"/>
1679
+ <!-- no params -->
1680
+
1681
+ <xsl:template name="process-root">
1682
+ <xsl:param name="contents"/>
1683
+ <xsl:param name="id" />
1684
+ <xsl:param name="version" />
1685
+ <xsl:param name="schemaVersion" />
1686
+ <xsl:param name="queryBinding" />
1687
+ <xsl:param name="title" />
1688
+
1689
+
1690
+ <!-- "Rich" parameters -->
1691
+ <xsl:param name="fpi" />
1692
+ <xsl:param name="icon" />
1693
+ <xsl:param name="lang" />
1694
+ <xsl:param name="see" />
1695
+ <xsl:param name="space" />
1696
+
1697
+ <xsl:copy-of select="$contents"/>
1698
+ </xsl:template>
1699
+
1700
+ <xsl:template name="process-assert">
1701
+
1702
+ <xsl:param name="test"/>
1703
+ <xsl:param name="diagnostics" />
1704
+ <xsl:param name="id" />
1705
+ <xsl:param name="flag" />
1706
+
1707
+ <!-- "Linkable" parameters -->
1708
+ <xsl:param name="role"/>
1709
+ <xsl:param name="subject"/>
1710
+
1711
+ <!-- "Rich" parameters -->
1712
+ <xsl:param name="fpi" />
1713
+ <xsl:param name="icon" />
1714
+ <xsl:param name="lang" />
1715
+ <xsl:param name="see" />
1716
+ <xsl:param name="space" />
1717
+
1718
+
1719
+ <xsl:call-template name="process-message">
1720
+ <xsl:with-param name="pattern" select="$test"/>
1721
+ <xsl:with-param name="role" select="$role"/>
1722
+ </xsl:call-template>
1723
+
1724
+
1725
+ </xsl:template>
1726
+
1727
+ <xsl:template name="process-report">
1728
+ <xsl:param name="test"/>
1729
+ <xsl:param name="diagnostics" />
1730
+ <xsl:param name="id" />
1731
+ <xsl:param name="flag" />
1732
+
1733
+ <!-- "Linkable" parameters -->
1734
+ <xsl:param name="role"/>
1735
+ <xsl:param name="subject"/>
1736
+
1737
+ <!-- "Rich" parameters -->
1738
+ <xsl:param name="fpi" />
1739
+ <xsl:param name="icon" />
1740
+ <xsl:param name="lang" />
1741
+ <xsl:param name="see" />
1742
+ <xsl:param name="space" />
1743
+
1744
+ <xsl:call-template name="process-message">
1745
+ <xsl:with-param name="pattern" select="$test"/>
1746
+ <xsl:with-param name="role" select="$role"/>
1747
+ </xsl:call-template>
1748
+ </xsl:template>
1749
+
1750
+ <xsl:template name="process-diagnostic">
1751
+ <xsl:param name="id" />
1752
+
1753
+ <!-- "Rich" parameters -->
1754
+ <xsl:param name="fpi" />
1755
+ <xsl:param name="icon" />
1756
+ <xsl:param name="lang" />
1757
+ <xsl:param name="see" />
1758
+ <xsl:param name="space" />
1759
+
1760
+ <!-- We generate too much whitespace rather than risking concatenation -->
1761
+ <axsl:text> </axsl:text>
1762
+ <xsl:apply-templates mode="text"/>
1763
+ <axsl:text> </axsl:text>
1764
+ </xsl:template>
1765
+
1766
+ <xsl:template name="process-dir">
1767
+ <xsl:param name="value" />
1768
+
1769
+ <!-- We generate too much whitespace rather than risking concatenation -->
1770
+ <axsl:text> </axsl:text>
1771
+ <xsl:apply-templates mode="inline-text"/>
1772
+ <axsl:text> </axsl:text>
1773
+ </xsl:template>
1774
+
1775
+ <xsl:template name="process-emph">
1776
+ <!-- We generate too much whitespace rather than risking concatenation -->
1777
+ <axsl:text> </axsl:text>
1778
+ <xsl:apply-templates mode="inline-text"/>
1779
+ <axsl:text> </axsl:text>
1780
+ </xsl:template>
1781
+
1782
+ <xsl:template name="process-name">
1783
+ <xsl:param name="name"/>
1784
+
1785
+ <!-- We generate too much whitespace rather than risking concatenation -->
1786
+ <axsl:text> </axsl:text>
1787
+ <axsl:value-of select="{$name}"/>
1788
+ <axsl:text> </axsl:text>
1789
+
1790
+ </xsl:template>
1791
+
1792
+ <xsl:template name="process-ns" >
1793
+ <!-- Note that process-ns is for reporting. The iso:ns elements are
1794
+ independently used in the iso:schema template to provide namespace bindings -->
1795
+ <xsl:param name="prefix"/>
1796
+ <xsl:param name="uri" />
1797
+ </xsl:template>
1798
+
1799
+ <xsl:template name="process-p">
1800
+ <xsl:param name="id" />
1801
+ <xsl:param name="class" />
1802
+ <xsl:param name="icon" />
1803
+ <xsl:param name="lang" />
1804
+ </xsl:template>
1805
+
1806
+ <xsl:template name="process-pattern">
1807
+ <xsl:param name="id" />
1808
+ <xsl:param name="name" />
1809
+ <xsl:param name="is-a" />
1810
+
1811
+ <!-- "Rich" parameters -->
1812
+ <xsl:param name="fpi" />
1813
+ <xsl:param name="icon" />
1814
+ <xsl:param name="lang" />
1815
+ <xsl:param name="see" />
1816
+ <xsl:param name="space" />
1817
+ </xsl:template>
1818
+
1819
+
1820
+ <xsl:template name="process-rule">
1821
+ <xsl:param name="context" />
1822
+
1823
+ <xsl:param name="id" />
1824
+ <xsl:param name="flag" />
1825
+
1826
+ <!-- "Linkable" parameters -->
1827
+ <xsl:param name="role"/>
1828
+ <xsl:param name="subject"/>
1829
+
1830
+ <!-- "Rich" parameters -->
1831
+ <xsl:param name="fpi" />
1832
+ <xsl:param name="icon" />
1833
+ <xsl:param name="lang" />
1834
+ <xsl:param name="see" />
1835
+ <xsl:param name="space" />
1836
+ </xsl:template>
1837
+
1838
+ <xsl:template name="process-span" >
1839
+ <xsl:param name="class" />
1840
+
1841
+ <!-- We generate too much whitespace rather than risking concatenation -->
1842
+ <axsl:text> </axsl:text>
1843
+ <xsl:apply-templates mode="inline-text"/>
1844
+ <axsl:text> </axsl:text>
1845
+ </xsl:template>
1846
+
1847
+ <xsl:template name="process-title" >
1848
+ <xsl:param name="class" />
1849
+ <xsl:call-template name="process-p">
1850
+ <xsl:with-param name="class">title</xsl:with-param>
1851
+ </xsl:call-template>
1852
+ </xsl:template>
1853
+
1854
+ <xsl:template name="process-schema-title" >
1855
+ <xsl:param name="class" />
1856
+ <xsl:call-template name="process-title">
1857
+ <xsl:with-param name="class">schema-title</xsl:with-param>
1858
+ </xsl:call-template>
1859
+ </xsl:template>
1860
+
1861
+ <xsl:template name="process-value-of">
1862
+ <xsl:param name="select"/>
1863
+
1864
+ <!-- We generate too much whitespace rather than risking concatenation -->
1865
+ <axsl:text> </axsl:text>
1866
+ <axsl:value-of select="{$select}"/>
1867
+ <axsl:text> </axsl:text>
1868
+ </xsl:template>
1869
+
1870
+ <!-- default output action: the simplest customization is to just override this -->
1871
+ <xsl:template name="process-message">
1872
+ <xsl:param name="pattern" />
1873
+ <xsl:param name="role" />
1874
+
1875
+ <xsl:apply-templates mode="text"/>
1876
+ <xsl:if test=" $message-newline = 'true'" >
1877
+ <axsl:value-of select="string('&#10;')"/>
1878
+ </xsl:if>
1879
+
1880
+ </xsl:template>
1881
+ </xsl:stylesheet>
1882
+
1883
+
1884
+