File: iso_dsdl_include.xsl

package info (click to toggle)
mobyle 1.5.5%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,288 kB
  • sloc: python: 22,709; makefile: 35; sh: 33; ansic: 10; xml: 6
file content (989 lines) | stat: -rw-r--r-- 41,433 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
<?xml version="1.0" encoding="UTF-8"?><?xar XSLT?>

<!-- 
     OVERVIEW : iso_dsdl_include.xsl
     
	    This is an inclusion preprocessor for the non-smart text inclusions
	    of ISO DSDL. It handles 
	    	<relax:extRef> for ISO RELAX NG
	    	<sch:include>  for ISO Schematron and Schematron 1.n
	    	<xi:xinclude>  simple W3C XIncludes for ISO NVRL and DSRL 
	    	<crdl:ref>     for draft ISO CRDL
	    	<dtll:include> for draft ISO DTLL
	    	<* @xlink:href> for simple W3C XLink 1.1 embedded links
	    	
		 
		This should be the first in any chain of processing. It only requires
		XSLT 1. Each kind of inclusion can be turned off (or on) on the command line.
		
		Ids in fragment identifiers or xpointers will be sought in the following
		order:
		    * @xml:id
		    * id() for typed schemas (e.g. from DTD) [NOTE: XInclude does not support this]
		    * untyped @id 
		    
		The proposed behaviour for the update to ISO Schematron has been implemented. If an
		include points to an element with the same name as the parent, then that element's
		contents will be included. This supports the merge style of inclusion.    
		
		When an inclusion is made, it is preceded by a PI with target DSDL_INCLUDE_START
		and the href and closed by a PI with target DSDL_INCLUDE_START and the href. This is
		to allow better location of problems, though only to the file level. 
		    
		Limitations:
			* No rebasing: relative paths will be interpreted based on the initial document's
			path, not the including document. (Severe limitation!)
			* No checking for circular references
			* Not full xpointers: only ID matching
			* <relax:include> not implemented 
			* XInclude handling of xml:base and xml:lang not implemented   
-->
<!-- 
  VERSION INFORMATION
  2008-09-18
    * Remove new behaviour for include, because it conflicts with existing usage [KH]
    * Add extends[@href] element with that merge functionality
    * Generate PIs to notate source of inclusions for potential better diagnostics
    
  2008-09-16
    * Fix for XSLT1
    
  2008-08-28
  	* New behaviour for schematron includes: if the pointed to element is the same as the current,
  	include the children.
  	
  2008-08-20
  	* Fix bug: in XSLT1 cannot do $document/id('x') but need to use for-each
  	
  2008-08-04
  	* Add support for inclusions in old namespace  
  	
  2008-08-03
  	* Fix wrong param name include-relaxng & include-crdl (KH, PH)
  	* Allow inclusion of XSLT and XHTML (KH)
  	* Fix inclusion of fragments (KH)
  	
  2008-07-25
  	* Add selectable input parameter
  
  2008-07-24  
	* RJ New
-->	
<!--
 LEGAL INFORMATION
 
 Copyright (c) 2008 Rick Jelliffe 

 This software is provided 'as-is', without any express or implied warranty. 
 In no event will the authors be held liable for any damages arising from 
 the use of this software.

 Permission is granted to anyone to use this software for any purpose, 
 including commercial applications, and to alter it and redistribute it freely,
 subject to the following restrictions:

 1. The origin of this software must not be misrepresented; you must not claim
 that you wrote the original software. If you use this software in a product, 
 an acknowledgment in the product documentation would be appreciated but is 
 not required.

 2. Altered source versions must be plainly marked as such, and must not be 
 misrepresented as being the original software.

 3. This notice may not be removed or altered from any source distribution.
-->
<xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:iso="http://purl.oclc.org/dsdl/schematron" 
    xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl" 
	xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:schold="http://www.ascc.net/xml/schematron"
    xmlns:crdl="http://purl.oclc.org/dsdl/crepdl/ns/structure/1.0"
    xmlns:xi="http://www.w3.org/2001/XInclude"
    xmlns:dtll="http://www.jenitennison.com/datatypes"
    xmlns:dsdl="http://www.dsdl.org/namespace" 
    xmlns:relax="http://relaxng.org/ns/structure/1.0"
    xmlns:xlink="http://www.w3.org/1999/xlink"
            > 
	 <!-- Note: The URL for the dsdl namespace is not official -->
	
	
<xsl:param name="include-schematron">true</xsl:param>
<xsl:param name="include-crdl">true</xsl:param>
<xsl:param name="include-xinclude">true</xsl:param>
<xsl:param name="include-dtll">true</xsl:param>
<xsl:param name="include-relaxng">true</xsl:param> 
<xsl:param name="include-xlink">true</xsl:param> 
	
