schematron-wrapper 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +6 -0
- data/LICENSE +354 -0
- data/README.md +37 -0
- data/Rakefile +10 -0
- data/bin/saxon9he.jar +0 -0
- data/iso-schematron-xslt2/ExtractSchFromRNG-2.xsl +75 -0
- data/iso-schematron-xslt2/ExtractSchFromXSD-2.xsl +77 -0
- data/iso-schematron-xslt2/iso_abstract_expand.xsl +297 -0
- data/iso-schematron-xslt2/iso_dsdl_include.xsl +1508 -0
- data/iso-schematron-xslt2/iso_schematron_message_xslt2.xsl +55 -0
- data/iso-schematron-xslt2/iso_schematron_skeleton_for_saxon.xsl +2299 -0
- data/iso-schematron-xslt2/iso_svrl_for_xslt2.xsl +684 -0
- data/iso-schematron-xslt2/readme.txt +100 -0
- data/iso-schematron-xslt2/sch-messages-cs.xhtml +56 -0
- data/iso-schematron-xslt2/sch-messages-de.xhtml +57 -0
- data/iso-schematron-xslt2/sch-messages-en.xhtml +57 -0
- data/iso-schematron-xslt2/sch-messages-fr.xhtml +54 -0
- data/iso-schematron-xslt2/sch-messages-nl.xhtml +58 -0
- data/iso-schematron-xslt2/schematron-skeleton-api.htm +723 -0
- data/lib/schematron.rb +6 -0
- data/lib/schematron/utils.rb +29 -0
- data/lib/schematron/version.rb +4 -0
- data/lib/schematron/xslt2.rb +71 -0
- data/schematron_wrapper.gemspec +25 -0
- data/spec/lib/schematron/xslt2_spec.rb +50 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/samples/compiled.xsl +334 -0
- data/spec/support/samples/initial.sch +52 -0
- data/spec/support/samples/target.xml +1032 -0
- data/spec/support/samples/validation_result.xml +46 -0
- metadata +99 -0
@@ -0,0 +1,1508 @@
|
|
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 ) > 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 ) > 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 ) > 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 ) > 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 ) > 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 ) > 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 ) > 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 ) > 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
|
+
It does not check balancing. It does not check inside string literals in XPaths.
|
1277
|
+
|
1278
|
+
If there is no error, empty content is returned. If there is an error, it is given
|
1279
|
+
as an error message. This is not localized yet.
|
1280
|
+
-->
|
1281
|
+
|
1282
|
+
|
1283
|
+
<xsl:variable name="stripped-contents">
|
1284
|
+
<xsl:call-template name="sch-check:strip-strings" >
|
1285
|
+
<xsl:with-param name="string" select=" $string " />
|
1286
|
+
<xsl:with-param name="mode" select=" 0" />
|
1287
|
+
</xsl:call-template>
|
1288
|
+
</xsl:variable>
|
1289
|
+
|
1290
|
+
|
1291
|
+
<xsl:variable name="paren-result">
|
1292
|
+
<xsl:call-template name="sch-check:test-paren" >
|
1293
|
+
<xsl:with-param name="string" select="$stripped-contents" />
|
1294
|
+
<xsl:with-param name="count" select=" 0" />
|
1295
|
+
</xsl:call-template>
|
1296
|
+
</xsl:variable>
|
1297
|
+
|
1298
|
+
|
1299
|
+
<xsl:variable name="sqb-result">
|
1300
|
+
<xsl:call-template name="sch-check:test-sqb" >
|
1301
|
+
<xsl:with-param name="string" select="$stripped-contents" />
|
1302
|
+
<xsl:with-param name="count" select=" 0" />
|
1303
|
+
</xsl:call-template>
|
1304
|
+
</xsl:variable>
|
1305
|
+
|
1306
|
+
|
1307
|
+
<xsl:choose>
|
1308
|
+
<xsl:when test="string-length( normalize-space($string)) = 0"
|
1309
|
+
>XPath error. No XPath.</xsl:when>
|
1310
|
+
<xsl:when test="contains( $stripped-contents, '/[' )"
|
1311
|
+
>XPath error. Missing location step. Suggestion: remove '/' before '['.
|
1312
|
+
<xsl:value-of select=" normalize-space($string)"/></xsl:when>
|
1313
|
+
<!-- not implemented yet
|
1314
|
+
<xsl:when test=" count () mod 2 = 1"
|
1315
|
+
>XPath syntax error. Odd number of apostrophe characters. Suggestion: check string termination and delimiting.
|
1316
|
+
<xsl:value-of select=" normalize-space($string)"/></xsl:when>
|
1317
|
+
<xsl:when test=" count ( ) mod 2 = 1"
|
1318
|
+
>XPath syntax error. Odd number of quote characters. Suggestion: check string termination and delimiting.
|
1319
|
+
<xsl:value-of select=" normalize-space($string)"/></xsl:when>
|
1320
|
+
-->
|
1321
|
+
<xsl:when test=" $paren-result > 0 "
|
1322
|
+
>XPath syntax error. Unclosed parenthesis. Suggestion: add ')'.
|
1323
|
+
<xsl:value-of select=" normalize-space($string)"/></xsl:when>
|
1324
|
+
<xsl:when test=" $paren-result < 0 "
|
1325
|
+
>XPath syntax error. Extra close parenthesis. Suggestion: remove ')'.
|
1326
|
+
<xsl:value-of select=" normalize-space($string)"/></xsl:when>
|
1327
|
+
|
1328
|
+
<xsl:when test=" $sqb-result > 0 "
|
1329
|
+
>XPath syntax error. Unclosed left square bracket. Suggestion: add ']'.
|
1330
|
+
<xsl:value-of select=" normalize-space($string)"/></xsl:when>
|
1331
|
+
<xsl:when test=" $sqb-result < 0 "
|
1332
|
+
>XPath syntax error. Extra right square bracket. Suggestion: remove ']'.
|
1333
|
+
<xsl:value-of select=" normalize-space($string)"/></xsl:when>
|
1334
|
+
|
1335
|
+
</xsl:choose>
|
1336
|
+
|
1337
|
+
|
1338
|
+
|
1339
|
+
</xsl:template>
|
1340
|
+
|
1341
|
+
|
1342
|
+
<!-- STRIP XPATH STRINGS -->
|
1343
|
+
<xsl:template name="sch-check:strip-strings">
|
1344
|
+
<xsl:param name="string" />
|
1345
|
+
<xsl:param name="mode" />
|
1346
|
+
|
1347
|
+
<!--
|
1348
|
+
mode 0 = outside string
|
1349
|
+
mode 1 = in double quote string
|
1350
|
+
mode 2 = in single quote string
|
1351
|
+
-->
|
1352
|
+
<xsl:choose>
|
1353
|
+
<xsl:when test=" string-length( $string) = 0" />
|
1354
|
+
<xsl:when test="$mode = 1 ">
|
1355
|
+
<xsl:choose>
|
1356
|
+
|
1357
|
+
|
1358
|
+
<xsl:when test="starts-with( $string, '""') " >
|
1359
|
+
|
1360
|
+
<xsl:call-template name="sch-check:strip-strings">
|
1361
|
+
<xsl:with-param name="string" select=" substring ( $string, 3 )"/>
|
1362
|
+
<xsl:with-param name="mode" select=" $mode" />
|
1363
|
+
</xsl:call-template>
|
1364
|
+
</xsl:when>
|
1365
|
+
<xsl:when test="starts-with( $string, '"') " >
|
1366
|
+
<xsl:call-template name="sch-check:strip-strings">
|
1367
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )"/>
|
1368
|
+
<xsl:with-param name="mode" select=" 0 " />
|
1369
|
+
</xsl:call-template>
|
1370
|
+
</xsl:when>
|
1371
|
+
|
1372
|
+
<xsl:otherwise>
|
1373
|
+
<xsl:call-template name="sch-check:strip-strings">
|
1374
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )"/>
|
1375
|
+
<xsl:with-param name="mode" select=" $mode " />
|
1376
|
+
</xsl:call-template>
|
1377
|
+
</xsl:otherwise>
|
1378
|
+
</xsl:choose>
|
1379
|
+
</xsl:when>
|
1380
|
+
|
1381
|
+
<xsl:when test="$mode = 2 ">
|
1382
|
+
<xsl:choose>
|
1383
|
+
|
1384
|
+
<!-- doubled double quote or double apos is an escape -->
|
1385
|
+
<xsl:when test="starts-with( $string, "''") " >
|
1386
|
+
<xsl:call-template name="sch-check:strip-strings">
|
1387
|
+
<xsl:with-param name="string" select=" substring ( $string, 3 )"/>
|
1388
|
+
<xsl:with-param name="mode" select=" $mode" />
|
1389
|
+
</xsl:call-template>
|
1390
|
+
</xsl:when>
|
1391
|
+
<xsl:when test="starts-with( $string, "'" )" >
|
1392
|
+
<xsl:call-template name="sch-check:strip-strings">
|
1393
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )"/>
|
1394
|
+
<xsl:with-param name="mode" select=" 0 " />
|
1395
|
+
</xsl:call-template>
|
1396
|
+
</xsl:when>
|
1397
|
+
<xsl:otherwise>
|
1398
|
+
<xsl:call-template name="sch-check:strip-strings">
|
1399
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )"/>
|
1400
|
+
<xsl:with-param name="mode" select=" $mode " />
|
1401
|
+
</xsl:call-template>
|
1402
|
+
</xsl:otherwise>
|
1403
|
+
</xsl:choose>
|
1404
|
+
</xsl:when>
|
1405
|
+
|
1406
|
+
<xsl:otherwise> <!-- mode = 0 -->
|
1407
|
+
<xsl:choose>
|
1408
|
+
<xsl:when test="starts-with( $string, '"')" >
|
1409
|
+
<xsl:call-template name="sch-check:strip-strings">
|
1410
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )"/>
|
1411
|
+
<xsl:with-param name="mode" select=" 1 " />
|
1412
|
+
</xsl:call-template>
|
1413
|
+
</xsl:when>
|
1414
|
+
|
1415
|
+
<xsl:when test="starts-with( $string, "'" )" >
|
1416
|
+
<xsl:call-template name="sch-check:strip-strings">
|
1417
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )"/>
|
1418
|
+
<xsl:with-param name="mode" select=" 2 " />
|
1419
|
+
</xsl:call-template>
|
1420
|
+
</xsl:when>
|
1421
|
+
<xsl:otherwise>
|
1422
|
+
<xsl:value-of select="substring( $string, 1, 1)" />
|
1423
|
+
<xsl:call-template name="sch-check:strip-strings">
|
1424
|
+
|
1425
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )"/>
|
1426
|
+
<xsl:with-param name="mode" select=" $mode " />
|
1427
|
+
</xsl:call-template>
|
1428
|
+
</xsl:otherwise>
|
1429
|
+
</xsl:choose>
|
1430
|
+
</xsl:otherwise>
|
1431
|
+
</xsl:choose>
|
1432
|
+
|
1433
|
+
|
1434
|
+
</xsl:template>
|
1435
|
+
|
1436
|
+
<!-- COUNT THE NUMBER OF UNMATCHED PARENTHESES -->
|
1437
|
+
<!-- Limitation: Does not check balancing. -->
|
1438
|
+
|
1439
|
+
<xsl:template name="sch-check:test-paren">
|
1440
|
+
<xsl:param name="string" />
|
1441
|
+
<xsl:param name="count" />
|
1442
|
+
|
1443
|
+
<xsl:choose>
|
1444
|
+
<xsl:when test=" string-length( $string) = 0">
|
1445
|
+
<xsl:value-of select=" $count " />
|
1446
|
+
</xsl:when>
|
1447
|
+
<xsl:when test=" starts-with( $string, '(') ">
|
1448
|
+
<xsl:call-template name="sch-check:test-paren">
|
1449
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )" />
|
1450
|
+
<xsl:with-param name="count" select=" $count + 1 " />
|
1451
|
+
</xsl:call-template>
|
1452
|
+
</xsl:when>
|
1453
|
+
<xsl:when test=" starts-with( $string, ')') ">
|
1454
|
+
<xsl:call-template name="sch-check:test-paren">
|
1455
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )"/>
|
1456
|
+
<xsl:with-param name="count" select="$count - 1 " />
|
1457
|
+
</xsl:call-template>
|
1458
|
+
</xsl:when>
|
1459
|
+
<xsl:otherwise>
|
1460
|
+
<xsl:call-template name="sch-check:test-paren">
|
1461
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )"/>
|
1462
|
+
<xsl:with-param name="count" select=" $count " />
|
1463
|
+
</xsl:call-template>
|
1464
|
+
</xsl:otherwise>
|
1465
|
+
</xsl:choose>
|
1466
|
+
|
1467
|
+
|
1468
|
+
</xsl:template>
|
1469
|
+
|
1470
|
+
|
1471
|
+
<!-- COUNT THE NUMBER OF SQUARE BRACKETS -->
|
1472
|
+
<!-- Limitation: Does not check balancing. -->
|
1473
|
+
<xsl:template name="sch-check:test-sqb">
|
1474
|
+
<xsl:param name="string" />
|
1475
|
+
<xsl:param name="count" />
|
1476
|
+
|
1477
|
+
<xsl:choose>
|
1478
|
+
<xsl:when test=" string-length( $string) = 0">
|
1479
|
+
<xsl:value-of select=" $count " />
|
1480
|
+
</xsl:when>
|
1481
|
+
<xsl:when test=" starts-with( $string, '[') ">
|
1482
|
+
<xsl:call-template name="sch-check:test-sqb">
|
1483
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )" />
|
1484
|
+
<xsl:with-param name="count" select=" $count + 1 " />
|
1485
|
+
</xsl:call-template>
|
1486
|
+
</xsl:when>
|
1487
|
+
<xsl:when test=" starts-with( $string, ']') ">
|
1488
|
+
<xsl:call-template name="sch-check:test-sqb">
|
1489
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )"/>
|
1490
|
+
<xsl:with-param name="count" select="$count - 1 " />
|
1491
|
+
</xsl:call-template>
|
1492
|
+
</xsl:when>
|
1493
|
+
<xsl:otherwise>
|
1494
|
+
<xsl:call-template name="sch-check:test-sqb">
|
1495
|
+
<xsl:with-param name="string" select=" substring ( $string, 2 )"/>
|
1496
|
+
<xsl:with-param name="count" select=" $count " />
|
1497
|
+
</xsl:call-template>
|
1498
|
+
</xsl:otherwise>
|
1499
|
+
</xsl:choose>
|
1500
|
+
|
1501
|
+
|
1502
|
+
</xsl:template>
|
1503
|
+
|
1504
|
+
|
1505
|
+
|
1506
|
+
|
1507
|
+
|
1508
|
+
</xslt:stylesheet>
|