health-data-standards 3.5.3 → 3.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -3
  3. data/README.md +10 -2
  4. data/lib/health-data-standards.rb +5 -28
  5. data/lib/health-data-standards/export/cat_1.rb +3 -2
  6. data/lib/health-data-standards/export/cat_1_r2.rb +11 -0
  7. data/lib/health-data-standards/ext/node.rb +1 -2
  8. data/lib/health-data-standards/import/bulk_record_importer.rb +4 -4
  9. data/lib/health-data-standards/import/bundle/importer.rb +62 -0
  10. data/lib/health-data-standards/import/c32/insurance_provider_importer.rb +10 -8
  11. data/lib/health-data-standards/import/cat1/patient_importer.rb +3 -3
  12. data/lib/health-data-standards/import/cat1/procedure_importer.rb +42 -0
  13. data/lib/health-data-standards/import/cda/medication_importer.rb +11 -11
  14. data/lib/health-data-standards/import/cda/section_importer.rb +13 -7
  15. data/lib/health-data-standards/models/cqm/aggregate_objects.rb +5 -1
  16. data/lib/health-data-standards/models/cqm/bundle.rb +5 -3
  17. data/lib/health-data-standards/models/cqm/measure.rb +1 -1
  18. data/lib/health-data-standards/models/entry.rb +5 -1
  19. data/lib/health-data-standards/models/record.rb +10 -0
  20. data/lib/health-data-standards/models/reference.rb +23 -0
  21. data/lib/health-data-standards/models/svs/value_set.rb +4 -3
  22. data/lib/health-data-standards/railtie.rb +1 -1
  23. data/lib/health-data-standards/tasks.rb +1 -0
  24. data/lib/health-data-standards/tasks/bundle.rake +84 -2
  25. data/lib/health-data-standards/util/vs_api.rb +40 -7
  26. data/lib/health-data-standards/validate/base_validator.rb +23 -0
  27. data/lib/health-data-standards/validate/data_validator.rb +85 -0
  28. data/lib/health-data-standards/validate/measure_validator.rb +127 -0
  29. data/lib/health-data-standards/validate/performance_rate_validator.rb +94 -0
  30. data/lib/health-data-standards/validate/reported_result_extractor.rb +170 -0
  31. data/lib/health-data-standards/validate/schema_validator.rb +24 -0
  32. data/lib/health-data-standards/validate/schematron/c_processor.rb +28 -0
  33. data/lib/health-data-standards/validate/schematron/java_processor.rb +93 -0
  34. data/lib/health-data-standards/validate/schematron_validator.rb +34 -0
  35. data/lib/health-data-standards/validate/validation_error.rb +10 -0
  36. data/lib/health-data-standards/validate/validators.rb +80 -0
  37. data/lib/hqmf-generator/fulfills.xml.erb +7 -0
  38. data/lib/hqmf-generator/hqmf-generator.rb +8 -3
  39. data/lib/hqmf-model/data_criteria.rb +3 -0
  40. data/lib/hqmf-model/types.rb +29 -0
  41. data/lib/hqmf-parser/2.0/data_criteria.rb +7 -0
  42. data/lib/hqmf-parser/2.0/types.rb +24 -0
  43. data/resources/schema/infrastructure/cda/CDA_SDTC.xsd +44 -0
  44. data/resources/schema/infrastructure/cda/POCD_MT000040_SDTC.xsd +1500 -0
  45. data/resources/schema/infrastructure/cda/SDTC.xsd +210 -0
  46. data/resources/schema/processable/coreschemas/NarrativeBlock.xsd +557 -0
  47. data/resources/schema/processable/coreschemas/datatypes-base_SDTC.xsd +1850 -0
  48. data/resources/schema/processable/coreschemas/datatypes.xsd +1375 -0
  49. data/resources/schema/processable/coreschemas/infrastructureRoot.xsd +27 -0
  50. data/resources/schema/processable/coreschemas/voc.xsd +2124 -0
  51. data/resources/schematron/iso-schematron-xslt1/ExtractSchFromRNG.xsl +75 -0
  52. data/resources/schematron/iso-schematron-xslt1/ExtractSchFromXSD.xsl +77 -0
  53. data/resources/schematron/iso-schematron-xslt1/iso_abstract_expand.xsl +297 -0
  54. data/resources/schematron/iso-schematron-xslt1/iso_dsdl_include.xsl +1509 -0
  55. data/resources/schematron/iso-schematron-xslt1/iso_schematron_message.xsl +55 -0
  56. data/resources/schematron/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl +1844 -0
  57. data/resources/schematron/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl +605 -0
  58. data/resources/schematron/iso-schematron-xslt1/readme.txt +101 -0
  59. data/resources/schematron/iso-schematron-xslt1/schematron-skeleton-api.htm +723 -0
  60. data/resources/schematron/iso-schematron-xslt2/ExtractSchFromRNG-2.xsl +75 -0
  61. data/resources/schematron/iso-schematron-xslt2/ExtractSchFromXSD-2.xsl +77 -0
  62. data/resources/schematron/iso-schematron-xslt2/iso_abstract_expand.xsl +297 -0
  63. data/resources/schematron/iso-schematron-xslt2/iso_dsdl_include.xsl +1508 -0
  64. data/resources/schematron/iso-schematron-xslt2/iso_schematron_message_xslt2.xsl +55 -0
  65. data/resources/schematron/iso-schematron-xslt2/iso_schematron_skeleton_for_saxon.xsl +2299 -0
  66. data/resources/schematron/iso-schematron-xslt2/iso_svrl_for_xslt2.xsl +684 -0
  67. data/resources/schematron/iso-schematron-xslt2/readme.txt +100 -0
  68. data/resources/schematron/iso-schematron-xslt2/sch-messages-cs.xhtml +56 -0
  69. data/resources/schematron/iso-schematron-xslt2/sch-messages-de.xhtml +57 -0
  70. data/resources/schematron/iso-schematron-xslt2/sch-messages-en.xhtml +57 -0
  71. data/resources/schematron/iso-schematron-xslt2/sch-messages-fr.xhtml +54 -0
  72. data/resources/schematron/iso-schematron-xslt2/sch-messages-nl.xhtml +58 -0
  73. data/resources/schematron/iso-schematron-xslt2/schematron-skeleton-api.htm +723 -0
  74. data/resources/schematron/qrda/cat_1/CDAR2_QRDA_I_R1_D3_2015MAY_Schematron.sch +4676 -0
  75. data/resources/schematron/qrda/cat_1/voc.xml +1177 -0
  76. data/resources/schematron/qrda/cat_1_r2/QRDA Category I Release 2.sch +4069 -0
  77. data/resources/schematron/qrda/cat_1_r2/voc.xml +1065 -0
  78. data/resources/schematron/qrda/cat_3/QRDA Category III.sch +675 -0
  79. data/resources/schematron/qrda/cat_3/voc.xml +21 -0
  80. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.26.cat1.erb +18 -0
  81. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.32.cat1.erb +4 -0
  82. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.38.cat1.erb +5 -1
  83. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.4.cat1.erb +1 -0
  84. data/templates/cat1/_2.16.840.1.113883.10.20.24.3.64.cat1.erb +20 -0
  85. data/templates/cat1/_fulfills.cat1.erb +14 -0
  86. data/templates/cat1/_organization.cat1.erb +2 -1
  87. data/templates/cat1/_patient_data.cat1.erb +1 -1
  88. data/templates/cat1/show.cat1.erb +5 -4
  89. data/templates/cat3/_performance_rate.cat3.erb +5 -1
  90. data/templates/cat3/show.cat3.erb +1 -1
  91. metadata +128 -109
  92. data/lib/health-data-standards/export/ccr.rb +0 -417
  93. data/lib/health-data-standards/export/green_c32/entry.rb +0 -18
  94. data/lib/health-data-standards/export/green_c32/export_generator.rb +0 -23
  95. data/lib/health-data-standards/export/green_c32/record.rb +0 -18
  96. data/lib/health-data-standards/export/helper/gc32_view_helper.rb +0 -39
  97. data/lib/health-data-standards/import/ccr/patient_importer.rb +0 -238
  98. data/lib/health-data-standards/import/ccr/product_importer.rb +0 -60
  99. data/lib/health-data-standards/import/ccr/provider_importer.rb +0 -49
  100. data/lib/health-data-standards/import/ccr/result_importer.rb +0 -49
  101. data/lib/health-data-standards/import/ccr/section_importer.rb +0 -135
  102. data/lib/health-data-standards/import/ccr/simple_importer.rb +0 -30
  103. data/lib/health-data-standards/import/green_c32/advance_directive_importer.rb +0 -14
  104. data/lib/health-data-standards/import/green_c32/allergy_importer.rb +0 -20
  105. data/lib/health-data-standards/import/green_c32/care_goal_importer.rb +0 -26
  106. data/lib/health-data-standards/import/green_c32/condition_importer.rb +0 -38
  107. data/lib/health-data-standards/import/green_c32/encounter_importer.rb +0 -33
  108. data/lib/health-data-standards/import/green_c32/immunization_importer.rb +0 -23
  109. data/lib/health-data-standards/import/green_c32/medical_equipment_importer.rb +0 -24
  110. data/lib/health-data-standards/import/green_c32/medication_importer.rb +0 -68
  111. data/lib/health-data-standards/import/green_c32/patient_importer.rb +0 -14
  112. data/lib/health-data-standards/import/green_c32/procedure_importer.rb +0 -27
  113. data/lib/health-data-standards/import/green_c32/result_importer.rb +0 -43
  114. data/lib/health-data-standards/import/green_c32/section_importer.rb +0 -186
  115. data/lib/health-data-standards/import/green_c32/social_history_importer.rb +0 -13
  116. data/lib/health-data-standards/import/green_c32/support_importer.rb +0 -22
  117. data/lib/health-data-standards/import/green_c32/vital_sign_importer.rb +0 -21
  118. data/templates/gc32/_address.gc32.erb +0 -9
  119. data/templates/gc32/_advance_directive.gc32.erb +0 -5
  120. data/templates/gc32/_allergy.gc32.erb +0 -12
  121. data/templates/gc32/_care_goal.gc32.erb +0 -8
  122. data/templates/gc32/_condition.gc32.erb +0 -10
  123. data/templates/gc32/_encounter.gc32.erb +0 -28
  124. data/templates/gc32/_entry.gc32.erb +0 -3
  125. data/templates/gc32/_entry_attributes.gc32.erb +0 -10
  126. data/templates/gc32/_immunization.gc32.erb +0 -9
  127. data/templates/gc32/_insurance_provider.gc32.erb +0 -28
  128. data/templates/gc32/_medical_equipment.gc32.erb +0 -6
  129. data/templates/gc32/_medication.gc32.erb +0 -91
  130. data/templates/gc32/_name.gc32.erb +0 -11
  131. data/templates/gc32/_organization.gc32.erb +0 -10
  132. data/templates/gc32/_person_attributes.gc32.erb +0 -7
  133. data/templates/gc32/_procedure.gc32.erb +0 -9
  134. data/templates/gc32/_provider.gc32.erb +0 -9
  135. data/templates/gc32/_result.gc32.erb +0 -12
  136. data/templates/gc32/_social_history.gc32.erb +0 -6
  137. data/templates/gc32/_support.gc32.erb +0 -15
  138. data/templates/gc32/_telecom.gc32.erb +0 -1
  139. data/templates/gc32/_vital_sign.gc32.erb +0 -4
  140. data/templates/gc32/record.gc32.erb +0 -97