<xsl:template match="/">
  <xsl:apply-templates select="." mode="dsdl:go" />
</xsl:template>
	
	<!-- output everything else unchanged -->
	<xslt:template match="node()" priority="-1" mode="dsdl:go"> 
	    <xslt:copy>
			<xslt:copy-of select="@*" />
			<xslt:apply-templates mode="dsdl:go"   /> 
		</xslt:copy>
	</xslt:template>

	 
			
	<!-- =========================================================== -->
	<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages   -->
	<!-- Part 2 - Regular grammar-based validation - RELAX NG        --> 
	<!-- This only implements relax:extRef not relax:include which   -->
	<!-- is complex.                                                 -->
	<!-- =========================================================== -->
	<xslt:template   match="relax:extRef" mode="dsdl:go">
	 
	
	    <!-- Insert subschema -->
       
       <xsl:variable name="document-uri" select="substring-before(concat(@href,'#'), '#')"/>
       <xsl:variable name="fragment-id" select="substring-after(@href, '#')"/>
       
     	<xsl:processing-instruction name="DSDL_INCLUDE_START">  <xsl:value-of select="@href"/></xsl:processing-instruction>
       <xsl:choose>
       	<xsl:when test="not( $include-relaxng = 'true' )">
       	  <xslt:copy>
			<xslt:copy-of select="@*" />
			<xslt:apply-templates mode="dsdl:go"   /> 
		  </xslt:copy>
		</xsl:when>
		<xsl:otherwise>
       
       <xsl:choose> 
          
          <xsl:when test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0" >
          	<xsl:message>Error: Impossible URL in RELAX NG extRef include</xsl:message>
          </xsl:when> 
          
          <!-- this case is when there is in embedded schema in the same document elsewhere -->
          <xslt:when test="string-length( $document-uri ) = 0">
              <xslt:apply-templates mode="dsdl:go"
              	select="//*[@xml:id= $fragment-id ] | id( $fragment-id) | //*[@id= $fragment-id ]"/>
          </xslt:when>
          
          <xsl:when test="string-length( $fragment-id ) &gt; 0">
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
             
               <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if> 
			<!-- use a for-each so that the id() function works correctly on the external document -->
			<xsl:for-each select="$theDocument">
              <xsl:variable name="theFragment" select="$theDocument//*[@xml:id= $fragment-id ]        
                  |  id( $fragment-id)          
              | $theDocument//*[@id= $fragment-id ]" />
   			<xsl:if test="not($theFragment)">
				<xsl:message terminate="no">
					<xsl:text>Unable to locate id attribute: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
              <xsl:apply-templates select=" $theFragment[1]" mode="dsdl:go"/>
             </xsl:for-each>
		   </xsl:when>
		  
		   <xsl:otherwise>
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
              <xsl:variable name="theFragment" select="$theDocument/*" />
              <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
 
   			<xsl:if test="not($theFragment)">
				<xsl:message terminate="no">
					<xsl:text>Unable to locate id attribute: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
       		<xsl:apply-templates select="$theFragment " mode="dsdl:go"/>
       	   </xsl:otherwise>
       </xsl:choose> 
       	
       </xsl:otherwise>
      </xsl:choose>
      
     	<xsl:processing-instruction name="DSDL_INCLUDE_END">  <xsl:value-of select="@href"/></xsl:processing-instruction>
   </xslt:template>
	    
	
	
	<!-- =========================================================== -->
	<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages   -->
	<!-- Part 3 - Rule-based validation - Schematron                 --> 
	<!-- =========================================================== -->
	
	
   <!-- Extend the URI syntax to allow # references -->
   <!-- Add experimental support for simple containers like  /xxx:xxx/iso:pattern to allow better includes -->
   <xsl:template match="iso:include" mode="dsdl:go">
    
       <xsl:variable name="document-uri" select="substring-before(concat(@href,'#'), '#')"/>
       <xsl:variable name="fragment-id" select="substring-after(@href, '#')"/>
       
       
     	<xsl:processing-instruction name="DSDL_INCLUDE_START">  <xsl:value-of select="@href"/></xsl:processing-instruction>
     	
    <xsl:choose>
       	<xsl:when test="not( $include-schematron = 'true' )">
       	  <xslt:copy>
			<xslt:copy-of select="@*" />
			<xslt:apply-templates mode="dsdl:go"   /> 
		  </xslt:copy>
		</xsl:when>
		<xsl:otherwise>    
       
       <xsl:choose> 
          
          <xsl:when test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0" >
          	<xsl:message>Error: Impossible URL in Schematron include</xsl:message>
          </xsl:when> 
          
          <!-- this case is when there is in embedded schema in the same document elsewhere -->
          <xslt:when test="string-length( $document-uri ) = 0">
              <xslt:apply-templates mode="dsdl:go"
              	select="//iso:*[@xml:id= $fragment-id ] 
              	 |id( $fragment-id)
              	 | //iso:*[@id= $fragment-id ]"/>
          </xslt:when>
          
          <!-- case where there is a fragment in another document (should be an iso: element) -->
			<!-- There are three cases for includes with fragment:
					0) No href file or no matching id - error!
			    	1) REMOVED
			    	      
			        2) The linked-to element is sch:schema however the parent of the include
			            is not a schema. In this case, it is an error. (Actually, it should
			            be an error for other kinds of containment problems, but we won't
			            check for them in this version.)
			            
			        3) Otherwise, include the pointed-to element
			 -->  
          
          <xsl:when test="string-length( $fragment-id ) &gt; 0">
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
              <xsl:variable name="originalParent" select=".." />
              
              <!-- case 0 -->
              <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			   </xsl:if>
			   <!-- use for-each to rebase id() to external document -->
			   <xsl:for-each select="$theDocument" >
              		<xsl:variable name="theFragment" 
              			select=" $theDocument//iso:*[@xml:id= $fragment-id ] |
              	 		id($fragment-id) |
              			$theDocument//iso:*[@id= $fragment-id ]" />
              		 	
              	
              		<xsl:choose>
              			<!-- case 0 -->
   						<xsl:when test="not($theFragment)">
							<xsl:message terminate="no">
								<xsl:text>Unable to locate id attribute: </xsl:text>
								<xsl:value-of select="@href"/>
							</xsl:message>
						</xsl:when>
              		
              		
              			<!-- case 1 REMOVED -->	 
						              		
              			<!-- case 2 -->
              			<xsl:when test=" $theFragment/self::iso:schema ">
                			 <xsl:message>Schema error: Use include to include fragments, not a whole schema</xsl:message>
              			</xsl:when>
              			
              			<!-- case 3 -->
              			<xsl:otherwise> 
		              		<xsl:apply-templates select=" $theFragment[1]" mode="dsdl:go"/>
		              	</xsl:otherwise>
		              </xsl:choose>
              </xsl:for-each>
		   </xsl:when>
		  
		  <!-- Case where there is no ID so we include the whole document -->
		  <!-- Experimental addition: include fragments of children -->
		   <xsl:otherwise>
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
              <xsl:variable name="theFragment" select="$theDocument/iso:*" />
              <xsl:variable name="theContainedFragments" select="$theDocument/*/iso:* | $theDocument/*/xsl:* | $theDocument/*/xhtml:*" />
              <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
   			  </xsl:if>

			  <!-- There are three cases for includes:
					0) No text specified- error!
					
			    	1) REMOVED
			    	      
			        2) The linked-to element is sch:schema however the parent of the include
			            is not a schema. In this case, it is an error. (Actually, it should
			            be an error for other kinds of containment problems, but we won't
			            check for them in this version.)
			            
			        3) Otherwise, include the pointed-to element
			 -->  
			<xsl:choose>
				<!-- case 0 -->
   				<xsl:when test="not($theFragment) and not ($theContainedFragments)">
					<xsl:message terminate="no">
						<xsl:text>Unable to locate id attribute: </xsl:text>
						<xsl:value-of select="@href"/>
					</xsl:message>
				</xsl:when>
			
				<!-- case 1 removed --> 
				
				<!-- case 2 -->
              	<xsl:when test=" $theFragment/self::iso:schema or $theContainedFragments/self::iso:schema">
                	 <xsl:message>Schema error: Use include to include fragments, not a whole schema</xsl:message>
              	</xsl:when>

				<!-- If this were XLST 2, we could use  
					if ($theFragment) then $theFragment else $theContainedFragments
					here (thanks to KN)
				-->
				<!-- case 3 -->
       			<xsl:otherwise>	
       				<xsl:apply-templates select="$theFragment "  mode="dsdl:go"/>
 		      	</xsl:otherwise>
   			</xsl:choose>
       	   </xsl:otherwise>
       	</xsl:choose>
       </xsl:otherwise>
      </xsl:choose>
      
     	<xsl:processing-instruction name="DSDL_INCLUDE_END">  <xsl:value-of select="@href"/></xsl:processing-instruction>
   </xsl:template>
	
	
	<!-- WARNING   sch:extends[@href] is experimental and non standard  --> 
   <!-- Basically, it adds the children of the selected element, not the element itself.  -->
   <xsl:template match="iso:extends[@href]" mode="dsdl:go">
       
       <xsl:variable name="document-uri" select="substring-before(concat(@href,'#'), '#')"/>
       <xsl:variable name="fragment-id" select="substring-after(@href, '#')"/>
     
     
     	<xsl:processing-instruction name="DSDL_INCLUDE_START">  <xsl:value-of select="@href"/></xsl:processing-instruction>
      
    <xsl:choose>
       	<xsl:when test="not( $include-schematron = 'true' )">
       	  <xslt:copy>
			<xslt:copy-of select="@*" />
			<xslt:apply-templates mode="dsdl:go"   /> 
		  </xslt:copy>
		</xsl:when>
		<xsl:otherwise>    
       
       <xsl:choose> 
          
          <xsl:when test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0" >
          	<xsl:message>Error: Impossible URL in Schematron include</xsl:message>
          </xsl:when> 
          
          <!-- this case is when there is in embedded schema in the same document elsewhere -->
          <xslt:when test="string-length( $document-uri ) = 0">
              <xslt:apply-templates mode="dsdl:go"
              	select="//iso:*[@xml:id= $fragment-id ]/* 
              	 |id( $fragment-id)/*
              	 | //iso:*[@id= $fragment-id ]/*"/>
          </xslt:when>
          
          <!-- case where there is a fragment in another document (should be an iso: element) -->
			<!-- There are three cases for includes with fragment:
					0) No href file or no matching id - error!
			    	1) REMOVED
			    	      
			        2) REMOVED
			            
			        3) Otherwise, include the pointed-to element
			 -->  
          
          <xsl:when test="string-length( $fragment-id ) &gt; 0">
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
              <xsl:variable name="originalParent" select=".." />
              
              <!-- case 0 -->
              <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			   </xsl:if>
			   <!-- use for-each to rebase id() to external document -->
			   <xsl:for-each select="$theDocument" >
              		<xsl:variable name="theFragment" 
              			select=" $theDocument//iso:*[@xml:id= $fragment-id ] |
              	 		id($fragment-id) |
              			$theDocument//iso:*[@id= $fragment-id ]" />
              		 	
              	
              		<xsl:choose>
              			<!-- case 0 -->
   						<xsl:when test="not($theFragment)">
							<xsl:message terminate="no">
								<xsl:text>Unable to locate id attribute: </xsl:text>
								<xsl:value-of select="@href"/>
							</xsl:message>
						</xsl:when>
              		
              		
              			<!-- case 1 REMOVED -->	 
						              		
              			<!-- case 2 REMOVED -->
              			 
              			
              			<!-- case 3 -->
              			<xsl:otherwise>
              			
		              		<xsl:apply-templates select=" $theFragment[1]/*" mode="dsdl:go"/>
		              	</xsl:otherwise>
		              </xsl:choose>
              </xsl:for-each>
		   </xsl:when>
		  
		  <!-- Case where there is no ID so we include the whole document -->
		  <!-- Experimental addition: include fragments of children -->
		   <xsl:otherwise>
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
              <xsl:variable name="theFragment" select="$theDocument/iso:*" />
              <xsl:variable name="theContainedFragments" select="$theDocument/*/iso:* | $theDocument/*/xsl:* | $theDocument/*/xhtml:*" />
              <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
   			  </xsl:if>

			  <!-- There are three cases for includes:
					0) No text specified- error!
					
			    	1) REMOVED
			    	      
			        2) REMOVED
			            
			        3) Otherwise, include the pointed-to element
			 -->  
			<xsl:choose>
				<!-- case 0 -->
   				<xsl:when test="not($theFragment) and not ($theContainedFragments)">
					<xsl:message terminate="no">
						<xsl:text>Unable to locate id attribute: </xsl:text>
						<xsl:value-of select="@href"/>
					</xsl:message>
				</xsl:when>
			
				<!-- case 1 removed --> 
				
				<!-- case 2 removed --> 

				<!-- If this were XLST 2, we could use  
					if ($theFragment) then $theFragment else $theContainedFragments
					here (thanks to KN)
				-->
				<!-- case 3 -->
       			<xsl:otherwise>	
       				<xsl:apply-templates select="$theFragment/* "  mode="dsdl:go"/>
 		      	</xsl:otherwise>
   			</xsl:choose>
       	   </xsl:otherwise>
       	</xsl:choose>
       </xsl:otherwise>
      </xsl:choose>
      
     	<xsl:processing-instruction name="DSDL_INCLUDE_END">  <xsl:value-of select="@href"/></xsl:processing-instruction>
   </xsl:template>
	
	
	
	<!-- =========================================================== -->
	<!-- Handle Schematron 1.6 inclusions: clone of ISO code above   -->
	<!-- =========================================================== -->
	
	
   <!-- Extend the URI syntax to allow # references -->
   <!-- Add experimental support for simple containers like  /xxx:xxx/schold:pattern to allow better includes -->
   <xsl:template match="schold:include" mode="dsdl:go">
       <xsl:variable name="document-uri" select="substring-before(concat(@href,'#'), '#')"/>
       <xsl:variable name="fragment-id" select="substring-after(@href, '#')"/>
     
     	<xsl:processing-instruction name="DSDL_INCLUDE_START">  <xsl:value-of select="@href"/></xsl:processing-instruction>
 
  <xsl:choose>
       	<xsl:when test="not( $include-schematron = 'true' )">
       	  <xslt:copy>
			<xslt:copy-of select="@*" />
			<xslt:apply-templates mode="dsdl:go"   /> 
		  </xslt:copy>
		</xsl:when>
		<xsl:otherwise>  
       <xsl:choose> 
          
          <xsl:when test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0" >
          	<xsl:message>Error: Impossible URL in Schematron include</xsl:message>
          </xsl:when> 
          
          <!-- this case is when there is in embedded schema in the same document elsewhere -->
          <xslt:when test="string-length( $document-uri ) = 0">
              <xslt:apply-templates mode="dsdl:go"
              	select="//schold:*[@xml:id= $fragment-id ] 
              	 |id( $fragment-id)
              	 | //schold:*[@id= $fragment-id ]"/>
          </xslt:when>
          
          <!-- case where there is a fragment in another document (should be an iso: element) -->
          <xsl:when test="string-length( $fragment-id ) &gt; 0">
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
              <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
			<!-- use for-each to rebase id() to $theDocument -->
			<xsl:for-each select="$theDocument">
              <xsl:variable name="theFragment" 
              	select=" $theDocument//schold:*[@xml:id= $fragment-id ] |
              	id($fragment-id) |
              	$theDocument//schold:*[@id= $fragment-id ]" />
              <xsl:if test=" $theFragment/self::schold:schema ">
                 <xsl:message>Schema error: Use include to include fragments, not a whole schema</xsl:message>
              </xsl:if>
   			<xsl:if test="not($theFragment)">
				<xsl:message terminate="no">
					<xsl:text>Unable to locate id attribute: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
              <xsl:apply-templates select=" $theFragment[1]" mode="dsdl:go"/>
              </xsl:for-each>
		   </xsl:when>
		  
		  <!-- Case where there is no ID so we include the whole document -->
		  <!-- Experimental addition: include fragments of children -->
		   <xsl:otherwise>
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
              <xsl:variable name="theFragment" select="$theDocument/iso:*" />
              <xsl:variable name="theContainedFragments" select="$theDocument/*/schold:* | $theDocument/*/xsl:* | $theDocument/*/xhtml:*" />
              <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>

              <xsl:if test=" $theFragment/self::schold:schema or $theContainedFragments/self::schold:schema">
                 <xsl:message>Schema error: Use include to include fragments, not a whole schema</xsl:message>
              </xsl:if>
   			<xsl:if test="not($theFragment) and not ($theContainedFragments)">
				<xsl:message terminate="no">
					<xsl:text>Unable to locate id attribute: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
			<!-- If this were XLST 2, we could use  
					if ($theFragment) then $theFragment else $theContainedFragments
				here (thanks to KN)
			-->
			<xsl:choose>
				<xsl:when test=" $theFragment ">			
       				<xsl:apply-templates select="$theFragment "  mode="dsdl:go"/>
       			</xsl:when>
       			<xsl:otherwise>	
       				<!-- WARNING!  EXPERIMENTAL! Use at your own risk. This may be discontinued! -->
 		      		<xsl:apply-templates select="  $theContainedFragments " mode="dsdl:go"/>
 		      	</xsl:otherwise>
 		     </xsl:choose>
       	   </xsl:otherwise>
       </xsl:choose>
       
       </xsl:otherwise>
      </xsl:choose>
      
      <xsl:processing-instruction name="DSDL_INCLUDE_END">  <xsl:value-of select="@href"/></xsl:processing-instruction>
   </xsl:template>
	<!-- =========================================================== -->
	<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages   -->
	<!-- Part 5 - DataType Library Language - DTLL                   -->
	<!-- Committee Draft  Experimental support only                  -->
	<!-- The <include> element may well be replaced by XInclude in   -->
	<!-- any final version.                                          -->
	<!-- =========================================================== -->
	<xslt:template   match="dtll:include" mode="dsdl:go">
	    <!-- Insert subschema -->
       
       <xsl:variable name="document-uri" select="substring-before(concat(@href,'#'), '#')"/>
       <xsl:variable name="fragment-id" select="substring-after(@href, '#')"/>
  <xsl:processing-instruction name="DSDL_INCLUDE_START">  <xsl:value-of select="@href"/></xsl:processing-instruction>
  <xsl:choose>
       	<xsl:when test="not( $include-dtll = 'true' )">
       	  <xslt:copy>
			<xslt:copy-of select="@*" />
			<xslt:apply-templates mode="dsdl:go"   /> 
		  </xslt:copy>
		</xsl:when>
		<xsl:otherwise>     
       <xsl:choose> 
          
          <xsl:when test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0" >
          	<xsl:message>Error: Impossible URL in DTLL include</xsl:message>
          </xsl:when> 
          
          <!-- this case is when there is in embedded schema in the same document elsewhere -->
          <xslt:when test="string-length( $document-uri ) = 0">
              <xslt:apply-templates mode="dsdl:go"
              	select="//*[@xml:id= $fragment-id ] | id( $fragment-id) 
              	| //*[@id= $fragment-id ]"/>
          </xslt:when>
          
          <xsl:when test="string-length( $fragment-id ) &gt; 0">
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
              <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if> 
			<!-- use for-each to rebase id() to $theDocument -->
			<xsl:for-each select="$theDocument" >
              <xsl:variable name="theFragment" select="$theDocument//*[@xml:id= $fragment-id ]
               | id( $fragment-id ) 
               | $theDocument//*[@id= $fragment-id ]" />
   			<xsl:if test="not($theFragment)">
				<xsl:message terminate="no">
					<xsl:text>Unable to locate id attribute: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
              <xsl:apply-templates select=" $theFragment[1]" mode="dsdl:go"/>
              </xsl:for-each>
		   </xsl:when>
		  
		   <xsl:otherwise>
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
              <xsl:variable name="theFragment" select="$theDocument/*" />
              
              <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
 
   			<xsl:if test="not($theFragment)">
				<xsl:message terminate="no">
					<xsl:text>Unable to locate id attribute: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
       		<xsl:apply-templates select="$theFragment " mode="dsdl:go"/>
       	   </xsl:otherwise>
       </xsl:choose> 
       	
       </xsl:otherwise>
      </xsl:choose>
      <xsl:processing-instruction name="DSDL_INCLUDE_END">  <xsl:value-of select="@href"/></xsl:processing-instruction>
   </xslt:template>
	    
	<!-- =========================================================== -->
	<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages   -->
	<!-- Part 7 - Character Repertoire Description Language - CRDL   -->
	<!-- Final Committee Draft 2008-01-11 Experimental support only  -->
	<!-- =========================================================== -->
	<xslt:template   match="crdl:ref" mode="dsdl:go">
	    <!-- Insert subschema -->
       
       <xsl:variable name="document-uri" select="substring-before(concat(@href,'#'), '#')"/>
       <xsl:variable name="fragment-id" select="substring-after(@href, '#')"/>
 <xsl:processing-instruction name="DSDL_INCLUDE_START">  <xsl:value-of select="@href"/></xsl:processing-instruction>
 <xsl:choose>
       	<xsl:when test="not( $include-crdl = 'true' )">
       	  <xslt:copy>
			<xslt:copy-of select="@*" />
			<xslt:apply-templates mode="dsdl:go"   /> 
		  </xslt:copy>
		</xsl:when>
		<xsl:otherwise>       
       <xsl:choose> 
          
          <xsl:when test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0" >
          	<xsl:message>Error: Impossible URL in CRDL include</xsl:message>
          </xsl:when> 
          
          <!-- this case is when there is in embedded schema in the same document elsewhere -->
          <xslt:when test="string-length( $document-uri ) = 0">
          
              <xslt:apply-templates mode="dsdl:go"
              	select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
              	| //*[@id= $fragment-id ]"/>
          </xslt:when>
          
          <xsl:when test="string-length( $fragment-id ) &gt; 0">
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
               <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>  
			<!-- use for-each to rebase id() to $theDocument -->
			<xsl:for-each select="$theDocument" >
              <xsl:variable name="theFragment" select="$theDocument//*[@xml:id= $fragment-id ]
               | id( $fragment-id )
               | $theDocument//*[@id= $fragment-id ]" />
			
   			<xsl:if test="not($theFragment)">
				<xsl:message terminate="no">
					<xsl:text>Unable to locate id attribute: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
              <xsl:apply-templates select=" $theFragment " mode="dsdl:go"/>
              </xsl:for-each>
		   </xsl:when>
		  
		   <xsl:otherwise>
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
              <xsl:variable name="theFragment" select="$theDocument/*" />
       
               <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
   			<xsl:if test="not($theFragment)">
				<xsl:message terminate="no">
					<xsl:text>Unable to locate id attribute: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
  
       		<xsl:apply-templates select="$theFragment " mode="dsdl:go"/>
       	   </xsl:otherwise>
       </xsl:choose> 
       	
       </xsl:otherwise>
      </xsl:choose>
      <xsl:processing-instruction name="DSDL_INCLUDE_END">  <xsl:value-of select="@href"/></xsl:processing-instruction>
   </xslt:template>
	    
	    
	<!-- =========================================================== -->
	<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages   -->
	<!-- Part 4 - Namespace-based Validation Dispatching Language - NVDL -->
	<!-- Note: This does not include schemas referenced for          -->
	<!-- validation, it merely handles any simple XIncludes          -->
	<!-- =========================================================== -->
	<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages   -->
	<!-- Part 8 - Document Schema Renaming Language - DSRL           -->
	<!-- Note: Final? Committee Draft   Experimental support only    -->
	<!-- =========================================================== -->
	<!-- XInclude support for id based references only, with 1 level -->
	<!-- of fallback.                                                -->
	<!-- =========================================================== -->
	    
	   <xslt:template mode="dsdl:go"
	   	match="xi:include[@href][not(@parseType) or @parseType ='xml']">
	    <!-- Simple inclusions only here --> 
	    <xsl:processing-instruction name="DSDL_INCLUDE_START">  <xsl:value-of select="@href"/></xsl:processing-instruction>
  <xsl:choose>
       	<xsl:when test="not( $include-xinclude = 'true' )">
       	  <xslt:copy>
			<xslt:copy-of select="@*" />
			<xslt:apply-templates mode="dsdl:go"   /> 
		  </xslt:copy>
		</xsl:when>
		<xsl:otherwise>  
       <xsl:choose> 
          
       		<xsl:when  test="contains( @href, '#')">
       			<xsl:message terminate="yes">Fatal error: Xinclude href contains
       				fragment identifier #</xsl:message>
	       </xsl:when>
	       
	       
       		<xsl:when  test="contains( @xpointer, '(')">
       			<xsl:message terminate="yes">Fatal error: Sorry, this software
       			only supports simple ids in XInclude xpointers</xsl:message>
	       </xsl:when>
    
         <xsl:when test="string-length( @href ) = 0 and string-length( @xpointer ) = 0" >
          	
          	<xsl:message terminate="yes">Fatal Error: Impossible URL in XInclude include</xsl:message>
          </xsl:when> 
          
          <!-- this case is when there is in embedded schema in the same document elsewhere -->
          <xslt:when test="string-length( @href ) = 0">
           
              <xslt:apply-templates mode="dsdl:go"
              	select="//*[@xml:id= current()/@xpointer  ] | id( @xpointer)
              	| //*[@id= current()/@xpointer  ]"/>
          </xslt:when>
          
          <xsl:when test="string-length( @xpointer ) &gt; 0">
              <xsl:variable name="theDocument" select="document( @href,/ )" />
              <xsl:variable name="theFragment" select="$theDocument//*[@xml:id= current()/@xpointer  ]
             
              | $theDocument//*[@id= current()/@xpointer  ]" /> 
              <!-- removed
               | $theDocument/id( @xpointer)
               because it requires rebasing in XSLT1 and that would mess up the use of current()
               -->
              
           
              <!-- Allow one level of fallback, to another XInclude -->
              <xsl:if test="not($theDocument)">
                <xsl:choose>
                    <xsl:when test="xi:fallback">
                    	 <xsl:variable name="theDocument" select="document( xi:fallback[1]/xi:include[not(@parseType)
                    	 or @parseType='xml']/@href,/ )" />
              			<xsl:variable name="theFragment" select="$theDocument//*[@xml:id= current()/xi:fallback[1]/xi:include/@xpointer  ]
              				| $theDocument//*[@id= current()/xi:fallback[1]/xi:include/@xpointer  ]" />
              				<!-- removed 
              						| $theDocument/id( xi:fallback[1]/xi:include/@xpointer)
              				because it id() would need rebasing in XSLT1 and that would mess up use of current()
              				-->
             
              				  				<xsl:if test="not($theDocument)">
              				
								<xsl:message terminate="no">
									<xsl:text>Unable to open referenced included file and fallback
									file: </xsl:text>
										<xsl:value-of select="@href"/>
								</xsl:message>
							</xsl:if>
                    </xsl:when>
					<xsl:otherwise>
						<xsl:message terminate="no">
							<xsl:text>Unable to open referenced included file: </xsl:text>
							<xsl:value-of select="@href"/>
						</xsl:message>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:if> 
              <xsl:apply-templates select=" $theFragment" mode="dsdl:go"/> 
		   </xsl:when>
		  
		  <!-- Document but no fragment specified -->
		   <xsl:otherwise>
              <xsl:variable name="theDocument" select="document( @href,/ )" />
              <xsl:variable name="theFragment" select="$theDocument/*" />
               
              <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@href"/>
				</xsl:message>
			</xsl:if>
 
       		<xsl:apply-templates select="$theFragment " mode="dsdl:go"/>
       	   </xsl:otherwise>
       </xsl:choose> 
       	
       </xsl:otherwise>
      </xsl:choose>
      <xsl:processing-instruction name="DSDL_INCLUDE_START">  <xsl:value-of select="@href"/></xsl:processing-instruction>
   </xslt:template>
   
   	<!-- =========================================================== -->
	<!-- W3C XLink 1.1 embedded simple links                        -->
	<!-- =========================================================== -->
	<xslt:template   match="*[@xlink:href][not(parent::*[@xlink:type='complex'])]
	           [not(@xlink:type) or (@xlink:type='simple')]
	           [@xlink:show='embed']
	           [not(@xlink:actuate) or (@xlink:actuate='onLoad')]" 
	           mode="dsdl:go" priority="1"> 
       
       <xsl:variable name="document-uri" select="substring-before(concat(@xlink:href,'#'), '#')"/>
       <xsl:variable name="fragment-id" select="substring-after(@xlink:href, '#')"/>
  <xsl:processing-instruction name="DSDL_INCLUDE_START">  <xsl:value-of select="@xlink:href"/></xsl:processing-instruction>
	            <xsl:choose>
       	<xsl:when test="not( $include-xlink = 'true' )">
       	  <xslt:copy>
			<xslt:copy-of select="@*" />
			<xslt:apply-templates mode="dsdl:go"   /> 
		  </xslt:copy>
		</xsl:when>
		<xsl:otherwise>     
       <xsl:choose> 
          
          <xsl:when test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0" >
          	<xsl:message>Error: Impossible URL in XLink embedding link</xsl:message>
          </xsl:when> 
          
          <!-- this case is when there is in embedded schema in the same document elsewhere -->
          <xslt:when test="string-length( $document-uri ) = 0">
              <xslt:apply-templates mode="dsdl:go"
              	select="//*[@xml:id= $fragment-id ] | id( $fragment-id) 
              	| //*[@id= $fragment-id ]"/>
          </xslt:when>
          
          <xsl:when test="string-length( $fragment-id ) &gt; 0">
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
              <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@xlink:href"/>
				</xsl:message>
			</xsl:if> 
			<!-- use for-each to rebase id() to $theDocument -->
			<xsl:for-each select="$theDocument" >
              <xsl:variable name="theFragment" select="$theDocument//*[@xml:id= $fragment-id ]
               | id( $fragment-id ) 
               | $theDocument//*[@id= $fragment-id ]" />
   			<xsl:if test="not($theFragment)">
				<xsl:message terminate="no">
					<xsl:text>Unable to locate id attribute: </xsl:text>
					<xsl:value-of select="@xlink:href"/>
				</xsl:message>
			</xsl:if>
              <xsl:apply-templates select=" $theFragment[1]" mode="dsdl:go"/>
              </xsl:for-each>
		   </xsl:when>
		  
		   <xsl:otherwise>
              <xsl:variable name="theDocument" select="document( $document-uri,/ )" />
              <xsl:variable name="theFragment" select="$theDocument/*" />
              
              <xsl:if test="not($theDocument)">
				<xsl:message terminate="no">
					<xsl:text>Unable to open referenced included file: </xsl:text>
					<xsl:value-of select="@xlink:href"/>
				</xsl:message>
			</xsl:if>
 
   			<xsl:if test="not($theFragment)">
				<xsl:message terminate="no">
					<xsl:text>Unable to locate id attribute: </xsl:text>
					<xsl:value-of select="@xlink:href"/>
				</xsl:message>
			</xsl:if>
       		<xsl:apply-templates select="$theFragment " mode="dsdl:go"/>
       	   </xsl:otherwise>
       </xsl:choose> 
       
       </xsl:otherwise>
      </xsl:choose>
       	
  <xsl:processing-instruction name="DSDL_INCLUDE_START">  <xsl:value-of select="@xlink:href"/></xsl:processing-instruction>
   </xslt:template>
	    
	    
</xslt:stylesheet>