schematron 0.1.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.semver +5 -0
- data/README.md +4 -4
- data/bin/stron +21 -14
- data/{iso_impl → iso-schematron-xslt1}/iso_abstract_expand.xsl +2 -1
- data/iso-schematron-xslt1/iso_dsdl_include.xsl +1160 -0
- data/iso-schematron-xslt1/iso_schematron_message.xsl +55 -0
- data/{iso_impl → iso-schematron-xslt1}/iso_schematron_skeleton_for_xslt1.xsl +108 -36
- data/{iso_impl/iso_svrl.xsl → iso-schematron-xslt1/iso_svrl_for_xslt1.xsl} +16 -11
- data/iso-schematron-xslt1/readme.txt +83 -0
- data/lib/schematron.rb +3 -3
- data/schematron.gemspec +8 -27
- metadata +19 -9
- data/Rakefile +0 -14
- data/iso_impl/iso_dsdl_include.xsl +0 -989
- data/iso_impl/iso_schematron_skeleton_for_saxon.xsl +0 -1884
- data/iso_impl/iso_schematron_text.xsl +0 -126
@@ -0,0 +1,1160 @@
|
|
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
|
+
2009-02-25
|
45
|
+
* Update DSDL namespace to use schematron.com
|
46
|
+
* Tested with SAXON9, Xalan 2.7.1, IE7,
|
47
|
+
* IE does not like multiple variables in same template with same name: rename.
|
48
|
+
2008-09-18
|
49
|
+
* Remove new behaviour for include, because it conflicts with existing usage [KH]
|
50
|
+
* Add extends[@href] element with that merge functionality
|
51
|
+
* Generate PIs to notate source of inclusions for potential better diagnostics
|
52
|
+
|
53
|
+
2008-09-16
|
54
|
+
* Fix for XSLT1
|
55
|
+
|
56
|
+
2008-08-28
|
57
|
+
* New behaviour for schematron includes: if the pointed to element is the same as the current,
|
58
|
+
include the children.
|
59
|
+
|
60
|
+
2008-08-20
|
61
|
+
* Fix bug: in XSLT1 cannot do $document/id('x') but need to use for-each
|
62
|
+
|
63
|
+
2008-08-04
|
64
|
+
* Add support for inclusions in old namespace
|
65
|
+
|
66
|
+
2008-08-03
|
67
|
+
* Fix wrong param name include-relaxng & include-crdl (KH, PH)
|
68
|
+
* Allow inclusion of XSLT and XHTML (KH)
|
69
|
+
* Fix inclusion of fragments (KH)
|
70
|
+
|
71
|
+
2008-07-25
|
72
|
+
* Add selectable input parameter
|
73
|
+
|
74
|
+
2008-07-24
|
75
|
+
* RJ New
|
76
|
+
-->
|
77
|
+
<!--
|
78
|
+
LEGAL INFORMATION
|
79
|
+
|
80
|
+
Copyright (c) 2008 Rick Jelliffe
|
81
|
+
|
82
|
+
This software is provided 'as-is', without any express or implied warranty.
|
83
|
+
In no event will the authors be held liable for any damages arising from
|
84
|
+
the use of this software.
|
85
|
+
|
86
|
+
Permission is granted to anyone to use this software for any purpose,
|
87
|
+
including commercial applications, and to alter it and redistribute it freely,
|
88
|
+
subject to the following restrictions:
|
89
|
+
|
90
|
+
1. The origin of this software must not be misrepresented; you must not claim
|
91
|
+
that you wrote the original software. If you use this software in a product,
|
92
|
+
an acknowledgment in the product documentation would be appreciated but is
|
93
|
+
not required.
|
94
|
+
|
95
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
96
|
+
misrepresented as being the original software.
|
97
|
+
|
98
|
+
3. This notice may not be removed or altered from any source distribution.
|
99
|
+
-->
|
100
|
+
<xslt:stylesheet version="1.0"
|
101
|
+
xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
|
102
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
103
|
+
xmlns:iso="http://purl.oclc.org/dsdl/schematron"
|
104
|
+
xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl"
|
105
|
+
xmlns:xhtml="http://www.w3.org/1999/xhtml"
|
106
|
+
xmlns:schold="http://www.ascc.net/xml/schematron"
|
107
|
+
xmlns:crdl="http://purl.oclc.org/dsdl/crepdl/ns/structure/1.0"
|
108
|
+
xmlns:xi="http://www.w3.org/2001/XInclude"
|
109
|
+
xmlns:dtll="http://www.jenitennison.com/datatypes"
|
110
|
+
xmlns:dsdl="http://www.schematron.com/namespace/dsdl"
|
111
|
+
xmlns:relax="http://relaxng.org/ns/structure/1.0"
|
112
|
+
xmlns:xlink="http://www.w3.org/1999/xlink">
|
113
|
+
<!-- Note: The URL for the dsdl namespace is not official -->
|
114
|
+
|
115
|
+
|
116
|
+
<xsl:param name="include-schematron">true</xsl:param>
|
117
|
+
<xsl:param name="include-crdl">true</xsl:param>
|
118
|
+
<xsl:param name="include-xinclude">true</xsl:param>
|
119
|
+
<xsl:param name="include-dtll">true</xsl:param>
|
120
|
+
<xsl:param name="include-relaxng">true</xsl:param>
|
121
|
+
<xsl:param name="include-xlink">true</xsl:param>
|
122
|
+
|
123
|
+
<xsl:template match="/">
|
124
|
+
<xsl:apply-templates select="." mode="dsdl:go" />
|
125
|
+
</xsl:template>
|
126
|
+
|
127
|
+
<!-- output everything else unchanged -->
|
128
|
+
<xslt:template match="node()" priority="-1" mode="dsdl:go">
|
129
|
+
<xslt:copy>
|
130
|
+
<xslt:copy-of select="@*" />
|
131
|
+
<xslt:apply-templates mode="dsdl:go" />
|
132
|
+
</xslt:copy>
|
133
|
+
</xslt:template>
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
<!-- =========================================================== -->
|
138
|
+
<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
|
139
|
+
<!-- Part 2 - Regular grammar-based validation - RELAX NG -->
|
140
|
+
<!-- This only implements relax:extRef not relax:include which -->
|
141
|
+
<!-- is complex. -->
|
142
|
+
<!-- =========================================================== -->
|
143
|
+
<xslt:template match="relax:extRef" mode="dsdl:go">
|
144
|
+
|
145
|
+
|
146
|
+
<!-- Insert subschema -->
|
147
|
+
|
148
|
+
<xsl:variable name="document-uri"
|
149
|
+
select="substring-before(concat(@href,'#'), '#')" />
|
150
|
+
<xsl:variable name="fragment-id"
|
151
|
+
select="substring-after(@href, '#')" />
|
152
|
+
|
153
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
154
|
+
<xsl:value-of select="@href" />
|
155
|
+
</xsl:processing-instruction>
|
156
|
+
<xsl:choose>
|
157
|
+
<xsl:when test="not( $include-relaxng = 'true' )">
|
158
|
+
<xslt:copy>
|
159
|
+
<xslt:copy-of select="@*" />
|
160
|
+
<xslt:apply-templates mode="dsdl:go" />
|
161
|
+
</xslt:copy>
|
162
|
+
</xsl:when>
|
163
|
+
<xsl:otherwise>
|
164
|
+
|
165
|
+
<xsl:choose>
|
166
|
+
|
167
|
+
<xsl:when
|
168
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
169
|
+
<xsl:message>
|
170
|
+
Error: Impossible URL in RELAX NG extRef
|
171
|
+
include
|
172
|
+
</xsl:message>
|
173
|
+
</xsl:when>
|
174
|
+
|
175
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
176
|
+
<xslt:when
|
177
|
+
test="string-length( $document-uri ) = 0">
|
178
|
+
<xslt:apply-templates mode="dsdl:go"
|
179
|
+
select="//*[@xml:id= $fragment-id ] | id( $fragment-id) | //*[@id= $fragment-id ]" />
|
180
|
+
</xslt:when>
|
181
|
+
|
182
|
+
<xsl:when
|
183
|
+
test="string-length( $fragment-id ) > 0">
|
184
|
+
<xsl:variable name="theDocument_1"
|
185
|
+
select="document( $document-uri,/ )" />
|
186
|
+
|
187
|
+
<xsl:if test="not($theDocument_1)">
|
188
|
+
<xsl:message terminate="no">
|
189
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
190
|
+
<xsl:value-of select="@href" />
|
191
|
+
</xsl:message>
|
192
|
+
</xsl:if>
|
193
|
+
<!-- use a for-each so that the id() function works correctly on the external document -->
|
194
|
+
<xsl:for-each select="$theDocument_1">
|
195
|
+
<xsl:variable name="theFragment_1"
|
196
|
+
select="$theDocument_1//*[@xml:id= $fragment-id ]
|
197
|
+
| id( $fragment-id)
|
198
|
+
| $theDocument_1//*[@id= $fragment-id ]" />
|
199
|
+
<xsl:if test="not($theFragment_1)">
|
200
|
+
<xsl:message terminate="no">
|
201
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
202
|
+
<xsl:value-of select="@href" />
|
203
|
+
</xsl:message>
|
204
|
+
</xsl:if>
|
205
|
+
<xsl:apply-templates
|
206
|
+
select=" $theFragment_1[1]" mode="dsdl:go" />
|
207
|
+
</xsl:for-each>
|
208
|
+
</xsl:when>
|
209
|
+
|
210
|
+
<xsl:otherwise>
|
211
|
+
<xsl:variable name="theDocument_2"
|
212
|
+
select="document( $document-uri,/ )" />
|
213
|
+
<xsl:variable name="theFragment_2"
|
214
|
+
select="$theDocument_2/*" />
|
215
|
+
<xsl:if test="not($theDocument_2)">
|
216
|
+
<xsl:message terminate="no">
|
217
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
218
|
+
<xsl:value-of select="@href" />
|
219
|
+
</xsl:message>
|
220
|
+
</xsl:if>
|
221
|
+
|
222
|
+
<xsl:if test="not($theFragment_2)">
|
223
|
+
<xsl:message terminate="no">
|
224
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
225
|
+
<xsl:value-of select="@href" />
|
226
|
+
</xsl:message>
|
227
|
+
</xsl:if>
|
228
|
+
<xsl:apply-templates select="$theFragment_2 "
|
229
|
+
mode="dsdl:go" />
|
230
|
+
</xsl:otherwise>
|
231
|
+
</xsl:choose>
|
232
|
+
|
233
|
+
</xsl:otherwise>
|
234
|
+
</xsl:choose>
|
235
|
+
|
236
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
237
|
+
<xsl:value-of select="@href" />
|
238
|
+
</xsl:processing-instruction>
|
239
|
+
</xslt:template>
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
<!-- =========================================================== -->
|
244
|
+
<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
|
245
|
+
<!-- Part 3 - Rule-based validation - Schematron -->
|
246
|
+
<!-- =========================================================== -->
|
247
|
+
|
248
|
+
|
249
|
+
<!-- Extend the URI syntax to allow # references -->
|
250
|
+
<!-- Add experimental support for simple containers like /xxx:xxx/iso:pattern to allow better includes -->
|
251
|
+
<xsl:template match="iso:include" mode="dsdl:go">
|
252
|
+
|
253
|
+
<xsl:variable name="document-uri"
|
254
|
+
select="substring-before(concat(@href,'#'), '#')" />
|
255
|
+
<xsl:variable name="fragment-id"
|
256
|
+
select="substring-after(@href, '#')" />
|
257
|
+
|
258
|
+
|
259
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
260
|
+
<xsl:value-of select="@href" />
|
261
|
+
</xsl:processing-instruction>
|
262
|
+
|
263
|
+
<xsl:choose>
|
264
|
+
<xsl:when test="not( $include-schematron = 'true' )">
|
265
|
+
<xslt:copy>
|
266
|
+
<xslt:copy-of select="@*" />
|
267
|
+
<xslt:apply-templates mode="dsdl:go" />
|
268
|
+
</xslt:copy>
|
269
|
+
</xsl:when>
|
270
|
+
<xsl:otherwise>
|
271
|
+
|
272
|
+
<xsl:choose>
|
273
|
+
|
274
|
+
<xsl:when
|
275
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
276
|
+
<xsl:message>
|
277
|
+
Error: Impossible URL in Schematron include
|
278
|
+
</xsl:message>
|
279
|
+
</xsl:when>
|
280
|
+
|
281
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
282
|
+
<xslt:when
|
283
|
+
test="string-length( $document-uri ) = 0">
|
284
|
+
<xslt:apply-templates mode="dsdl:go"
|
285
|
+
select="//iso:*[@xml:id= $fragment-id ]
|
286
|
+
|id( $fragment-id)
|
287
|
+
| //iso:*[@id= $fragment-id ]" />
|
288
|
+
</xslt:when>
|
289
|
+
|
290
|
+
<!-- case where there is a fragment in another document (should be an iso: element) -->
|
291
|
+
<!-- There are three cases for includes with fragment:
|
292
|
+
0) No href file or no matching id - error!
|
293
|
+
1) REMOVED
|
294
|
+
|
295
|
+
2) The linked-to element is sch:schema however the parent of the include
|
296
|
+
is not a schema. In this case, it is an error. (Actually, it should
|
297
|
+
be an error for other kinds of containment problems, but we won't
|
298
|
+
check for them in this version.)
|
299
|
+
|
300
|
+
3) Otherwise, include the pointed-to element
|
301
|
+
-->
|
302
|
+
|
303
|
+
<xsl:when
|
304
|
+
test="string-length( $fragment-id ) > 0">
|
305
|
+
<xsl:variable name="theDocument_1"
|
306
|
+
select="document( $document-uri,/ )" />
|
307
|
+
<xsl:variable name="originalParent" select=".." />
|
308
|
+
|
309
|
+
<!-- case 0 -->
|
310
|
+
<xsl:if test="not($theDocument_1)">
|
311
|
+
<xsl:message terminate="no">
|
312
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
313
|
+
<xsl:value-of select="@href" />
|
314
|
+
</xsl:message>
|
315
|
+
</xsl:if>
|
316
|
+
<!-- use for-each to rebase id() to external document -->
|
317
|
+
<xsl:for-each select="$theDocument_1">
|
318
|
+
<xsl:variable name="theFragment_1"
|
319
|
+
select=" $theDocument_1//iso:*[@xml:id= $fragment-id ] |
|
320
|
+
id($fragment-id) |
|
321
|
+
$theDocument_1//iso:*[@id= $fragment-id ]" />
|
322
|
+
|
323
|
+
|
324
|
+
<xsl:choose>
|
325
|
+
<!-- case 0 -->
|
326
|
+
<xsl:when test="not($theFragment_1)">
|
327
|
+
<xsl:message terminate="no">
|
328
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
329
|
+
<xsl:value-of select="@href" />
|
330
|
+
</xsl:message>
|
331
|
+
</xsl:when>
|
332
|
+
|
333
|
+
|
334
|
+
<!-- case 1 REMOVED -->
|
335
|
+
|
336
|
+
<!-- case 2 -->
|
337
|
+
<xsl:when
|
338
|
+
test=" $theFragment_1/self::iso:schema ">
|
339
|
+
<xsl:message>
|
340
|
+
Schema error: Use include to
|
341
|
+
include fragments, not a whole
|
342
|
+
schema
|
343
|
+
</xsl:message>
|
344
|
+
</xsl:when>
|
345
|
+
|
346
|
+
<!-- case 3 -->
|
347
|
+
<xsl:otherwise>
|
348
|
+
<xsl:apply-templates
|
349
|
+
select=" $theFragment_1[1]" mode="dsdl:go" />
|
350
|
+
</xsl:otherwise>
|
351
|
+
</xsl:choose>
|
352
|
+
</xsl:for-each>
|
353
|
+
</xsl:when>
|
354
|
+
|
355
|
+
<!-- Case where there is no ID so we include the whole document -->
|
356
|
+
<!-- Experimental addition: include fragments of children -->
|
357
|
+
<xsl:otherwise>
|
358
|
+
<xsl:variable name="theDocument_2"
|
359
|
+
select="document( $document-uri,/ )" />
|
360
|
+
<xsl:variable name="theFragment_2"
|
361
|
+
select="$theDocument_2/iso:*" />
|
362
|
+
<xsl:variable name="theContainedFragments"
|
363
|
+
select="$theDocument_2/*/iso:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
|
364
|
+
<xsl:if test="not($theDocument_2)">
|
365
|
+
<xsl:message terminate="no">
|
366
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
367
|
+
<xsl:value-of select="@href" />
|
368
|
+
</xsl:message>
|
369
|
+
</xsl:if>
|
370
|
+
|
371
|
+
<!-- There are three cases for includes:
|
372
|
+
0) No text specified- error!
|
373
|
+
|
374
|
+
1) REMOVED
|
375
|
+
|
376
|
+
2) The linked-to element is sch:schema however the parent of the include
|
377
|
+
is not a schema. In this case, it is an error. (Actually, it should
|
378
|
+
be an error for other kinds of containment problems, but we won't
|
379
|
+
check for them in this version.)
|
380
|
+
|
381
|
+
3) Otherwise, include the pointed-to element
|
382
|
+
-->
|
383
|
+
<xsl:choose>
|
384
|
+
<!-- case 0 -->
|
385
|
+
<xsl:when
|
386
|
+
test="not($theFragment_2) and not ($theContainedFragments)">
|
387
|
+
<xsl:message terminate="no">
|
388
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
389
|
+
<xsl:value-of select="@href" />
|
390
|
+
</xsl:message>
|
391
|
+
</xsl:when>
|
392
|
+
|
393
|
+
<!-- case 1 removed -->
|
394
|
+
|
395
|
+
<!-- case 2 -->
|
396
|
+
<xsl:when
|
397
|
+
test=" $theFragment_2/self::iso:schema or $theContainedFragments/self::iso:schema">
|
398
|
+
<xsl:message>
|
399
|
+
Schema error: Use include to include
|
400
|
+
fragments, not a whole schema
|
401
|
+
</xsl:message>
|
402
|
+
</xsl:when>
|
403
|
+
|
404
|
+
<!-- If this were XLST 2, we could use
|
405
|
+
if ($theFragment) then $theFragment else $theContainedFragments
|
406
|
+
here (thanks to KN)
|
407
|
+
-->
|
408
|
+
<!-- case 3 -->
|
409
|
+
<xsl:otherwise>
|
410
|
+
<xsl:apply-templates
|
411
|
+
select="$theFragment_2 " mode="dsdl:go" />
|
412
|
+
</xsl:otherwise>
|
413
|
+
</xsl:choose>
|
414
|
+
</xsl:otherwise>
|
415
|
+
</xsl:choose>
|
416
|
+
</xsl:otherwise>
|
417
|
+
</xsl:choose>
|
418
|
+
|
419
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
420
|
+
<xsl:value-of select="@href" />
|
421
|
+
</xsl:processing-instruction>
|
422
|
+
</xsl:template>
|
423
|
+
|
424
|
+
|
425
|
+
<!-- WARNING sch:extends[@href] is experimental and non standard -->
|
426
|
+
<!-- Basically, it adds the children of the selected element, not the element itself. -->
|
427
|
+
<xsl:template match="iso:extends[@href]" mode="dsdl:go">
|
428
|
+
|
429
|
+
<xsl:variable name="document-uri"
|
430
|
+
select="substring-before(concat(@href,'#'), '#')" />
|
431
|
+
<xsl:variable name="fragment-id"
|
432
|
+
select="substring-after(@href, '#')" />
|
433
|
+
|
434
|
+
|
435
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
436
|
+
<xsl:value-of select="@href" />
|
437
|
+
</xsl:processing-instruction>
|
438
|
+
|
439
|
+
<xsl:choose>
|
440
|
+
<xsl:when test="not( $include-schematron = 'true' )">
|
441
|
+
<xslt:copy>
|
442
|
+
<xslt:copy-of select="@*" />
|
443
|
+
<xslt:apply-templates mode="dsdl:go" />
|
444
|
+
</xslt:copy>
|
445
|
+
</xsl:when>
|
446
|
+
<xsl:otherwise>
|
447
|
+
|
448
|
+
<xsl:choose>
|
449
|
+
|
450
|
+
<xsl:when
|
451
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
452
|
+
<xsl:message>
|
453
|
+
Error: Impossible URL in Schematron include
|
454
|
+
</xsl:message>
|
455
|
+
</xsl:when>
|
456
|
+
|
457
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
458
|
+
<xslt:when
|
459
|
+
test="string-length( $document-uri ) = 0">
|
460
|
+
<xslt:apply-templates mode="dsdl:go"
|
461
|
+
select="//iso:*[@xml:id= $fragment-id ]/*
|
462
|
+
|id( $fragment-id)/*
|
463
|
+
| //iso:*[@id= $fragment-id ]/*" />
|
464
|
+
</xslt:when>
|
465
|
+
|
466
|
+
<!-- case where there is a fragment in another document (should be an iso: element) -->
|
467
|
+
<!-- There are three cases for includes with fragment:
|
468
|
+
0) No href file or no matching id - error!
|
469
|
+
1) REMOVED
|
470
|
+
|
471
|
+
2) REMOVED
|
472
|
+
|
473
|
+
3) Otherwise, include the pointed-to element
|
474
|
+
-->
|
475
|
+
|
476
|
+
<xsl:when
|
477
|
+
test="string-length( $fragment-id ) > 0">
|
478
|
+
<xsl:variable name="theDocument_1"
|
479
|
+
select="document( $document-uri,/ )" />
|
480
|
+
<xsl:variable name="originalParent" select=".." />
|
481
|
+
|
482
|
+
<!-- case 0 -->
|
483
|
+
<xsl:if test="not($theDocument_1)">
|
484
|
+
<xsl:message terminate="no">
|
485
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
486
|
+
<xsl:value-of select="@href" />
|
487
|
+
</xsl:message>
|
488
|
+
</xsl:if>
|
489
|
+
<!-- use for-each to rebase id() to external document -->
|
490
|
+
<xsl:for-each select="$theDocument_1">
|
491
|
+
<xsl:variable name="theFragment_1"
|
492
|
+
select=" $theDocument_1//iso:*[@xml:id= $fragment-id ] |
|
493
|
+
id($fragment-id) |
|
494
|
+
$theDocument_1//iso:*[@id= $fragment-id ]" />
|
495
|
+
|
496
|
+
|
497
|
+
<xsl:choose>
|
498
|
+
<!-- case 0 -->
|
499
|
+
<xsl:when test="not($theFragment_1)">
|
500
|
+
<xsl:message terminate="no">
|
501
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
502
|
+
<xsl:value-of select="@href" />
|
503
|
+
</xsl:message>
|
504
|
+
</xsl:when>
|
505
|
+
|
506
|
+
|
507
|
+
<!-- case 1 REMOVED -->
|
508
|
+
|
509
|
+
<!-- case 2 REMOVED -->
|
510
|
+
|
511
|
+
|
512
|
+
<!-- case 3 -->
|
513
|
+
<xsl:otherwise>
|
514
|
+
|
515
|
+
<xsl:apply-templates
|
516
|
+
select=" $theFragment_1[1]/*" mode="dsdl:go" />
|
517
|
+
</xsl:otherwise>
|
518
|
+
</xsl:choose>
|
519
|
+
</xsl:for-each>
|
520
|
+
</xsl:when>
|
521
|
+
|
522
|
+
<!-- Case where there is no ID so we include the whole document -->
|
523
|
+
<!-- Experimental addition: include fragments of children -->
|
524
|
+
<xsl:otherwise>
|
525
|
+
<xsl:variable name="theDocument_2"
|
526
|
+
select="document( $document-uri,/ )" />
|
527
|
+
<xsl:variable name="theFragment_2"
|
528
|
+
select="$theDocument_2/iso:*" />
|
529
|
+
<xsl:variable name="theContainedFragments"
|
530
|
+
select="$theDocument_2/*/iso:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
|
531
|
+
<xsl:if test="not($theDocument_2)">
|
532
|
+
<xsl:message terminate="no">
|
533
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
534
|
+
<xsl:value-of select="@href" />
|
535
|
+
</xsl:message>
|
536
|
+
</xsl:if>
|
537
|
+
|
538
|
+
<!-- There are three cases for includes:
|
539
|
+
0) No text specified- error!
|
540
|
+
|
541
|
+
1) REMOVED
|
542
|
+
|
543
|
+
2) REMOVED
|
544
|
+
|
545
|
+
3) Otherwise, include the pointed-to element
|
546
|
+
-->
|
547
|
+
<xsl:choose>
|
548
|
+
<!-- case 0 -->
|
549
|
+
<xsl:when
|
550
|
+
test="not($theFragment_2) and not ($theContainedFragments)">
|
551
|
+
<xsl:message terminate="no">
|
552
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
553
|
+
<xsl:value-of select="@href" />
|
554
|
+
</xsl:message>
|
555
|
+
</xsl:when>
|
556
|
+
|
557
|
+
<!-- case 1 removed -->
|
558
|
+
|
559
|
+
<!-- case 2 removed -->
|
560
|
+
|
561
|
+
<!-- If this were XLST 2, we could use
|
562
|
+
if ($theFragment) then $theFragment else $theContainedFragments
|
563
|
+
here (thanks to KN)
|
564
|
+
-->
|
565
|
+
<!-- case 3 -->
|
566
|
+
<xsl:otherwise>
|
567
|
+
<xsl:apply-templates
|
568
|
+
select="$theFragment_2/* " mode="dsdl:go" />
|
569
|
+
</xsl:otherwise>
|
570
|
+
</xsl:choose>
|
571
|
+
</xsl:otherwise>
|
572
|
+
</xsl:choose>
|
573
|
+
</xsl:otherwise>
|
574
|
+
</xsl:choose>
|
575
|
+
|
576
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
577
|
+
<xsl:value-of select="@href" />
|
578
|
+
</xsl:processing-instruction>
|
579
|
+
</xsl:template>
|
580
|
+
|
581
|
+
|
582
|
+
|
583
|
+
<!-- =========================================================== -->
|
584
|
+
<!-- Handle Schematron 1.6 inclusions: clone of ISO code above -->
|
585
|
+
<!-- =========================================================== -->
|
586
|
+
|
587
|
+
|
588
|
+
<!-- Extend the URI syntax to allow # references -->
|
589
|
+
<!-- Add experimental support for simple containers like /xxx:xxx/schold:pattern to allow better includes -->
|
590
|
+
<xsl:template match="schold:include" mode="dsdl:go">
|
591
|
+
<xsl:variable name="document-uri"
|
592
|
+
select="substring-before(concat(@href,'#'), '#')" />
|
593
|
+
<xsl:variable name="fragment-id"
|
594
|
+
select="substring-after(@href, '#')" />
|
595
|
+
|
596
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
597
|
+
<xsl:value-of select="@href" />
|
598
|
+
</xsl:processing-instruction>
|
599
|
+
|
600
|
+
<xsl:choose>
|
601
|
+
<xsl:when test="not( $include-schematron = 'true' )">
|
602
|
+
<xslt:copy>
|
603
|
+
<xslt:copy-of select="@*" />
|
604
|
+
<xslt:apply-templates mode="dsdl:go" />
|
605
|
+
</xslt:copy>
|
606
|
+
</xsl:when>
|
607
|
+
<xsl:otherwise>
|
608
|
+
<xsl:choose>
|
609
|
+
|
610
|
+
<xsl:when
|
611
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
612
|
+
<xsl:message>
|
613
|
+
Error: Impossible URL in Schematron include
|
614
|
+
</xsl:message>
|
615
|
+
</xsl:when>
|
616
|
+
|
617
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
618
|
+
<xslt:when
|
619
|
+
test="string-length( $document-uri ) = 0">
|
620
|
+
<xslt:apply-templates mode="dsdl:go"
|
621
|
+
select="//schold:*[@xml:id= $fragment-id ]
|
622
|
+
|id( $fragment-id)
|
623
|
+
| //schold:*[@id= $fragment-id ]" />
|
624
|
+
</xslt:when>
|
625
|
+
|
626
|
+
<!-- case where there is a fragment in another document (should be an iso: element) -->
|
627
|
+
<xsl:when
|
628
|
+
test="string-length( $fragment-id ) > 0">
|
629
|
+
<xsl:variable name="theDocument_1"
|
630
|
+
select="document( $document-uri,/ )" />
|
631
|
+
<xsl:if test="not($theDocument_1)">
|
632
|
+
<xsl:message terminate="no">
|
633
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
634
|
+
<xsl:value-of select="@href" />
|
635
|
+
</xsl:message>
|
636
|
+
</xsl:if>
|
637
|
+
<!-- use for-each to rebase id() to $theDocument -->
|
638
|
+
<xsl:for-each select="$theDocument_1">
|
639
|
+
<xsl:variable name="theFragment_1"
|
640
|
+
select=" $theDocument_1//schold:*[@xml:id= $fragment-id ] |
|
641
|
+
id($fragment-id) |
|
642
|
+
$theDocument_1//schold:*[@id= $fragment-id ]" />
|
643
|
+
<xsl:if
|
644
|
+
test=" $theFragment_1/self::schold:schema ">
|
645
|
+
<xsl:message>
|
646
|
+
Schema error: Use include to include
|
647
|
+
fragments, not a whole schema
|
648
|
+
</xsl:message>
|
649
|
+
</xsl:if>
|
650
|
+
<xsl:if test="not($theFragment_1)">
|
651
|
+
<xsl:message terminate="no">
|
652
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
653
|
+
<xsl:value-of select="@href" />
|
654
|
+
</xsl:message>
|
655
|
+
</xsl:if>
|
656
|
+
<xsl:apply-templates
|
657
|
+
select=" $theFragment_1[1]" mode="dsdl:go" />
|
658
|
+
</xsl:for-each>
|
659
|
+
</xsl:when>
|
660
|
+
|
661
|
+
<!-- Case where there is no ID so we include the whole document -->
|
662
|
+
<!-- Experimental addition: include fragments of children -->
|
663
|
+
<xsl:otherwise>
|
664
|
+
<xsl:variable name="theDocument_2"
|
665
|
+
select="document( $document-uri,/ )" />
|
666
|
+
<xsl:variable name="theFragment_2"
|
667
|
+
select="$theDocument_2/iso:*" />
|
668
|
+
<xsl:variable name="theContainedFragments"
|
669
|
+
select="$theDocument_2/*/schold:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
|
670
|
+
<xsl:if test="not($theDocument_2)">
|
671
|
+
<xsl:message terminate="no">
|
672
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
673
|
+
<xsl:value-of select="@href" />
|
674
|
+
</xsl:message>
|
675
|
+
</xsl:if>
|
676
|
+
|
677
|
+
<xsl:if
|
678
|
+
test=" $theFragment_2/self::schold:schema or $theContainedFragments/self::schold:schema">
|
679
|
+
<xsl:message>
|
680
|
+
Schema error: Use include to include
|
681
|
+
fragments, not a whole schema
|
682
|
+
</xsl:message>
|
683
|
+
</xsl:if>
|
684
|
+
<xsl:if
|
685
|
+
test="not($theFragment_2) and not ($theContainedFragments)">
|
686
|
+
<xsl:message terminate="no">
|
687
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
688
|
+
<xsl:value-of select="@href" />
|
689
|
+
</xsl:message>
|
690
|
+
</xsl:if>
|
691
|
+
<!-- If this were XLST 2, we could use
|
692
|
+
if ($theFragment) then $theFragment else $theContainedFragments
|
693
|
+
here (thanks to KN)
|
694
|
+
-->
|
695
|
+
<xsl:choose>
|
696
|
+
<xsl:when test=" $theFragment_2 ">
|
697
|
+
<xsl:apply-templates
|
698
|
+
select="$theFragment_2 " mode="dsdl:go" />
|
699
|
+
</xsl:when>
|
700
|
+
<xsl:otherwise>
|
701
|
+
<!-- WARNING! EXPERIMENTAL! Use at your own risk. This may be discontinued! -->
|
702
|
+
<xsl:apply-templates
|
703
|
+
select=" $theContainedFragments " mode="dsdl:go" />
|
704
|
+
</xsl:otherwise>
|
705
|
+
</xsl:choose>
|
706
|
+
</xsl:otherwise>
|
707
|
+
</xsl:choose>
|
708
|
+
|
709
|
+
</xsl:otherwise>
|
710
|
+
</xsl:choose>
|
711
|
+
|
712
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
713
|
+
<xsl:value-of select="@href" />
|
714
|
+
</xsl:processing-instruction>
|
715
|
+
</xsl:template>
|
716
|
+
<!-- =========================================================== -->
|
717
|
+
<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
|
718
|
+
<!-- Part 5 - DataType Library Language - DTLL -->
|
719
|
+
<!-- Committee Draft Experimental support only -->
|
720
|
+
<!-- The <include> element may well be replaced by XInclude in -->
|
721
|
+
<!-- any final version. -->
|
722
|
+
<!-- =========================================================== -->
|
723
|
+
<xslt:template match="dtll:include" mode="dsdl:go">
|
724
|
+
<!-- Insert subschema -->
|
725
|
+
|
726
|
+
<xsl:variable name="document-uri"
|
727
|
+
select="substring-before(concat(@href,'#'), '#')" />
|
728
|
+
<xsl:variable name="fragment-id"
|
729
|
+
select="substring-after(@href, '#')" />
|
730
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
731
|
+
<xsl:value-of select="@href" />
|
732
|
+
</xsl:processing-instruction>
|
733
|
+
<xsl:choose>
|
734
|
+
<xsl:when test="not( $include-dtll = 'true' )">
|
735
|
+
<xslt:copy>
|
736
|
+
<xslt:copy-of select="@*" />
|
737
|
+
<xslt:apply-templates mode="dsdl:go" />
|
738
|
+
</xslt:copy>
|
739
|
+
</xsl:when>
|
740
|
+
<xsl:otherwise>
|
741
|
+
<xsl:choose>
|
742
|
+
|
743
|
+
<xsl:when
|
744
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
745
|
+
<xsl:message>
|
746
|
+
Error: Impossible URL in DTLL include
|
747
|
+
</xsl:message>
|
748
|
+
</xsl:when>
|
749
|
+
|
750
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
751
|
+
<xslt:when
|
752
|
+
test="string-length( $document-uri ) = 0">
|
753
|
+
<xslt:apply-templates mode="dsdl:go"
|
754
|
+
select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
|
755
|
+
| //*[@id= $fragment-id ]" />
|
756
|
+
</xslt:when>
|
757
|
+
|
758
|
+
<xsl:when
|
759
|
+
test="string-length( $fragment-id ) > 0">
|
760
|
+
<xsl:variable name="theDocument_1"
|
761
|
+
select="document( $document-uri,/ )" />
|
762
|
+
<xsl:if test="not($theDocument_1)">
|
763
|
+
<xsl:message terminate="no">
|
764
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
765
|
+
<xsl:value-of select="@href" />
|
766
|
+
</xsl:message>
|
767
|
+
</xsl:if>
|
768
|
+
<!-- use for-each to rebase id() to $theDocument -->
|
769
|
+
<xsl:for-each select="$theDocument_1">
|
770
|
+
<xsl:variable name="theFragment_1"
|
771
|
+
select="$theDocument_1//*[@xml:id= $fragment-id ]
|
772
|
+
| id( $fragment-id )
|
773
|
+
| $theDocument_1//*[@id= $fragment-id ]" />
|
774
|
+
<xsl:if test="not($theFragment_1)">
|
775
|
+
<xsl:message terminate="no">
|
776
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
777
|
+
<xsl:value-of select="@href" />
|
778
|
+
</xsl:message>
|
779
|
+
</xsl:if>
|
780
|
+
<xsl:apply-templates
|
781
|
+
select=" $theFragment_1[1]" mode="dsdl:go" />
|
782
|
+
</xsl:for-each>
|
783
|
+
</xsl:when>
|
784
|
+
|
785
|
+
<xsl:otherwise>
|
786
|
+
<xsl:variable name="theDocument_2"
|
787
|
+
select="document( $document-uri,/ )" />
|
788
|
+
<xsl:variable name="theFragment_2"
|
789
|
+
select="$theDocument_2/*" />
|
790
|
+
|
791
|
+
<xsl:if test="not($theDocument_2)">
|
792
|
+
<xsl:message terminate="no">
|
793
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
794
|
+
<xsl:value-of select="@href" />
|
795
|
+
</xsl:message>
|
796
|
+
</xsl:if>
|
797
|
+
|
798
|
+
<xsl:if test="not($theFragment_2)">
|
799
|
+
<xsl:message terminate="no">
|
800
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
801
|
+
<xsl:value-of select="@href" />
|
802
|
+
</xsl:message>
|
803
|
+
</xsl:if>
|
804
|
+
<xsl:apply-templates select="$theFragment_2 "
|
805
|
+
mode="dsdl:go" />
|
806
|
+
</xsl:otherwise>
|
807
|
+
</xsl:choose>
|
808
|
+
|
809
|
+
</xsl:otherwise>
|
810
|
+
</xsl:choose>
|
811
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
812
|
+
<xsl:value-of select="@href" />
|
813
|
+
</xsl:processing-instruction>
|
814
|
+
</xslt:template>
|
815
|
+
|
816
|
+
<!-- =========================================================== -->
|
817
|
+
<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
|
818
|
+
<!-- Part 7 - Character Repertoire Description Language - CRDL -->
|
819
|
+
<!-- Final Committee Draft 2008-01-11 Experimental support only -->
|
820
|
+
<!-- =========================================================== -->
|
821
|
+
<xslt:template match="crdl:ref" mode="dsdl:go">
|
822
|
+
<!-- Insert subschema -->
|
823
|
+
|
824
|
+
<xsl:variable name="document-uri"
|
825
|
+
select="substring-before(concat(@href,'#'), '#')" />
|
826
|
+
<xsl:variable name="fragment-id"
|
827
|
+
select="substring-after(@href, '#')" />
|
828
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
829
|
+
<xsl:value-of select="@href" />
|
830
|
+
</xsl:processing-instruction>
|
831
|
+
<xsl:choose>
|
832
|
+
<xsl:when test="not( $include-crdl = 'true' )">
|
833
|
+
<xslt:copy>
|
834
|
+
<xslt:copy-of select="@*" />
|
835
|
+
<xslt:apply-templates mode="dsdl:go" />
|
836
|
+
</xslt:copy>
|
837
|
+
</xsl:when>
|
838
|
+
<xsl:otherwise>
|
839
|
+
<xsl:choose>
|
840
|
+
|
841
|
+
<xsl:when
|
842
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
843
|
+
<xsl:message>
|
844
|
+
Error: Impossible URL in CRDL include
|
845
|
+
</xsl:message>
|
846
|
+
</xsl:when>
|
847
|
+
|
848
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
849
|
+
<xslt:when
|
850
|
+
test="string-length( $document-uri ) = 0">
|
851
|
+
|
852
|
+
<xslt:apply-templates mode="dsdl:go"
|
853
|
+
select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
|
854
|
+
| //*[@id= $fragment-id ]" />
|
855
|
+
</xslt:when>
|
856
|
+
|
857
|
+
<xsl:when
|
858
|
+
test="string-length( $fragment-id ) > 0">
|
859
|
+
<xsl:variable name="theDocument_1"
|
860
|
+
select="document( $document-uri,/ )" />
|
861
|
+
<xsl:if test="not($theDocument_1)">
|
862
|
+
<xsl:message terminate="no">
|
863
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
864
|
+
<xsl:value-of select="@href" />
|
865
|
+
</xsl:message>
|
866
|
+
</xsl:if>
|
867
|
+
<!-- use for-each to rebase id() to $theDocument -->
|
868
|
+
<xsl:for-each select="$theDocument_1">
|
869
|
+
<xsl:variable name="theFragment_1"
|
870
|
+
select="$theDocument_1//*[@xml:id= $fragment-id ]
|
871
|
+
| id( $fragment-id )
|
872
|
+
| $theDocument_1//*[@id= $fragment-id ]" />
|
873
|
+
|
874
|
+
<xsl:if test="not($theFragment_1)">
|
875
|
+
<xsl:message terminate="no">
|
876
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
877
|
+
<xsl:value-of select="@href" />
|
878
|
+
</xsl:message>
|
879
|
+
</xsl:if>
|
880
|
+
<xsl:apply-templates select=" $theFragment_1 "
|
881
|
+
mode="dsdl:go" />
|
882
|
+
</xsl:for-each>
|
883
|
+
</xsl:when>
|
884
|
+
|
885
|
+
<xsl:otherwise>
|
886
|
+
<xsl:variable name="theDocument_2"
|
887
|
+
select="document( $document-uri,/ )" />
|
888
|
+
<xsl:variable name="theFragment_2"
|
889
|
+
select="$theDocument_2/*" />
|
890
|
+
|
891
|
+
<xsl:if test="not($theDocument_2)">
|
892
|
+
<xsl:message terminate="no">
|
893
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
894
|
+
<xsl:value-of select="@href" />
|
895
|
+
</xsl:message>
|
896
|
+
</xsl:if>
|
897
|
+
<xsl:if test="not($theFragment_2)">
|
898
|
+
<xsl:message terminate="no">
|
899
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
900
|
+
<xsl:value-of select="@href" />
|
901
|
+
</xsl:message>
|
902
|
+
</xsl:if>
|
903
|
+
|
904
|
+
<xsl:apply-templates select="$theFragment_2"
|
905
|
+
mode="dsdl:go" />
|
906
|
+
</xsl:otherwise>
|
907
|
+
</xsl:choose>
|
908
|
+
|
909
|
+
</xsl:otherwise>
|
910
|
+
</xsl:choose>
|
911
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
912
|
+
<xsl:value-of select="@href" />
|
913
|
+
</xsl:processing-instruction>
|
914
|
+
</xslt:template>
|
915
|
+
|
916
|
+
|
917
|
+
<!-- =========================================================== -->
|
918
|
+
<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
|
919
|
+
<!-- Part 4 - Namespace-based Validation Dispatching Language - NVDL -->
|
920
|
+
<!-- Note: This does not include schemas referenced for -->
|
921
|
+
<!-- validation, it merely handles any simple XIncludes -->
|
922
|
+
<!-- =========================================================== -->
|
923
|
+
<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
|
924
|
+
<!-- Part 8 - Document Schema Renaming Language - DSRL -->
|
925
|
+
<!-- Note: Final? Committee Draft Experimental support only -->
|
926
|
+
<!-- =========================================================== -->
|
927
|
+
<!-- XInclude support for id based references only, with 1 level -->
|
928
|
+
<!-- of fallback. -->
|
929
|
+
<!-- =========================================================== -->
|
930
|
+
|
931
|
+
<xslt:template mode="dsdl:go"
|
932
|
+
match="xi:include[@href][not(@parseType) or @parseType ='xml']">
|
933
|
+
<!-- Simple inclusions only here -->
|
934
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
935
|
+
<xsl:value-of select="@href" />
|
936
|
+
</xsl:processing-instruction>
|
937
|
+
<xsl:choose>
|
938
|
+
<xsl:when test="not( $include-xinclude = 'true' )">
|
939
|
+
<xslt:copy>
|
940
|
+
<xslt:copy-of select="@*" />
|
941
|
+
<xslt:apply-templates mode="dsdl:go" />
|
942
|
+
</xslt:copy>
|
943
|
+
</xsl:when>
|
944
|
+
<xsl:otherwise>
|
945
|
+
<xsl:choose>
|
946
|
+
|
947
|
+
<xsl:when test="contains( @href, '#')">
|
948
|
+
<xsl:message terminate="yes">
|
949
|
+
Fatal error: Xinclude href contains fragment
|
950
|
+
identifier #
|
951
|
+
</xsl:message>
|
952
|
+
</xsl:when>
|
953
|
+
|
954
|
+
|
955
|
+
<xsl:when test="contains( @xpointer, '(')">
|
956
|
+
<xsl:message terminate="yes">
|
957
|
+
Fatal error: Sorry, this software only
|
958
|
+
supports simple ids in XInclude xpointers
|
959
|
+
</xsl:message>
|
960
|
+
</xsl:when>
|
961
|
+
|
962
|
+
<xsl:when
|
963
|
+
test="string-length( @href ) = 0 and string-length( @xpointer ) = 0">
|
964
|
+
|
965
|
+
<xsl:message terminate="yes">
|
966
|
+
Fatal Error: Impossible URL in XInclude
|
967
|
+
include
|
968
|
+
</xsl:message>
|
969
|
+
</xsl:when>
|
970
|
+
|
971
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
972
|
+
<xslt:when test="string-length( @href ) = 0">
|
973
|
+
|
974
|
+
<xslt:apply-templates mode="dsdl:go"
|
975
|
+
select="//*[@xml:id= current()/@xpointer ] | id( @xpointer)
|
976
|
+
| //*[@id= current()/@xpointer ]" />
|
977
|
+
</xslt:when>
|
978
|
+
|
979
|
+
<xsl:when
|
980
|
+
test="string-length( @xpointer ) > 0">
|
981
|
+
<xsl:variable name="theDocument_1"
|
982
|
+
select="document( @href,/ )" />
|
983
|
+
<xsl:variable name="theFragment_1"
|
984
|
+
select="$theDocument_1//*[@xml:id= current()/@xpointer ]
|
985
|
+
|
986
|
+
| $theDocument_1//*[@id= current()/@xpointer ]" />
|
987
|
+
<!-- removed
|
988
|
+
| $theDocument_1/id( @xpointer)
|
989
|
+
because it requires rebasing in XSLT1 and that would mess up the use of current()
|
990
|
+
-->
|
991
|
+
|
992
|
+
|
993
|
+
<!-- Allow one level of fallback, to another XInclude -->
|
994
|
+
<xsl:if test="not($theDocument_1)">
|
995
|
+
<xsl:choose>
|
996
|
+
<xsl:when test="xi:fallback">
|
997
|
+
<xsl:variable name="theDocument_2"
|
998
|
+
select="document( xi:fallback[1]/xi:include[not(@parseType)
|
999
|
+
or @parseType='xml']/@href,/ )" />
|
1000
|
+
<xsl:variable name="theFragment_2"
|
1001
|
+
select="$theDocument_2//*[@xml:id= current()/xi:fallback[1]/xi:include/@xpointer ]
|
1002
|
+
| $theDocument_2//*[@id= current()/xi:fallback[1]/xi:include/@xpointer ]" />
|
1003
|
+
<!-- removed
|
1004
|
+
| $theDocument_2/id( xi:fallback[1]/xi:include/@xpointer)
|
1005
|
+
because it id() would need rebasing in XSLT1 and that would mess up use of current()
|
1006
|
+
-->
|
1007
|
+
|
1008
|
+
<xsl:if
|
1009
|
+
test="not($theDocument_2)">
|
1010
|
+
|
1011
|
+
<xsl:message terminate="no">
|
1012
|
+
<xsl:text>Unable to open referenced included file and fallback
|
1013
|
+
file: </xsl:text>
|
1014
|
+
<xsl:value-of
|
1015
|
+
select="@href" />
|
1016
|
+
</xsl:message>
|
1017
|
+
</xsl:if>
|
1018
|
+
</xsl:when>
|
1019
|
+
<xsl:otherwise>
|
1020
|
+
<xsl:message terminate="no">
|
1021
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
1022
|
+
<xsl:value-of select="@href" />
|
1023
|
+
</xsl:message>
|
1024
|
+
</xsl:otherwise>
|
1025
|
+
</xsl:choose>
|
1026
|
+
</xsl:if>
|
1027
|
+
<xsl:apply-templates select=" $theFragment_1"
|
1028
|
+
mode="dsdl:go" />
|
1029
|
+
</xsl:when>
|
1030
|
+
|
1031
|
+
<!-- Document but no fragment specified -->
|
1032
|
+
<xsl:otherwise>
|
1033
|
+
<xsl:variable name="theDocument_3"
|
1034
|
+
select="document( @href,/ )" />
|
1035
|
+
<xsl:variable name="theFragment_3"
|
1036
|
+
select="$theDocument_3/*" />
|
1037
|
+
|
1038
|
+
<xsl:if test="not($theDocument_3)">
|
1039
|
+
<xsl:message terminate="no">
|
1040
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
1041
|
+
<xsl:value-of select="@href" />
|
1042
|
+
</xsl:message>
|
1043
|
+
</xsl:if>
|
1044
|
+
|
1045
|
+
<xsl:apply-templates select="$theFragment_3 "
|
1046
|
+
mode="dsdl:go" />
|
1047
|
+
</xsl:otherwise>
|
1048
|
+
</xsl:choose>
|
1049
|
+
|
1050
|
+
</xsl:otherwise>
|
1051
|
+
</xsl:choose>
|
1052
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
1053
|
+
<xsl:value-of select="@href" />
|
1054
|
+
</xsl:processing-instruction>
|
1055
|
+
</xslt:template>
|
1056
|
+
|
1057
|
+
<!-- =========================================================== -->
|
1058
|
+
<!-- W3C XLink 1.1 embedded simple links -->
|
1059
|
+
<!-- =========================================================== -->
|
1060
|
+
<xslt:template
|
1061
|
+
match="*[@xlink:href][not(parent::*[@xlink:type='complex'])]
|
1062
|
+
[not(@xlink:type) or (@xlink:type='simple')]
|
1063
|
+
[@xlink:show='embed']
|
1064
|
+
[not(@xlink:actuate) or (@xlink:actuate='onLoad')]"
|
1065
|
+
mode="dsdl:go" priority="1">
|
1066
|
+
|
1067
|
+
<xsl:variable name="document-uri"
|
1068
|
+
select="substring-before(concat(@xlink:href,'#'), '#')" />
|
1069
|
+
<xsl:variable name="fragment-id"
|
1070
|
+
select="substring-after(@xlink:href, '#')" />
|
1071
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
1072
|
+
<xsl:value-of select="@xlink:href" />
|
1073
|
+
</xsl:processing-instruction>
|
1074
|
+
<xsl:choose>
|
1075
|
+
<xsl:when test="not( $include-xlink = 'true' )">
|
1076
|
+
<xslt:copy>
|
1077
|
+
<xslt:copy-of select="@*" />
|
1078
|
+
<xslt:apply-templates mode="dsdl:go" />
|
1079
|
+
</xslt:copy>
|
1080
|
+
</xsl:when>
|
1081
|
+
<xsl:otherwise>
|
1082
|
+
<xsl:choose>
|
1083
|
+
|
1084
|
+
<xsl:when
|
1085
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
1086
|
+
<xsl:message>
|
1087
|
+
Error: Impossible URL in XLink embedding
|
1088
|
+
link
|
1089
|
+
</xsl:message>
|
1090
|
+
</xsl:when>
|
1091
|
+
|
1092
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
1093
|
+
<xslt:when
|
1094
|
+
test="string-length( $document-uri ) = 0">
|
1095
|
+
<xslt:apply-templates mode="dsdl:go"
|
1096
|
+
select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
|
1097
|
+
| //*[@id= $fragment-id ]" />
|
1098
|
+
</xslt:when>
|
1099
|
+
|
1100
|
+
<xsl:when
|
1101
|
+
test="string-length( $fragment-id ) > 0">
|
1102
|
+
<xsl:variable name="theDocument_1"
|
1103
|
+
select="document( $document-uri,/ )" />
|
1104
|
+
<xsl:if test="not($theDocument_1)">
|
1105
|
+
<xsl:message terminate="no">
|
1106
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
1107
|
+
<xsl:value-of select="@xlink:href" />
|
1108
|
+
</xsl:message>
|
1109
|
+
</xsl:if>
|
1110
|
+
<!-- use for-each to rebase id() to $theDocument -->
|
1111
|
+
<xsl:for-each select="$theDocument_1">
|
1112
|
+
<xsl:variable name="theFragment_1"
|
1113
|
+
select="$theDocument_1//*[@xml:id= $fragment-id ]
|
1114
|
+
| id( $fragment-id )
|
1115
|
+
| $theDocument_1//*[@id= $fragment-id ]" />
|
1116
|
+
<xsl:if test="not($theFragment_1)">
|
1117
|
+
<xsl:message terminate="no">
|
1118
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
1119
|
+
<xsl:value-of select="@xlink:href" />
|
1120
|
+
</xsl:message>
|
1121
|
+
</xsl:if>
|
1122
|
+
<xsl:apply-templates
|
1123
|
+
select=" $theFragment_1[1]" mode="dsdl:go" />
|
1124
|
+
</xsl:for-each>
|
1125
|
+
</xsl:when>
|
1126
|
+
|
1127
|
+
<xsl:otherwise>
|
1128
|
+
<xsl:variable name="theDocument_2"
|
1129
|
+
select="document( $document-uri,/ )" />
|
1130
|
+
<xsl:variable name="theFragment_2"
|
1131
|
+
select="$theDocument_2/*" />
|
1132
|
+
|
1133
|
+
<xsl:if test="not($theDocument_2)">
|
1134
|
+
<xsl:message terminate="no">
|
1135
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
1136
|
+
<xsl:value-of select="@xlink:href" />
|
1137
|
+
</xsl:message>
|
1138
|
+
</xsl:if>
|
1139
|
+
|
1140
|
+
<xsl:if test="not($theFragment_2)">
|
1141
|
+
<xsl:message terminate="no">
|
1142
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
1143
|
+
<xsl:value-of select="@xlink:href" />
|
1144
|
+
</xsl:message>
|
1145
|
+
</xsl:if>
|
1146
|
+
<xsl:apply-templates select="$theFragment_2 "
|
1147
|
+
mode="dsdl:go" />
|
1148
|
+
</xsl:otherwise>
|
1149
|
+
</xsl:choose>
|
1150
|
+
|
1151
|
+
</xsl:otherwise>
|
1152
|
+
</xsl:choose>
|
1153
|
+
|
1154
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
1155
|
+
<xsl:value-of select="@xlink:href" />
|
1156
|
+
</xsl:processing-instruction>
|
1157
|
+
</xslt:template>
|
1158
|
+
|
1159
|
+
|
1160
|
+
</xslt:stylesheet>
|