@@ -0,0 +1,1509 @@
1
+ <?xml version="1.0" encoding="UTF-8"?><?xar XSLT?>
2
+
3
+ <!--
4
+ OVERVIEW : iso_dsdl_include.xsl
5
+
6
+ This is an inclusion preprocessor for the non-smart text inclusions
7
+ of ISO DSDL. It handles
8
+ <relax:extRef> for ISO RELAX NG
9
+ <sch:include> for ISO Schematron and Schematron 1.n
10
+ <sch:extends> for 2009 draft ISO Schematron
11
+ <xi:xinclude> simple W3C XIncludes for ISO NVRL and DSRL
12
+ <crdl:ref> for draft ISO CRDL
13
+ <dtll:include> for draft ISO DTLL
14
+ <* @xlink:href> for simple W3C XLink 1.1 embedded links
15
+
16
+
17
+ This should be the first in any chain of processing. It only requires
18
+ XSLT 1. Each kind of inclusion can be turned off (or on) on the command line.
19
+
20
+ Ids in fragment identifiers or xpointers will be sought in the following
21
+ order:
22
+ * @xml:id
23
+ * id() for typed schemas (e.g. from DTD) [NOTE: XInclude does not support this]
24
+ * untyped @id
25
+
26
+ The proposed behaviour for the update to ISO Schematron has been implemented. If an
27
+ include points to an element with the same name as the parent, then that element's
28
+ contents will be included. This supports the merge style of inclusion.
29
+
30
+ When an inclusion is made, it is preceded by a PI with target DSDL_INCLUDE_START
31
+ and the href and closed by a PI with target DSDL_INCLUDE_START and the href. This is
32
+ to allow better location of problems, though only to the file level.
33
+
34
+ Limitations:
35
+ * No rebasing: relative paths will be interpreted based on the initial document's
36
+ path, not the including document. (Severe limitation!)
37
+ * No checking for circular references
38
+ * Not full xpointers: only ID matching
39
+ * <relax:include> not implemented
40
+ * XInclude handling of xml:base and xml:lang not implemented
41
+ -->
42
+ <!--
43
+ VERSION INFORMATION
44
+ 2010-04-21
45
+ * Add basic syntax checks on XPaths belonging to Schematron elements only
46
+ * Unlocalized messages are put out using xsl:message. The intent is to allow
47
+ * problems to be caught at compile time.
48
+ 2009-02-25
49
+ * Update DSDL namespace to use schematron.com
50
+ * Tested with SAXON9, Xalan 2.7.1, IE7,
51
+ * IE does not like multiple variables in same template with same name: rename.
52
+ 2008-09-18
53
+ * Remove new behaviour for include, because it conflicts with existing usage [KH]
54
+ * Add extends[@href] element with that merge functionality
55
+ * Generate PIs to notate source of inclusions for potential better diagnostics
56
+
57
+ 2008-09-16
58
+ * Fix for XSLT1
59
+
60
+ 2008-08-28
61
+ * New behaviour for schematron includes: if the pointed to element is the same as the current,
62
+ include the children.
63
+
64
+ 2008-08-20
65
+ * Fix bug: in XSLT1 cannot do $document/id('x') but need to use for-each
66
+
67
+ 2008-08-04
68
+ * Add support for inclusions in old namespace
69
+
70
+ 2008-08-03
71
+ * Fix wrong param name include-relaxng & include-crdl (KH, PH)
72
+ * Allow inclusion of XSLT and XHTML (KH)
73
+ * Fix inclusion of fragments (KH)
74
+
75
+ 2008-07-25
76
+ * Add selectable input parameter
77
+
78
+ 2008-07-24
79
+ * RJ New
80
+ -->
81
+ <!--
82
+ LEGAL INFORMATION
83
+
84
+ Copyright (c) 2008 Rick Jelliffe
85
+
86
+ This software is provided 'as-is', without any express or implied warranty.
87
+ In no event will the authors be held liable for any damages arising from
88
+ the use of this software.
89
+
90
+ Permission is granted to anyone to use this software for any purpose,
91
+ including commercial applications, and to alter it and redistribute it freely,
92
+ subject to the following restrictions:
93
+
94
+ 1. The origin of this software must not be misrepresented; you must not claim
95
+ that you wrote the original software. If you use this software in a product,
96
+ an acknowledgment in the product documentation would be appreciated but is
97
+ not required.
98
+
99
+ 2. Altered source versions must be plainly marked as such, and must not be
100
+ misrepresented as being the original software.
101
+
102
+ 3. This notice may not be removed or altered from any source distribution.
103
+ -->
104
+ <xslt:stylesheet version="1.0"
105
+ xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
106
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
107
+ xmlns:iso="http://purl.oclc.org/dsdl/schematron"
108
+ xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl"
109
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
110
+ xmlns:schold="http://www.ascc.net/xml/schematron"
111
+ xmlns:crdl="http://purl.oclc.org/dsdl/crepdl/ns/structure/1.0"
112
+ xmlns:xi="http://www.w3.org/2001/XInclude"
113
+ xmlns:dtll="http://www.jenitennison.com/datatypes"
114
+ xmlns:dsdl="http://www.schematron.com/namespace/dsdl"
115
+ xmlns:relax="http://relaxng.org/ns/structure/1.0"
116
+ xmlns:xlink="http://www.w3.org/1999/xlink"
117
+
118
+
119
+ xmlns:sch-check="http://www.schematron.com/namespace/sch-check"
120
+ >
121
+ <!-- Note: The URL for the dsdl namespace is not official -->
122
+
123
+
124
+ <xsl:param name="include-schematron">true</xsl:param>
125
+ <xsl:param name="include-crdl">true</xsl:param>
126
+ <xsl:param name="include-xinclude">true</xsl:param>
127
+ <xsl:param name="include-dtll">true</xsl:param>
128
+ <xsl:param name="include-relaxng">true</xsl:param>
129
+ <xsl:param name="include-xlink">true</xsl:param>
130
+
131
+
132
+ <!-- ========================================================== -->
133
+ <!-- Output and process contents, check Schematron XPaths too -->
134
+ <!-- ========================================================== -->
135
+
136
+ <xsl:template match="/">
137
+ <xsl:apply-templates select="." mode="dsdl:go" />
138
+ </xsl:template>
139
+
140
+ <!-- output everything else unchanged. But check Xpaths here. -->
141
+
142
+ <xslt:template match="iso:rule[@context]" mode="dsdl:go">
143
+ <xsl:call-template name="sch-check:xpath-wf-message">
144
+ <xsl:with-param name="string" select=" @context " />
145
+ <xsl:with-param name="subject" select=" 'Bad rule: ' " />
146
+ </xsl:call-template>
147
+
148
+ <xslt:copy>
149
+ <xslt:copy-of select="@*" />
150
+ <xslt:apply-templates mode="dsdl:go" />
151
+ </xslt:copy>
152
+ </xslt:template>
153
+
154
+ <xslt:template match="iso:assert[@test]" mode="dsdl:go">
155
+ <xsl:call-template name="sch-check:xpath-wf-message">
156
+ <xsl:with-param name="string" select=" @test " />
157
+ <xsl:with-param name="subject" select=" 'Bad assert: ' " />
158
+ </xsl:call-template>
159
+
160
+ <xslt:copy>
161
+ <xslt:copy-of select="@*" />
162
+ <xslt:apply-templates mode="dsdl:go" />
163
+ </xslt:copy>
164
+ </xslt:template>
165
+
166
+ <xslt:template match="iso:report[@test]" mode="dsdl:go">
167
+ <xsl:call-template name="sch-check:xpath-wf-message">
168
+ <xsl:with-param name="string" select=" @test " />
169
+ <xsl:with-param name="subject" select=" 'Bad report: ' " />
170
+ </xsl:call-template>
171
+
172
+ <xslt:copy>
173
+ <xslt:copy-of select="@*" />
174
+ <xslt:apply-templates mode="dsdl:go" />
175
+ </xslt:copy>
176
+ </xslt:template>
177
+
178
+ <xslt:template match="iso:let[@value]" mode="dsdl:go">
179
+ <xsl:call-template name="sch-check:xpath-wf-message">
180
+ <xsl:with-param name="string" select=" @value " />
181
+ <xsl:with-param name="subject" select=" 'Bad let: ' " />
182
+ </xsl:call-template>
183
+
184
+ <xslt:copy>
185
+ <xslt:copy-of select="@*" />
186
+ <xslt:apply-templates mode="dsdl:go" />
187
+ </xslt:copy>
188
+ </xslt:template>
189
+
190
+
191
+ <xslt:template match="iso:value-of[@select]" mode="dsdl:go">
192
+ <xsl:call-template name="sch-check:xpath-wf-message">
193
+ <xsl:with-param name="string" select=" @select " />
194
+ <xsl:with-param name="subject" select=" 'Bad value-of: ' " />
195
+ </xsl:call-template>
196
+
197
+ <xslt:copy>
198
+ <xslt:copy-of select="@*" />
199
+ <xslt:apply-templates mode="dsdl:go" />
200
+ </xslt:copy>
201
+ </xslt:template>
202
+
203
+ <xslt:template match="iso:name[@path]" mode="dsdl:go">
204
+ <xsl:call-template name="sch-check:xpath-wf-message">
205
+ <xsl:with-param name="string" select=" @select " />
206
+ <xsl:with-param name="subject" select=" 'Bad name element: ' " />
207
+ </xsl:call-template>
208
+
209
+ <xslt:copy>
210
+ <xslt:copy-of select="@*" />
211
+ <xslt:apply-templates mode="dsdl:go" />
212
+ </xslt:copy>
213
+ </xslt:template>
214
+
215
+ <!-- output everything else unchanged -->
216
+ <xslt:template match="node()" priority="-1" mode="dsdl:go">
217
+ <xslt:copy>
218
+ <xslt:copy-of select="@*" />
219
+ <xslt:apply-templates mode="dsdl:go" />
220
+ </xslt:copy>
221
+ </xslt:template>
222
+
223
+
224
+
225
+ <!-- =========================================================== -->
226
+ <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
227
+ <!-- Part 2 - Regular grammar-based validation - RELAX NG -->
228
+ <!-- This only implements relax:extRef not relax:include which -->
229
+ <!-- is complex. -->
230
+ <!-- =========================================================== -->
231
+ <xslt:template match="relax:extRef" mode="dsdl:go">
232
+
233
+
234
+ <!-- Insert subschema -->
235
+
236
+ <xsl:variable name="document-uri"
237
+ select="substring-before(concat(@href,'#'), '#')" />
238
+ <xsl:variable name="fragment-id"
239
+ select="substring-after(@href, '#')" />
240
+
241
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
242
+ <xsl:value-of select="@href" />
243
+ </xsl:processing-instruction>
244
+ <xsl:choose>
245
+ <xsl:when test="not( $include-relaxng = 'true' )">
246
+ <xslt:copy>
247
+ <xslt:copy-of select="@*" />
248
+ <xslt:apply-templates mode="dsdl:go" />
249
+ </xslt:copy>
250
+ </xsl:when>
251
+ <xsl:otherwise>
252
+
253
+ <xsl:choose>
254
+
255
+ <xsl:when
256
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
257
+ <xsl:message>
258
+ Error: Impossible URL in RELAX NG extRef
259
+ include
260
+ </xsl:message>
261
+ </xsl:when>
262
+
263
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
264
+ <xslt:when
265
+ test="string-length( $document-uri ) = 0">
266
+ <xslt:apply-templates mode="dsdl:go"
267
+ select="//*[@xml:id= $fragment-id ] | id( $fragment-id) | //*[@id= $fragment-id ]" />
268
+ </xslt:when>
269
+
270
+ <xsl:when
271
+ test="string-length( $fragment-id ) &gt; 0">
272
+ <xsl:variable name="theDocument_1"
273
+ select="document( $document-uri,/ )" />
274
+
275
+ <xsl:if test="not($theDocument_1)">
276
+ <xsl:message terminate="no">
277
+ <xsl:text>Unable to open referenced included file: </xsl:text>
278
+ <xsl:value-of select="@href" />
279
+ </xsl:message>
280
+ </xsl:if>
281
+ <!-- use a for-each so that the id() function works correctly on the external document -->
282
+ <xsl:for-each select="$theDocument_1">
283
+ <xsl:variable name="theFragment_1"
284
+ select="$theDocument_1//*[@xml:id= $fragment-id ]
285
+ | id( $fragment-id)
286
+ | $theDocument_1//*[@id= $fragment-id ]" />
287
+ <xsl:if test="not($theFragment_1)">
288
+ <xsl:message terminate="no">
289
+ <xsl:text>Unable to locate id attribute: </xsl:text>
290
+ <xsl:value-of select="@href" />
291
+ </xsl:message>
292
+ </xsl:if>
293
+ <xsl:apply-templates
294
+ select=" $theFragment_1[1]" mode="dsdl:go" />
295
+ </xsl:for-each>
296
+ </xsl:when>
297
+
298
+ <xsl:otherwise>
299
+ <xsl:variable name="theDocument_2"
300
+ select="document( $document-uri,/ )" />
301
+ <xsl:variable name="theFragment_2"
302
+ select="$theDocument_2/*" />
303
+ <xsl:if test="not($theDocument_2)">
304
+ <xsl:message terminate="no">
305
+ <xsl:text>Unable to open referenced included file: </xsl:text>
306
+ <xsl:value-of select="@href" />
307
+ </xsl:message>
308
+ </xsl:if>
309
+
310
+ <xsl:if test="not($theFragment_2)">
311
+ <xsl:message terminate="no">
312
+ <xsl:text>Unable to locate id attribute: </xsl:text>
313
+ <xsl:value-of select="@href" />
314
+ </xsl:message>
315
+ </xsl:if>
316
+ <xsl:apply-templates select="$theFragment_2 "
317
+ mode="dsdl:go" />
318
+ </xsl:otherwise>
319
+ </xsl:choose>
320
+
321
+ </xsl:otherwise>
322
+ </xsl:choose>
323
+
324
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
325
+ <xsl:value-of select="@href" />
326
+ </xsl:processing-instruction>
327
+ </xslt:template>
328
+
329
+
330
+
331
+ <!-- =========================================================== -->
332
+ <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
333
+ <!-- Part 3 - Rule-based validation - Schematron -->
334
+ <!-- =========================================================== -->
335
+
336
+
337
+ <!-- Extend the URI syntax to allow # references -->
338
+ <!-- Add experimental support for simple containers like /xxx:xxx/iso:pattern to allow better includes -->
339
+ <xsl:template match="iso:include" mode="dsdl:go">
340
+
341
+ <xsl:variable name="document-uri"
342
+ select="substring-before(concat(@href,'#'), '#')" />
343
+ <xsl:variable name="fragment-id"
344
+ select="substring-after(@href, '#')" />
345
+
346
+
347
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
348
+ <xsl:value-of select="@href" />
349
+ </xsl:processing-instruction>
350
+
351
+ <xsl:choose>
352
+ <xsl:when test="not( $include-schematron = 'true' )">
353
+ <xslt:copy>
354
+ <xslt:copy-of select="@*" />
355
+ <xslt:apply-templates mode="dsdl:go" />
356
+ </xslt:copy>
357
+ </xsl:when>
358
+ <xsl:otherwise>
359
+
360
+ <xsl:choose>
361
+
362
+ <xsl:when
363
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
364
+ <xsl:message>
365
+ Error: Impossible URL in Schematron include
366
+ </xsl:message>
367
+ </xsl:when>
368
+
369
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
370
+ <xslt:when
371
+ test="string-length( $document-uri ) = 0">
372
+ <xslt:apply-templates mode="dsdl:go"
373
+ select="//iso:*[@xml:id= $fragment-id ]
374
+ |id( $fragment-id)
375
+ | //iso:*[@id= $fragment-id ]" />
376
+ </xslt:when>
377
+
378
+ <!-- case where there is a fragment in another document (should be an iso: element) -->
379
+ <!-- There are three cases for includes with fragment:
380
+ 0) No href file or no matching id - error!
381
+ 1) REMOVED
382
+
383
+ 2) The linked-to element is sch:schema however the parent of the include
384
+ is not a schema. In this case, it is an error. (Actually, it should
385
+ be an error for other kinds of containment problems, but we won't
386
+ check for them in this version.)
387
+
388
+ 3) Otherwise, include the pointed-to element
389
+ -->
390
+
391
+ <xsl:when
392
+ test="string-length( $fragment-id ) &gt; 0">
393
+ <xsl:variable name="theDocument_1"
394
+ select="document( $document-uri,/ )" />
395
+ <xsl:variable name="originalParent" select=".." />
396
+
397
+ <!-- case 0 -->
398
+ <xsl:if test="not($theDocument_1)">
399
+ <xsl:message terminate="no">
400
+ <xsl:text>Unable to open referenced included file: </xsl:text>
401
+ <xsl:value-of select="@href" />
402
+ </xsl:message>
403
+ </xsl:if>
404
+ <!-- use for-each to rebase id() to external document -->
405
+ <xsl:for-each select="$theDocument_1">
406
+ <xsl:variable name="theFragment_1"
407
+ select=" $theDocument_1//iso:*[@xml:id= $fragment-id ] |
408
+ id($fragment-id) |
409
+ $theDocument_1//iso:*[@id= $fragment-id ]" />
410
+
411
+
412
+ <xsl:choose>
413
+ <!-- case 0 -->
414
+ <xsl:when test="not($theFragment_1)">
415
+ <xsl:message terminate="no">
416
+ <xsl:text>Unable to locate id attribute: </xsl:text>
417
+ <xsl:value-of select="@href" />
418
+ </xsl:message>
419
+ </xsl:when>
420
+
421
+
422
+ <!-- case 1 REMOVED -->
423
+
424
+ <!-- case 2 -->
425
+ <xsl:when
426
+ test=" $theFragment_1/self::iso:schema ">
427
+ <xsl:message>
428
+ Schema error: Use include to
429
+ include fragments, not a whole
430
+ schema
431
+ </xsl:message>
432
+ </xsl:when>
433
+
434
+ <!-- case 3 -->
435
+ <xsl:otherwise>
436
+ <xsl:apply-templates
437
+ select=" $theFragment_1[1]" mode="dsdl:go" />
438
+ </xsl:otherwise>
439
+ </xsl:choose>
440
+ </xsl:for-each>
441
+ </xsl:when>
442
+
443
+ <!-- Case where there is no ID so we include the whole document -->
444
+ <!-- Experimental addition: include fragments of children -->
445
+ <xsl:otherwise>
446
+ <xsl:variable name="theDocument_2"
447
+ select="document( $document-uri,/ )" />
448
+ <xsl:variable name="theFragment_2"
449
+ select="$theDocument_2/iso:*" />
450
+ <xsl:variable name="theContainedFragments"
451
+ select="$theDocument_2/*/iso:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
452
+ <xsl:if test="not($theDocument_2)">
453
+ <xsl:message terminate="no">
454
+ <xsl:text>Unable to open referenced included file: </xsl:text>
455
+ <xsl:value-of select="@href" />
456
+ </xsl:message>
457
+ </xsl:if>
458
+
459
+ <!-- There are three cases for includes:
460
+ 0) No text specified- error!
461
+
462
+ 1) REMOVED
463
+
464
+ 2) The linked-to element is sch:schema however the parent of the include
465
+ is not a schema. In this case, it is an error. (Actually, it should
466
+ be an error for other kinds of containment problems, but we won't
467
+ check for them in this version.)
468
+
469
+ 3) Otherwise, include the pointed-to element
470
+ -->
471
+ <xsl:choose>
472
+ <!-- case 0 -->
473
+ <xsl:when
474
+ test="not($theFragment_2) and not ($theContainedFragments)">
475
+ <xsl:message terminate="no">
476
+ <xsl:text>Unable to locate id attribute: </xsl:text>
477
+ <xsl:value-of select="@href" />
478
+ </xsl:message>
479
+ </xsl:when>
480
+
481
+ <!-- case 1 removed -->
482
+
483
+ <!-- case 2 -->
484
+ <xsl:when
485
+ test=" $theFragment_2/self::iso:schema or $theContainedFragments/self::iso:schema">
486
+ <xsl:message>
487
+ Schema error: Use include to include
488
+ fragments, not a whole schema
489
+ </xsl:message>
490
+ </xsl:when>
491
+
492
+ <!-- If this were XLST 2, we could use
493
+ if ($theFragment) then $theFragment else $theContainedFragments
494
+ here (thanks to KN)
495
+ -->
496
+ <!-- case 3 -->
497
+ <xsl:otherwise>
498
+ <xsl:apply-templates
499
+ select="$theFragment_2 " mode="dsdl:go" />
500
+ </xsl:otherwise>
501
+ </xsl:choose>
502
+ </xsl:otherwise>
503
+ </xsl:choose>
504
+ </xsl:otherwise>
505
+ </xsl:choose>
506
+
507
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
508
+ <xsl:value-of select="@href" />
509
+ </xsl:processing-instruction>
510
+ </xsl:template>
511
+
512
+
513
+ <!-- WARNING sch:extends[@href] is experimental and non standard -->
514
+ <!-- Basically, it adds the children of the selected element, not the element itself. -->
515
+ <xsl:template match="iso:extends[@href]" mode="dsdl:go">
516
+
517
+ <xsl:variable name="document-uri"
518
+ select="substring-before(concat(@href,'#'), '#')" />
519
+ <xsl:variable name="fragment-id"
520
+ select="substring-after(@href, '#')" />
521
+
522
+
523
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
524
+ <xsl:value-of select="@href" />
525
+ </xsl:processing-instruction>
526
+
527
+ <xsl:choose>
528
+ <xsl:when test="not( $include-schematron = 'true' )">
529
+ <xslt:copy>
530
+ <xslt:copy-of select="@*" />
531
+ <xslt:apply-templates mode="dsdl:go" />
532
+ </xslt:copy>
533
+ </xsl:when>
534
+ <xsl:otherwise>
535
+
536
+ <xsl:choose>
537
+
538
+ <xsl:when
539
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
540
+ <xsl:message>
541
+ Error: Impossible URL in Schematron include
542
+ </xsl:message>
543
+ </xsl:when>
544
+
545
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
546
+ <xslt:when
547
+ test="string-length( $document-uri ) = 0">
548
+ <xslt:apply-templates mode="dsdl:go"
549
+ select="//iso:*[@xml:id= $fragment-id ]/*
550
+ |id( $fragment-id)/*
551
+ | //iso:*[@id= $fragment-id ]/*" />
552
+ </xslt:when>
553
+
554
+ <!-- case where there is a fragment in another document (should be an iso: element) -->
555
+ <!-- There are three cases for includes with fragment:
556
+ 0) No href file or no matching id - error!
557
+ 1) REMOVED
558
+
559
+ 2) REMOVED
560
+
561
+ 3) Otherwise, include the pointed-to element
562
+ -->
563
+
564
+ <xsl:when
565
+ test="string-length( $fragment-id ) &gt; 0">
566
+ <xsl:variable name="theDocument_1"
567
+ select="document( $document-uri,/ )" />
568
+ <xsl:variable name="originalParent" select=".." />
569
+
570
+ <!-- case 0 -->
571
+ <xsl:if test="not($theDocument_1)">
572
+ <xsl:message terminate="no">
573
+ <xsl:text>Unable to open referenced included file: </xsl:text>
574
+ <xsl:value-of select="@href" />
575
+ </xsl:message>
576
+ </xsl:if>
577
+ <!-- use for-each to rebase id() to external document -->
578
+ <xsl:for-each select="$theDocument_1">
579
+ <xsl:variable name="theFragment_1"
580
+ select=" $theDocument_1//iso:*[@xml:id= $fragment-id ] |
581
+ id($fragment-id) |
582
+ $theDocument_1//iso:*[@id= $fragment-id ]" />
583
+
584
+
585
+ <xsl:choose>
586
+ <!-- case 0 -->
587
+ <xsl:when test="not($theFragment_1)">
588
+ <xsl:message terminate="no">
589
+ <xsl:text>Unable to locate id attribute: </xsl:text>
590
+ <xsl:value-of select="@href" />
591
+ </xsl:message>
592
+ </xsl:when>
593
+
594
+
595
+ <!-- case 1 REMOVED -->
596
+
597
+ <!-- case 2 REMOVED -->
598
+
599
+
600
+ <!-- case 3 -->
601
+ <xsl:otherwise>
602
+
603
+ <xsl:apply-templates
604
+ select=" $theFragment_1[1]/*" mode="dsdl:go" />
605
+ </xsl:otherwise>
606
+ </xsl:choose>
607
+ </xsl:for-each>
608
+ </xsl:when>
609
+
610
+ <!-- Case where there is no ID so we include the whole document -->
611
+ <!-- Experimental addition: include fragments of children -->
612
+ <xsl:otherwise>
613
+ <xsl:variable name="theDocument_2"
614
+ select="document( $document-uri,/ )" />
615
+ <xsl:variable name="theFragment_2"
616
+ select="$theDocument_2/iso:*" />
617
+ <xsl:variable name="theContainedFragments"
618
+ select="$theDocument_2/*/iso:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
619
+ <xsl:if test="not($theDocument_2)">
620
+ <xsl:message terminate="no">
621
+ <xsl:text>Unable to open referenced included file: </xsl:text>
622
+ <xsl:value-of select="@href" />
623
+ </xsl:message>
624
+ </xsl:if>
625
+
626
+ <!-- There are three cases for includes:
627
+ 0) No text specified- error!
628
+
629
+ 1) REMOVED
630
+
631
+ 2) REMOVED
632
+
633
+ 3) Otherwise, include the pointed-to element
634
+ -->
635
+ <xsl:choose>
636
+ <!-- case 0 -->
637
+ <xsl:when
638
+ test="not($theFragment_2) and not ($theContainedFragments)">
639
+ <xsl:message terminate="no">
640
+ <xsl:text>Unable to locate id attribute: </xsl:text>
641
+ <xsl:value-of select="@href" />
642
+ </xsl:message>
643
+ </xsl:when>
644
+
645
+ <!-- case 1 removed -->
646
+
647
+ <!-- case 2 removed -->
648
+
649
+ <!-- If this were XLST 2, we could use
650
+ if ($theFragment) then $theFragment else $theContainedFragments
651
+ here (thanks to KN)
652
+ -->
653
+ <!-- case 3 -->
654
+ <xsl:otherwise>
655
+ <xsl:apply-templates
656
+ select="$theFragment_2/* " mode="dsdl:go" />
657
+ </xsl:otherwise>
658
+ </xsl:choose>
659
+ </xsl:otherwise>
660
+ </xsl:choose>
661
+ </xsl:otherwise>
662
+ </xsl:choose>
663
+
664
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
665
+ <xsl:value-of select="@href" />
666
+ </xsl:processing-instruction>
667
+ </xsl:template>
668
+
669
+
670
+
671
+ <!-- =========================================================== -->
672
+ <!-- Handle Schematron 1.6 inclusions: clone of ISO code above -->
673
+ <!-- =========================================================== -->
674
+
675
+
676
+ <!-- Extend the URI syntax to allow # references -->
677
+ <!-- Add experimental support for simple containers like /xxx:xxx/schold:pattern to allow better includes -->
678
+ <xsl:template match="schold:include" mode="dsdl:go">
679
+ <xsl:variable name="document-uri"
680
+ select="substring-before(concat(@href,'#'), '#')" />
681
+ <xsl:variable name="fragment-id"
682
+ select="substring-after(@href, '#')" />
683
+
684
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
685
+ <xsl:value-of select="@href" />
686
+ </xsl:processing-instruction>
687
+
688
+ <xsl:choose>
689
+ <xsl:when test="not( $include-schematron = 'true' )">
690
+ <xslt:copy>
691
+ <xslt:copy-of select="@*" />
692
+ <xslt:apply-templates mode="dsdl:go" />
693
+ </xslt:copy>
694
+ </xsl:when>
695
+ <xsl:otherwise>
696
+ <xsl:choose>
697
+
698
+ <xsl:when
699
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
700
+ <xsl:message>
701
+ Error: Impossible URL in Schematron include
702
+ </xsl:message>
703
+ </xsl:when>
704
+
705
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
706
+ <xslt:when
707
+ test="string-length( $document-uri ) = 0">
708
+ <xslt:apply-templates mode="dsdl:go"
709
+ select="//schold:*[@xml:id= $fragment-id ]
710
+ |id( $fragment-id)
711
+ | //schold:*[@id= $fragment-id ]" />
712
+ </xslt:when>
713
+
714
+ <!-- case where there is a fragment in another document (should be an iso: element) -->
715
+ <xsl:when
716
+ test="string-length( $fragment-id ) &gt; 0">
717
+ <xsl:variable name="theDocument_1"
718
+ select="document( $document-uri,/ )" />
719
+ <xsl:if test="not($theDocument_1)">
720
+ <xsl:message terminate="no">
721
+ <xsl:text>Unable to open referenced included file: </xsl:text>
722
+ <xsl:value-of select="@href" />
723
+ </xsl:message>
724
+ </xsl:if>
725
+ <!-- use for-each to rebase id() to $theDocument -->
726
+ <xsl:for-each select="$theDocument_1">
727
+ <xsl:variable name="theFragment_1"
728
+ select=" $theDocument_1//schold:*[@xml:id= $fragment-id ] |
729
+ id($fragment-id) |
730
+ $theDocument_1//schold:*[@id= $fragment-id ]" />
731
+ <xsl:if
732
+ test=" $theFragment_1/self::schold:schema ">
733
+ <xsl:message>
734
+ Schema error: Use include to include
735
+ fragments, not a whole schema
736
+ </xsl:message>
737
+ </xsl:if>
738
+ <xsl:if test="not($theFragment_1)">
739
+ <xsl:message terminate="no">
740
+ <xsl:text>Unable to locate id attribute: </xsl:text>
741
+ <xsl:value-of select="@href" />
742
+ </xsl:message>
743
+ </xsl:if>
744
+ <xsl:apply-templates
745
+ select=" $theFragment_1[1]" mode="dsdl:go" />
746
+ </xsl:for-each>
747
+ </xsl:when>
748
+
749
+ <!-- Case where there is no ID so we include the whole document -->
750
+ <!-- Experimental addition: include fragments of children -->
751
+ <xsl:otherwise>
752
+ <xsl:variable name="theDocument_2"
753
+ select="document( $document-uri,/ )" />
754
+ <xsl:variable name="theFragment_2"
755
+ select="$theDocument_2/iso:*" />
756
+ <xsl:variable name="theContainedFragments"
757
+ select="$theDocument_2/*/schold:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
758
+ <xsl:if test="not($theDocument_2)">
759
+ <xsl:message terminate="no">
760
+ <xsl:text>Unable to open referenced included file: </xsl:text>
761
+ <xsl:value-of select="@href" />
762
+ </xsl:message>
763
+ </xsl:if>
764
+
765
+ <xsl:if
766
+ test=" $theFragment_2/self::schold:schema or $theContainedFragments/self::schold:schema">
767
+ <xsl:message>
768
+ Schema error: Use include to include
769
+ fragments, not a whole schema
770
+ </xsl:message>
771
+ </xsl:if>
772
+ <xsl:if
773
+ test="not($theFragment_2) and not ($theContainedFragments)">
774
+ <xsl:message terminate="no">
775
+ <xsl:text>Unable to locate id attribute: </xsl:text>
776
+ <xsl:value-of select="@href" />
777
+ </xsl:message>
778
+ </xsl:if>
779
+ <!-- If this were XLST 2, we could use
780
+ if ($theFragment) then $theFragment else $theContainedFragments
781
+ here (thanks to KN)
782
+ -->
783
+ <xsl:choose>
784
+ <xsl:when test=" $theFragment_2 ">
785
+ <xsl:apply-templates
786
+ select="$theFragment_2 " mode="dsdl:go" />
787
+ </xsl:when>
788
+ <xsl:otherwise>
789
+ <!-- WARNING! EXPERIMENTAL! Use at your own risk. This may be discontinued! -->
790
+ <xsl:apply-templates
791
+ select=" $theContainedFragments " mode="dsdl:go" />
792
+ </xsl:otherwise>
793
+ </xsl:choose>
794
+ </xsl:otherwise>
795
+ </xsl:choose>
796
+
797
+ </xsl:otherwise>
798
+ </xsl:choose>
799
+
800
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
801
+ <xsl:value-of select="@href" />
802
+ </xsl:processing-instruction>
803
+ </xsl:template>
804
+ <!-- =========================================================== -->
805
+ <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
806
+ <!-- Part 5 - DataType Library Language - DTLL -->
807
+ <!-- Committee Draft Experimental support only -->
808
+ <!-- The <include> element may well be replaced by XInclude in -->
809
+ <!-- any final version. -->
810
+ <!-- =========================================================== -->
811
+ <xslt:template match="dtll:include" mode="dsdl:go">
812
+ <!-- Insert subschema -->
813
+
814
+ <xsl:variable name="document-uri"
815
+ select="substring-before(concat(@href,'#'), '#')" />
816
+ <xsl:variable name="fragment-id"
817
+ select="substring-after(@href, '#')" />
818
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
819
+ <xsl:value-of select="@href" />
820
+ </xsl:processing-instruction>
821
+ <xsl:choose>
822
+ <xsl:when test="not( $include-dtll = 'true' )">
823
+ <xslt:copy>
824
+ <xslt:copy-of select="@*" />
825
+ <xslt:apply-templates mode="dsdl:go" />
826
+ </xslt:copy>
827
+ </xsl:when>
828
+ <xsl:otherwise>
829
+ <xsl:choose>
830
+
831
+ <xsl:when
832
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
833
+ <xsl:message>
834
+ Error: Impossible URL in DTLL include
835
+ </xsl:message>
836
+ </xsl:when>
837
+
838
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
839
+ <xslt:when
840
+ test="string-length( $document-uri ) = 0">
841
+ <xslt:apply-templates mode="dsdl:go"
842
+ select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
843
+ | //*[@id= $fragment-id ]" />
844
+ </xslt:when>
845
+
846
+ <xsl:when
847
+ test="string-length( $fragment-id ) &gt; 0">
848
+ <xsl:variable name="theDocument_1"
849
+ select="document( $document-uri,/ )" />
850
+ <xsl:if test="not($theDocument_1)">
851
+ <xsl:message terminate="no">
852
+ <xsl:text>Unable to open referenced included file: </xsl:text>
853
+ <xsl:value-of select="@href" />
854
+ </xsl:message>
855
+ </xsl:if>
856
+ <!-- use for-each to rebase id() to $theDocument -->
857
+ <xsl:for-each select="$theDocument_1">
858
+ <xsl:variable name="theFragment_1"
859
+ select="$theDocument_1//*[@xml:id= $fragment-id ]
860
+ | id( $fragment-id )
861
+ | $theDocument_1//*[@id= $fragment-id ]" />
862
+ <xsl:if test="not($theFragment_1)">
863
+ <xsl:message terminate="no">
864
+ <xsl:text>Unable to locate id attribute: </xsl:text>
865
+ <xsl:value-of select="@href" />
866
+ </xsl:message>
867
+ </xsl:if>
868
+ <xsl:apply-templates
869
+ select=" $theFragment_1[1]" mode="dsdl:go" />
870
+ </xsl:for-each>
871
+ </xsl:when>
872
+
873
+ <xsl:otherwise>
874
+ <xsl:variable name="theDocument_2"
875
+ select="document( $document-uri,/ )" />
876
+ <xsl:variable name="theFragment_2"
877
+ select="$theDocument_2/*" />
878
+
879
+ <xsl:if test="not($theDocument_2)">
880
+ <xsl:message terminate="no">
881
+ <xsl:text>Unable to open referenced included file: </xsl:text>
882
+ <xsl:value-of select="@href" />
883
+ </xsl:message>
884
+ </xsl:if>
885
+
886
+ <xsl:if test="not($theFragment_2)">
887
+ <xsl:message terminate="no">
888
+ <xsl:text>Unable to locate id attribute: </xsl:text>
889
+ <xsl:value-of select="@href" />
890
+ </xsl:message>
891
+ </xsl:if>
892
+ <xsl:apply-templates select="$theFragment_2 "
893
+ mode="dsdl:go" />
894
+ </xsl:otherwise>
895
+ </xsl:choose>
896
+
897
+ </xsl:otherwise>
898
+ </xsl:choose>
899
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
900
+ <xsl:value-of select="@href" />
901
+ </xsl:processing-instruction>
902
+ </xslt:template>
903
+
904
+ <!-- =========================================================== -->
905
+ <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
906
+ <!-- Part 7 - Character Repertoire Description Language - CRDL -->
907
+ <!-- Final Committee Draft 2008-01-11 Experimental support only -->
908
+ <!-- =========================================================== -->
909
+ <xslt:template match="crdl:ref" mode="dsdl:go">
910
+ <!-- Insert subschema -->
911
+
912
+ <xsl:variable name="document-uri"
913
+ select="substring-before(concat(@href,'#'), '#')" />
914
+ <xsl:variable name="fragment-id"
915
+ select="substring-after(@href, '#')" />
916
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
917
+ <xsl:value-of select="@href" />
918
+ </xsl:processing-instruction>
919
+ <xsl:choose>
920
+ <xsl:when test="not( $include-crdl = 'true' )">
921
+ <xslt:copy>
922
+ <xslt:copy-of select="@*" />
923
+ <xslt:apply-templates mode="dsdl:go" />
924
+ </xslt:copy>
925
+ </xsl:when>
926
+ <xsl:otherwise>
927
+ <xsl:choose>
928
+
929
+ <xsl:when
930
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
931
+ <xsl:message>
932
+ Error: Impossible URL in CRDL include
933
+ </xsl:message>
934
+ </xsl:when>
935
+
936
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
937
+ <xslt:when
938
+ test="string-length( $document-uri ) = 0">
939
+
940
+ <xslt:apply-templates mode="dsdl:go"
941
+ select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
942
+ | //*[@id= $fragment-id ]" />
943
+ </xslt:when>
944
+
945
+ <xsl:when
946
+ test="string-length( $fragment-id ) &gt; 0">
947
+ <xsl:variable name="theDocument_1"
948
+ select="document( $document-uri,/ )" />
949
+ <xsl:if test="not($theDocument_1)">
950
+ <xsl:message terminate="no">
951
+ <xsl:text>Unable to open referenced included file: </xsl:text>
952
+ <xsl:value-of select="@href" />
953
+ </xsl:message>
954
+ </xsl:if>
955
+ <!-- use for-each to rebase id() to $theDocument -->
956
+ <xsl:for-each select="$theDocument_1">
957
+ <xsl:variable name="theFragment_1"
958
+ select="$theDocument_1//*[@xml:id= $fragment-id ]
959
+ | id( $fragment-id )
960
+ | $theDocument_1//*[@id= $fragment-id ]" />
961
+
962
+ <xsl:if test="not($theFragment_1)">
963
+ <xsl:message terminate="no">
964
+ <xsl:text>Unable to locate id attribute: </xsl:text>
965
+ <xsl:value-of select="@href" />
966
+ </xsl:message>
967
+ </xsl:if>
968
+ <xsl:apply-templates select=" $theFragment_1 "
969
+ mode="dsdl:go" />
970
+ </xsl:for-each>
971
+ </xsl:when>
972
+
973
+ <xsl:otherwise>
974
+ <xsl:variable name="theDocument_2"
975
+ select="document( $document-uri,/ )" />
976
+ <xsl:variable name="theFragment_2"
977
+ select="$theDocument_2/*" />
978
+
979
+ <xsl:if test="not($theDocument_2)">
980
+ <xsl:message terminate="no">
981
+ <xsl:text>Unable to open referenced included file: </xsl:text>
982
+ <xsl:value-of select="@href" />
983
+ </xsl:message>
984
+ </xsl:if>
985
+ <xsl:if test="not($theFragment_2)">
986
+ <xsl:message terminate="no">
987
+ <xsl:text>Unable to locate id attribute: </xsl:text>
988
+ <xsl:value-of select="@href" />
989
+ </xsl:message>
990
+ </xsl:if>
991
+
992
+ <xsl:apply-templates select="$theFragment_2"
993
+ mode="dsdl:go" />
994
+ </xsl:otherwise>
995
+ </xsl:choose>
996
+
997
+ </xsl:otherwise>
998
+ </xsl:choose>
999
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
1000
+ <xsl:value-of select="@href" />
1001
+ </xsl:processing-instruction>
1002
+ </xslt:template>
1003
+
1004
+
1005
+ <!-- =========================================================== -->
1006
+ <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
1007
+ <!-- Part 4 - Namespace-based Validation Dispatching Language - NVDL -->
1008
+ <!-- Note: This does not include schemas referenced for -->
1009
+ <!-- validation, it merely handles any simple XIncludes -->
1010
+ <!-- =========================================================== -->
1011
+ <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
1012
+ <!-- Part 8 - Document Schema Renaming Language - DSRL -->
1013
+ <!-- Note: Final? Committee Draft Experimental support only -->
1014
+ <!-- =========================================================== -->
1015
+ <!-- XInclude support for id based references only, with 1 level -->
1016
+ <!-- of fallback. -->
1017
+ <!-- =========================================================== -->
1018
+
1019
+ <xslt:template mode="dsdl:go"
1020
+ match="xi:include[@href][not(@parseType) or @parseType ='xml']">
1021
+ <!-- Simple inclusions only here -->
1022
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
1023
+ <xsl:value-of select="@href" />
1024
+ </xsl:processing-instruction>
1025
+ <xsl:choose>
1026
+ <xsl:when test="not( $include-xinclude = 'true' )">
1027
+ <xslt:copy>
1028
+ <xslt:copy-of select="@*" />
1029
+ <xslt:apply-templates mode="dsdl:go" />
1030
+ </xslt:copy>
1031
+ </xsl:when>
1032
+ <xsl:otherwise>
1033
+ <xsl:choose>
1034
+
1035
+ <xsl:when test="contains( @href, '#')">
1036
+ <xsl:message terminate="yes">
1037
+ Fatal error: Xinclude href contains fragment
1038
+ identifier #
1039
+ </xsl:message>
1040
+ </xsl:when>
1041
+
1042
+
1043
+ <xsl:when test="contains( @xpointer, '(')">
1044
+ <xsl:message terminate="yes">
1045
+ Fatal error: Sorry, this software only
1046
+ supports simple ids in XInclude xpointers
1047
+ </xsl:message>
1048
+ </xsl:when>
1049
+
1050
+ <xsl:when
1051
+ test="string-length( @href ) = 0 and string-length( @xpointer ) = 0">
1052
+
1053
+ <xsl:message terminate="yes">
1054
+ Fatal Error: Impossible URL in XInclude
1055
+ include
1056
+ </xsl:message>
1057
+ </xsl:when>
1058
+
1059
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
1060
+ <xslt:when test="string-length( @href ) = 0">
1061
+
1062
+ <xslt:apply-templates mode="dsdl:go"
1063
+ select="//*[@xml:id= current()/@xpointer ] | id( @xpointer)
1064
+ | //*[@id= current()/@xpointer ]" />
1065
+ </xslt:when>
1066
+
1067
+ <xsl:when
1068
+ test="string-length( @xpointer ) &gt; 0">
1069
+ <xsl:variable name="theDocument_1"
1070
+ select="document( @href,/ )" />
1071
+ <xsl:variable name="theFragment_1"
1072
+ select="$theDocument_1//*[@xml:id= current()/@xpointer ]
1073
+
1074
+ | $theDocument_1//*[@id= current()/@xpointer ]" />
1075
+ <!-- removed
1076
+ | $theDocument_1/id( @xpointer)
1077
+ because it requires rebasing in XSLT1 and that would mess up the use of current()
1078
+ -->
1079
+
1080
+
1081
+ <!-- Allow one level of fallback, to another XInclude -->
1082
+ <xsl:if test="not($theDocument_1)">
1083
+ <xsl:choose>
1084
+ <xsl:when test="xi:fallback">
1085
+ <xsl:variable name="theDocument_2"
1086
+ select="document( xi:fallback[1]/xi:include[not(@parseType)
1087
+ or @parseType='xml']/@href,/ )" />
1088
+ <xsl:variable name="theFragment_2"
1089
+ select="$theDocument_2//*[@xml:id= current()/xi:fallback[1]/xi:include/@xpointer ]
1090
+ | $theDocument_2//*[@id= current()/xi:fallback[1]/xi:include/@xpointer ]" />
1091
+ <!-- removed
1092
+ | $theDocument_2/id( xi:fallback[1]/xi:include/@xpointer)
1093
+ because it id() would need rebasing in XSLT1 and that would mess up use of current()
1094
+ -->
1095
+
1096
+ <xsl:if
1097
+ test="not($theDocument_2)">
1098
+
1099
+ <xsl:message terminate="no">
1100
+ <xsl:text>Unable to open referenced included file and fallback
1101
+ file: </xsl:text>
1102
+ <xsl:value-of
1103
+ select="@href" />
1104
+ </xsl:message>
1105
+ </xsl:if>
1106
+ </xsl:when>
1107
+ <xsl:otherwise>
1108
+ <xsl:message terminate="no">
1109
+ <xsl:text>Unable to open referenced included file: </xsl:text>
1110
+ <xsl:value-of select="@href" />
1111
+ </xsl:message>
1112
+ </xsl:otherwise>
1113
+ </xsl:choose>
1114
+ </xsl:if>
1115
+ <xsl:apply-templates select=" $theFragment_1"
1116
+ mode="dsdl:go" />
1117
+ </xsl:when>
1118
+
1119
+ <!-- Document but no fragment specified -->
1120
+ <xsl:otherwise>
1121
+ <xsl:variable name="theDocument_3"
1122
+ select="document( @href,/ )" />
1123
+ <xsl:variable name="theFragment_3"
1124
+ select="$theDocument_3/*" />
1125
+
1126
+ <xsl:if test="not($theDocument_3)">
1127
+ <xsl:message terminate="no">
1128
+ <xsl:text>Unable to open referenced included file: </xsl:text>
1129
+ <xsl:value-of select="@href" />
1130
+ </xsl:message>
1131
+ </xsl:if>
1132
+
1133
+ <xsl:apply-templates select="$theFragment_3 "
1134
+ mode="dsdl:go" />
1135
+ </xsl:otherwise>
1136
+ </xsl:choose>
1137
+
1138
+ </xsl:otherwise>
1139
+ </xsl:choose>
1140
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
1141
+ <xsl:value-of select="@href" />
1142
+ </xsl:processing-instruction>
1143
+ </xslt:template>
1144
+
1145
+ <!-- =========================================================== -->
1146
+ <!-- W3C XLink 1.1 embedded simple links -->
1147
+ <!-- =========================================================== -->
1148
+ <xslt:template
1149
+ match="*[@xlink:href][not(parent::*[@xlink:type='complex'])]
1150
+ [not(@xlink:type) or (@xlink:type='simple')]
1151
+ [@xlink:show='embed']
1152
+ [not(@xlink:actuate) or (@xlink:actuate='onLoad')]"
1153
+ mode="dsdl:go" priority="1">
1154
+
1155
+ <xsl:variable name="document-uri"
1156
+ select="substring-before(concat(@xlink:href,'#'), '#')" />
1157
+ <xsl:variable name="fragment-id"
1158
+ select="substring-after(@xlink:href, '#')" />
1159
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
1160
+ <xsl:value-of select="@xlink:href" />
1161
+ </xsl:processing-instruction>
1162
+ <xsl:choose>
1163
+ <xsl:when test="not( $include-xlink = 'true' )">
1164
+ <xslt:copy>
1165
+ <xslt:copy-of select="@*" />
1166
+ <xslt:apply-templates mode="dsdl:go" />
1167
+ </xslt:copy>
1168
+ </xsl:when>
1169
+ <xsl:otherwise>
1170
+ <xsl:choose>
1171
+
1172
+ <xsl:when
1173
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
1174
+ <xsl:message>
1175
+ Error: Impossible URL in XLink embedding
1176
+ link
1177
+ </xsl:message>
1178
+ </xsl:when>
1179
+
1180
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
1181
+ <xslt:when
1182
+ test="string-length( $document-uri ) = 0">
1183
+ <xslt:apply-templates mode="dsdl:go"
1184
+ select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
1185
+ | //*[@id= $fragment-id ]" />
1186
+ </xslt:when>
1187
+
1188
+ <xsl:when
1189
+ test="string-length( $fragment-id ) &gt; 0">
1190
+ <xsl:variable name="theDocument_1"
1191
+ select="document( $document-uri,/ )" />
1192
+ <xsl:if test="not($theDocument_1)">
1193
+ <xsl:message terminate="no">
1194
+ <xsl:text>Unable to open referenced included file: </xsl:text>
1195
+ <xsl:value-of select="@xlink:href" />
1196
+ </xsl:message>
1197
+ </xsl:if>
1198
+ <!-- use for-each to rebase id() to $theDocument -->
1199
+ <xsl:for-each select="$theDocument_1">
1200
+ <xsl:variable name="theFragment_1"
1201
+ select="$theDocument_1//*[@xml:id= $fragment-id ]
1202
+ | id( $fragment-id )
1203
+ | $theDocument_1//*[@id= $fragment-id ]" />
1204
+ <xsl:if test="not($theFragment_1)">
1205
+ <xsl:message terminate="no">
1206
+ <xsl:text>Unable to locate id attribute: </xsl:text>
1207
+ <xsl:value-of select="@xlink:href" />
1208
+ </xsl:message>
1209
+ </xsl:if>
1210
+ <xsl:apply-templates
1211
+ select=" $theFragment_1[1]" mode="dsdl:go" />
1212
+ </xsl:for-each>
1213
+ </xsl:when>
1214
+
1215
+ <xsl:otherwise>
1216
+ <xsl:variable name="theDocument_2"
1217
+ select="document( $document-uri,/ )" />
1218
+ <xsl:variable name="theFragment_2"
1219
+ select="$theDocument_2/*" />
1220
+
1221
+ <xsl:if test="not($theDocument_2)">
1222
+ <xsl:message terminate="no">
1223
+ <xsl:text>Unable to open referenced included file: </xsl:text>
1224
+ <xsl:value-of select="@xlink:href" />
1225
+ </xsl:message>
1226
+ </xsl:if>
1227
+
1228
+ <xsl:if test="not($theFragment_2)">
1229
+ <xsl:message terminate="no">
1230
+ <xsl:text>Unable to locate id attribute: </xsl:text>
1231
+ <xsl:value-of select="@xlink:href" />
1232
+ </xsl:message>
1233
+ </xsl:if>
1234
+ <xsl:apply-templates select="$theFragment_2 "
1235
+ mode="dsdl:go" />
1236
+ </xsl:otherwise>
1237
+ </xsl:choose>
1238
+
1239
+ </xsl:otherwise>
1240
+ </xsl:choose>
1241
+
1242
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
1243
+ <xsl:value-of select="@xlink:href" />
1244
+ </xsl:processing-instruction>
1245
+ </xslt:template>
1246
+
1247
+ <!-- ================================================================= -->
1248
+ <!-- UTILITY TEMPLATES -->
1249
+ <!-- ================================================================= -->
1250
+
1251
+ <!-- MESSAGE WHEN XPATH NOT WELL FORMED -->
1252
+
1253
+ <xsl:template name="sch-check:xpath-wf-message" >
1254
+ <xsl:param name="string" />
1255
+ <xsl:param name="subject" />
1256
+ <xsl:variable name="xpath-wf-result">
1257
+ <xsl:call-template name="sch-check:xpath-wf">
1258
+ <xsl:with-param name="string" select=" $string " />
1259
+ </xsl:call-template>
1260
+ </xsl:variable>
1261
+
1262
+ <xsl:if test="string-length($xpath-wf-result) > 0">
1263
+ <xsl:message><xsl:value-of select="$subject"/><xsl:value-of select="$xpath-wf-result" /></xsl:message>
1264
+ </xsl:if>
1265
+ </xsl:template>
1266
+
1267
+ <!-- XPATH WELL FORMED -->
1268
+
1269
+ <xsl:template name="sch-check:xpath-wf" >
1270
+ <xsl:param name="string" />
1271
+ <!-- This does some minimal checks to see if a string is well-formed XPath.
1272
+ It checks
1273
+ 1) String is not empty,
1274
+ 2) equal number of open and close parens
1275
+ 3) equal number of left and right square brackets
1276
+ 4) if there is a predicate open immediately following a step separator
1277
+ It does not check balancing. It does not check inside string literals in XPaths.
1278
+
1279
+ If there is no error, empty content is returned. If there is an error, it is given
1280
+ as an error message. This is not localized yet.
1281
+ -->
1282
+
1283
+
1284
+ <xsl:variable name="stripped-contents">
1285
+ <xsl:call-template name="sch-check:strip-strings" >
1286
+ <xsl:with-param name="string" select=" $string " />
1287
+ <xsl:with-param name="mode" select=" 0" />
1288
+ </xsl:call-template>
1289
+ </xsl:variable>
1290
+
1291
+
1292
+ <xsl:variable name="paren-result">
1293
+ <xsl:call-template name="sch-check:test-paren" >
1294
+ <xsl:with-param name="string" select="$stripped-contents" />
1295
+ <xsl:with-param name="count" select=" 0" />
1296
+ </xsl:call-template>
1297
+ </xsl:variable>
1298
+
1299
+
1300
+ <xsl:variable name="sqb-result">
1301
+ <xsl:call-template name="sch-check:test-sqb" >
1302
+ <xsl:with-param name="string" select="$stripped-contents" />
1303
+ <xsl:with-param name="count" select=" 0" />
1304
+ </xsl:call-template>
1305
+ </xsl:variable>
1306
+
1307
+
1308
+ <xsl:choose>
1309
+ <xsl:when test="string-length( normalize-space($string)) = 0"
1310
+ >XPath error. No XPath.</xsl:when>
1311
+ <xsl:when test="contains( $stripped-contents, '/[' )"
1312
+ >XPath error. Missing location step. Suggestion: remove '/' before '['.
1313
+ <xsl:value-of select=" normalize-space($string)"/></xsl:when>
1314
+ <!-- not implemented yet
1315
+ <xsl:when test=" count () mod 2 = 1"
1316
+ >XPath syntax error. Odd number of apostrophe characters. Suggestion: check string termination and delimiting.
1317
+ <xsl:value-of select=" normalize-space($string)"/></xsl:when>
1318
+ <xsl:when test=" count ( ) mod 2 = 1"
1319
+ >XPath syntax error. Odd number of quote characters. Suggestion: check string termination and delimiting.
1320
+ <xsl:value-of select=" normalize-space($string)"/></xsl:when>
1321
+ -->
1322
+ <xsl:when test=" $paren-result > 0 "
1323
+ >XPath syntax error. Unclosed parenthesis. Suggestion: add ')'.
1324
+ <xsl:value-of select=" normalize-space($string)"/></xsl:when>
1325
+ <xsl:when test=" $paren-result &lt; 0 "
1326
+ >XPath syntax error. Extra close parenthesis. Suggestion: remove ')'.
1327
+ <xsl:value-of select=" normalize-space($string)"/></xsl:when>
1328
+
1329
+ <xsl:when test=" $sqb-result > 0 "
1330
+ >XPath syntax error. Unclosed left square bracket. Suggestion: add ']'.
1331
+ <xsl:value-of select=" normalize-space($string)"/></xsl:when>
1332
+ <xsl:when test=" $sqb-result &lt; 0 "
1333
+ >XPath syntax error. Extra right square bracket. Suggestion: remove ']'.
1334
+ <xsl:value-of select=" normalize-space($string)"/></xsl:when>
1335
+
1336
+ </xsl:choose>
1337
+
1338
+
1339
+
1340
+ </xsl:template>
1341
+
1342
+
1343
+ <!-- STRIP XPATH STRINGS -->
1344
+ <xsl:template name="sch-check:strip-strings">
1345
+ <xsl:param name="string" />
1346
+ <xsl:param name="mode" />
1347
+
1348
+ <!--
1349
+ mode 0 = outside string
1350
+ mode 1 = in double quote string
1351
+ mode 2 = in single quote string
1352
+ -->
1353
+ <xsl:choose>
1354
+ <xsl:when test=" string-length( $string) = 0" />
1355
+ <xsl:when test="$mode = 1 ">
1356
+ <xsl:choose>
1357
+
1358
+
1359
+ <xsl:when test="starts-with( $string, '&quot;&quot;') " >
1360
+
1361
+ <xsl:call-template name="sch-check:strip-strings">
1362
+ <xsl:with-param name="string" select=" substring ( $string, 3 )"/>
1363
+ <xsl:with-param name="mode" select=" $mode" />
1364
+ </xsl:call-template>
1365
+ </xsl:when>
1366
+ <xsl:when test="starts-with( $string, '&quot;') " >
1367
+ <xsl:call-template name="sch-check:strip-strings">
1368
+ <xsl:with-param name="string" select=" substring ( $string, 2 )"/>
1369
+ <xsl:with-param name="mode" select=" 0 " />
1370
+ </xsl:call-template>
1371
+ </xsl:when>
1372
+
1373
+ <xsl:otherwise>
1374
+ <xsl:call-template name="sch-check:strip-strings">
1375
+ <xsl:with-param name="string" select=" substring ( $string, 2 )"/>
1376
+ <xsl:with-param name="mode" select=" $mode " />
1377
+ </xsl:call-template>
1378
+ </xsl:otherwise>
1379
+ </xsl:choose>
1380
+ </xsl:when>
1381
+
1382
+ <xsl:when test="$mode = 2 ">
1383
+ <xsl:choose>
1384
+
1385
+ <!-- doubled double quote or double apos is an escape -->
1386
+ <xsl:when test="starts-with( $string, &quot;''&quot;) " >
1387
+ <xsl:call-template name="sch-check:strip-strings">
1388
+ <xsl:with-param name="string" select=" substring ( $string, 3 )"/>
1389
+ <xsl:with-param name="mode" select=" $mode" />
1390
+ </xsl:call-template>
1391
+ </xsl:when>
1392
+ <xsl:when test="starts-with( $string, &quot;'&quot; )" >
1393
+ <xsl:call-template name="sch-check:strip-strings">
1394
+ <xsl:with-param name="string" select=" substring ( $string, 2 )"/>
1395
+ <xsl:with-param name="mode" select=" 0 " />
1396
+ </xsl:call-template>
1397
+ </xsl:when>
1398
+ <xsl:otherwise>
1399
+ <xsl:call-template name="sch-check:strip-strings">
1400
+ <xsl:with-param name="string" select=" substring ( $string, 2 )"/>
1401
+ <xsl:with-param name="mode" select=" $mode " />
1402
+ </xsl:call-template>
1403
+ </xsl:otherwise>
1404
+ </xsl:choose>
1405
+ </xsl:when>
1406
+
1407
+ <xsl:otherwise> <!-- mode = 0 -->
1408
+ <xsl:choose>
1409
+ <xsl:when test="starts-with( $string, '&quot;')" >
1410
+ <xsl:call-template name="sch-check:strip-strings">
1411
+ <xsl:with-param name="string" select=" substring ( $string, 2 )"/>
1412
+ <xsl:with-param name="mode" select=" 1 " />
1413
+ </xsl:call-template>
1414
+ </xsl:when>
1415
+
1416
+ <xsl:when test="starts-with( $string, &quot;'&quot; )" >
1417
+ <xsl:call-template name="sch-check:strip-strings">
1418
+ <xsl:with-param name="string" select=" substring ( $string, 2 )"/>
1419
+ <xsl:with-param name="mode" select=" 2 " />
1420
+ </xsl:call-template>
1421
+ </xsl:when>
1422
+ <xsl:otherwise>
1423
+ <xsl:value-of select="substring( $string, 1, 1)" />
1424
+ <xsl:call-template name="sch-check:strip-strings">
1425
+
1426
+ <xsl:with-param name="string" select=" substring ( $string, 2 )"/>
1427
+ <xsl:with-param name="mode" select=" $mode " />
1428
+ </xsl:call-template>
1429
+ </xsl:otherwise>
1430
+ </xsl:choose>
1431
+ </xsl:otherwise>
1432
+ </xsl:choose>
1433
+
1434
+
1435
+ </xsl:template>
1436
+
1437
+ <!-- COUNT THE NUMBER OF UNMATCHED PARENTHESES -->
1438
+ <!-- Limitation: Does not check balancing. -->
1439
+
1440
+ <xsl:template name="sch-check:test-paren">
1441
+ <xsl:param name="string" />
1442
+ <xsl:param name="count" />
1443
+
1444
+ <xsl:choose>
1445
+ <xsl:when test=" string-length( $string) = 0">
1446
+ <xsl:value-of select=" $count " />
1447
+ </xsl:when>
1448
+ <xsl:when test=" starts-with( $string, '(') ">
1449
+ <xsl:call-template name="sch-check:test-paren">
1450
+ <xsl:with-param name="string" select=" substring ( $string, 2 )" />
1451
+ <xsl:with-param name="count" select=" $count + 1 " />
1452
+ </xsl:call-template>
1453
+ </xsl:when>
1454
+ <xsl:when test=" starts-with( $string, ')') ">
1455
+ <xsl:call-template name="sch-check:test-paren">
1456
+ <xsl:with-param name="string" select=" substring ( $string, 2 )"/>
1457
+ <xsl:with-param name="count" select="$count - 1 " />
1458
+ </xsl:call-template>
1459
+ </xsl:when>
1460
+ <xsl:otherwise>
1461
+ <xsl:call-template name="sch-check:test-paren">
1462
+ <xsl:with-param name="string" select=" substring ( $string, 2 )"/>
1463
+ <xsl:with-param name="count" select=" $count " />
1464
+ </xsl:call-template>
1465
+ </xsl:otherwise>
1466
+ </xsl:choose>
1467
+
1468
+
1469
+ </xsl:template>
1470
+
1471
+
1472
+ <!-- COUNT THE NUMBER OF SQUARE BRACKETS -->
1473
+ <!-- Limitation: Does not check balancing. -->
1474
+ <xsl:template name="sch-check:test-sqb">
1475
+ <xsl:param name="string" />
1476
+ <xsl:param name="count" />
1477
+
1478
+ <xsl:choose>
1479
+ <xsl:when test=" string-length( $string) = 0">
1480
+ <xsl:value-of select=" $count " />
1481
+ </xsl:when>
1482
+ <xsl:when test=" starts-with( $string, '[') ">
1483
+ <xsl:call-template name="sch-check:test-sqb">
1484
+ <xsl:with-param name="string" select=" substring ( $string, 2 )" />
1485
+ <xsl:with-param name="count" select=" $count + 1 " />
1486
+ </xsl:call-template>
1487
+ </xsl:when>
1488
+ <xsl:when test=" starts-with( $string, ']') ">
1489
+ <xsl:call-template name="sch-check:test-sqb">
1490
+ <xsl:with-param name="string" select=" substring ( $string, 2 )"/>
1491
+ <xsl:with-param name="count" select="$count - 1 " />
1492
+ </xsl:call-template>
1493
+ </xsl:when>
1494
+ <xsl:otherwise>
1495
+ <xsl:call-template name="sch-check:test-sqb">
1496
+ <xsl:with-param name="string" select=" substring ( $string, 2 )"/>
1497
+ <xsl:with-param name="count" select=" $count " />
1498
+ </xsl:call-template>
1499
+ </xsl:otherwise>
1500
+ </xsl:choose>
1501
+
1502
+
1503
+ </xsl:template>
1504
+
1505
+
1506
+
1507
+
1508
+
1509
+ </xslt:stylesheet>