Browse code

Everything

Apollia authored on 02/04/2017 22:53:47
Showing 21 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,51 @@
1
+# A simple Schematron demo for PHP 5.6.28 and Saxon/C 1.0.2
2
+
3
+I got this to work in Lighthouse 64 Puppy Linux 6.02 Beta 2.  http://lhpup.org/
4
+
5
+Haven't yet tried it in any other GNU/Linux.
6
+
7
+----
8
+
9
+The Schematron files in the "code" folder all came from the official Schematron repo:
10
+
11
+https://github.com/Schematron/schematron
12
+
13
+https://github.com/Schematron/schematron/tree/master/trunk/schematron/code
14
+
15
+
16
+The "dog-properties.sch" Schematron schema is my slightly modified, simpler version of the "test-properties.sch" file included in the official Schematron repo.
17
+
18
+https://github.com/Schematron/schematron/tree/master/trunk/schematron/test/properties
19
+
20
+----
21
+
22
+Here's a helpful introduction to the XML-validation language Schematron:
23
+
24
+http://www.xml.com/pub/a/2003/11/12/schematron.html
25
+
26
+To use Schematron, all you need is an XSLT processor, such as Saxon.
27
+
28
+https://en.wikipedia.org/wiki/XSLT
29
+
30
+----
31
+
32
+Saxon/C home page:
33
+
34
+http://www.saxonica.com/saxon-c/index.xml
35
+
36
+Documentation of Saxon/C PHP API:
37
+
38
+http://www.saxonica.com/saxon-c/doc/html/index.html#php-api
39
+
40
+----
41
+
42
+Here's my blog post on making Saxon/C into a PHP extension:
43
+
44
+http://astroblahhh.com/blog/puppy-linux/how-to-make-saxon-c-into-a-php-extension-for-php-5-6-13-in-lucid-puppy-linux-5-2-360.shtml#blogtoc
45
+
46
+----
47
+
48
+Some Rox-Filer run action scripts I made to make it easier to run PHP scripts without a web server:
49
+
50
+https://github.com/Apollia/Without-web-server-run-PHP-script-and-view-output-in-web-browser
51
+
0 52
new file mode 100644
... ...
@@ -0,0 +1,313 @@
1
+<?xml version="1.0" encoding="UTF-8"?><?xar XSLT?>
2
+
3
+<!-- 
4
+     OVERVIEW - iso_abstract_expand.xsl
5
+     
6
+	    This is a preprocessor for ISO Schematron, which implements abstract patterns. 
7
+	    It also 
8
+	       	* extracts a particular schema using an ID, where there are multiple 
9
+             schemas, such as when they are embedded in the same NVDL script 
10
+           * allows parameter substitution inside @context, @test, @select, @path
11
+	    	   * experimentally, allows parameter recognition and substitution inside
12
+             text (NOTE: to be removed, for compataibility with other implementations,   
13
+             please do not use this) 
14
+		
15
+		This should be used after iso-dsdl-include.xsl and before the skeleton or
16
+		meta-stylesheet (e.g. iso-svrl.xsl) . It only requires XSLT 1.
17
+		 
18
+		Each kind of inclusion can be turned off (or on) on the command line.
19
+		 
20
+-->
21
+
22
+<!--
23
+Open Source Initiative OSI - The MIT License:Licensing
24
+[OSI Approved License]
25
+
26
+This source code was previously available under the zlib/libpng license. 
27
+Attribution is polite.
28
+
29
+The MIT License
30
+
31
+Copyright (c) 2004-2010  Rick Jellife and Academia Sinica Computing Centre, Taiwan
32
+
33
+Permission is hereby granted, free of charge, to any person obtaining a copy
34
+of this software and associated documentation files (the "Software"), to deal
35
+in the Software without restriction, including without limitation the rights
36
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37
+copies of the Software, and to permit persons to whom the Software is
38
+furnished to do so, subject to the following conditions:
39
+
40
+The above copyright notice and this permission notice shall be included in
41
+all copies or substantial portions of the Software.
42
+
43
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
49
+THE SOFTWARE.
50
+-->
51
+
52
+<!--
53
+VERSION INFORMATION
54
+  2013-09-19 RJ
55
+     * Allow macro expansion in  @path attributes, eg. for   sch:name/@path
56
+
57
+  2010-07-10 RJ
58
+  		* Move to MIT license
59
+  		
60
+  2008-09-18 RJ
61
+  		* move out param test from iso:schema template  to work with XSLT 1. (Noah Fontes)
62
+  		
63
+  2008-07-29 RJ 
64
+  		* Create.  Pull out as distinct XSL in its own namespace from old iso_pre_pro.xsl
65
+  		* Put everything in private namespace
66
+  		* Rewrite replace_substring named template so that copyright is clear
67
+  	
68
+  2008-07-24 RJ
69
+       * correct abstract patterns so for correct names: param/@name and
70
+     param/@value
71
+    
72
+  2007-01-12  RJ 
73
+     * Use ISO namespace
74
+     * Use pattern/@id not  pattern/@name 
75
+     * Add Oliver Becker's suggests from old Schematron-love-in list for <copy> 
76
+     * Add XT -ism?
77
+  2003 RJ
78
+     * Original written for old namespace
79
+     * http://www.topologi.com/resources/iso-pre-pro.xsl
80
+-->	
81
+<xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform" 
82
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
83
+    xmlns:iso="http://purl.oclc.org/dsdl/schematron"  
84
+    xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl"  
85
+    
86
+    xmlns:iae="http://www.schematron.com/namespace/iae" 
87
+     
88
+      >
89
+	
90
+	<xslt:param name="schema-id"></xslt:param>
91
+	
92
+	
93
+	<!-- Driver for the mode -->
94
+	<xsl:template match="/">
95
+  		<xsl:apply-templates select="." mode="iae:go" />
96
+	</xsl:template> 
97
+	
98
+	
99
+	<!-- ================================================================================== -->
100
+	<!-- Normal processing rules                                                            -->
101
+	<!-- ================================================================================== -->
102
+	<!-- Output only the selected schema --> 
103
+	<xslt:template match="iso:schema" >
104
+	    <xsl:if test="string-length($schema-id) =0 or @id= $schema-id ">
105
+	    	<xslt:copy>
106
+				<xslt:copy-of select="@*" />
107
+				<xslt:apply-templates  mode="iae:go" /> 
108
+			</xslt:copy>
109
+		</xsl:if>
110
+	</xslt:template>
111
+	
112
+ 
113
+	<!-- Strip out any foreign elements above the Schematron schema .
114
+		-->
115
+	<xslt:template match="*[not(ancestor-or-self::iso:*)]"     mode="iae:go"  >
116
+	   <xslt:apply-templates  mode="iae:go" />
117
+	</xslt:template>
118
+	   
119
+	
120
+	<!-- ================================================================================== -->
121
+	<!-- Handle Schematron abstract pattern preprocessing                                   -->
122
+	<!-- abstract-to-real calls
123
+			do-pattern calls 
124
+				macro-expand calls 
125
+					multi-macro-expand
126
+						replace-substring                                                   -->
127
+	<!-- ================================================================================== -->
128
+	
129
+	<!--
130
+		Abstract patterns allow you to say, for example
131
+		
132
+		<pattern name="htmlTable" is-a="table">
133
+			<param name="row" value="html:tr"/>
134
+			<param name="cell" value="html:td" />
135
+			<param name="table" value="html:table" />
136
+		</pattern>
137
+		
138
+		For a good introduction, see Uche Ogbujii's article for IBM DeveloperWorks
139
+		"Discover the flexibility of Schematron abstract patterns"
140
+		  http://www-128.ibm.com/developerworks/xml/library/x-stron.html
141
+		However, note that ISO Schematron uses @name and @value attributes on
142
+		the iso:param element, and @id not @name on the pattern element.
143
+		
144
+	-->
145
+	
146
+	<!-- Suppress declarations of abstract patterns -->
147
+	<xslt:template match="iso:pattern[@abstract='true']"  mode="iae:go"  >
148
+		<xslt:comment>Suppressed abstract pattern <xslt:value-of select="@id"/> was here</xslt:comment>	
149
+	</xslt:template> 
150
+	
151
+	
152
+	<!-- Suppress uses of abstract patterns -->
153
+	<xslt:template match="iso:pattern[@is-a]"  mode="iae:go" >
154
+			
155
+		<xslt:comment>Start pattern based on abstract <xslt:value-of select="@is-a"/></xslt:comment>
156
+		
157
+		<xslt:call-template name="iae:abstract-to-real" >
158
+			<xslt:with-param name="caller" select="@id" />
159
+			<xslt:with-param name="is-a" select="@is-a" />
160
+		</xslt:call-template>
161
+			
162
+	</xslt:template>
163
+	 
164
+	 
165
+	
166
+	<!-- output everything else unchanged -->
167
+	<xslt:template match="*" priority="-1"  mode="iae:go" >
168
+	    <xslt:copy>
169
+			<xslt:copy-of select="@*" />
170
+			<xslt:apply-templates mode="iae:go"/> 
171
+		</xslt:copy>
172
+	</xslt:template>
173
+	
174
+	<!-- Templates for macro expansion of abstract patterns -->
175
+	<!-- Sets up the initial conditions for the recursive call -->
176
+	<xslt:template name="iae:macro-expand">
177
+		<xslt:param name="caller"/>
178
+		<xslt:param name="text" />
179
+		<xslt:call-template name="iae:multi-macro-expand">
180
+			<xslt:with-param name="caller" select="$caller"/>
181
+			<xslt:with-param name="text" select="$text"/>
182
+			<xslt:with-param name="paramNumber" select="1"/>
183
+		</xslt:call-template>
184
+		
185
+	</xslt:template>
186
+	
187
+	<!-- Template to replace the current parameter and then
188
+	   recurse to replace subsequent parameters. -->
189
+	    
190
+	<xslt:template name="iae:multi-macro-expand">
191
+		<xslt:param name="caller"/>
192
+		<xslt:param name="text" />
193
+		<xslt:param name="paramNumber" />
194
+
195
+		
196
+		<xslt:choose>
197
+			<xslt:when test="//iso:pattern[@id=$caller]/iso:param[ $paramNumber]">
198
+
199
+				<xslt:call-template name="iae:multi-macro-expand">
200
+					<xslt:with-param name="caller" select="$caller"/>	
201
+					<xslt:with-param name="paramNumber" select="$paramNumber + 1"/>		
202
+					<xslt:with-param name="text" >
203
+						<xslt:call-template name="iae:replace-substring">
204
+							<xslt:with-param name="original" select="$text"/>
205
+							<xslt:with-param name="substring"
206
+							select="concat('$', //iso:pattern[@id=$caller]/iso:param[ $paramNumber ]/@name)"/>
207
+							<xslt:with-param name="replacement"
208
+								select="//iso:pattern[@id=$caller]/iso:param[ $paramNumber ]/@value"/>			
209
+						</xslt:call-template>
210
+					</xslt:with-param>						
211
+				</xslt:call-template>
212
+			</xslt:when>
213
+			<xslt:otherwise><xslt:value-of select="$text" /></xslt:otherwise>		
214
+		
215
+		</xslt:choose>
216
+	</xslt:template>
217
+	
218
+	
219
+	<!-- generate the real pattern from an abstract pattern + parameters-->
220
+	<xslt:template name="iae:abstract-to-real" >
221
+		<xslt:param name="caller"/>
222
+		<xslt:param name="is-a" />
223
+		<xslt:for-each select="//iso:pattern[@id= $is-a]">
224
+		<xslt:copy>
225
+		
226
+		    <xslt:choose>
227
+		      <xslt:when test=" string-length( $caller ) = 0">
228
+		      <xslt:attribute name="id"><xslt:value-of select="concat( generate-id(.) , $is-a)" /></xslt:attribute>
229
+		      </xslt:when>
230
+		      <xslt:otherwise>
231
+				<xslt:attribute name="id"><xslt:value-of select="$caller" /></xslt:attribute>
232
+		      </xslt:otherwise>
233
+		    </xslt:choose> 
234
+			
235
+			<xslt:apply-templates select="*|text()" mode="iae:do-pattern"    >
236
+				<xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
237
+			</xslt:apply-templates>	
238
+			
239
+		</xslt:copy>
240
+		</xslt:for-each>
241
+	</xslt:template>
242
+		
243
+	
244
+	<!-- Generate a non-abstract pattern -->
245
+	<xslt:template mode="iae:do-pattern" match="*">
246
+		<xslt:param name="caller"/>
247
+		<xslt:copy>
248
+			<xslt:for-each select="@*[name()='test' or name()='context' or name()='select'   or name()='path'  ]">
249
+				<xslt:attribute name="{name()}">
250
+				<xslt:call-template name="iae:macro-expand">
251
+						<xslt:with-param name="text"><xslt:value-of select="."/></xslt:with-param>
252
+						<xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
253
+					</xslt:call-template>
254
+				</xslt:attribute>
255
+			</xslt:for-each>	
256
+			<xslt:copy-of select="@*[name()!='test'][name()!='context'][name()!='select'][name()!='path']" />
257
+			<xsl:for-each select="node()">
258
+				<xsl:choose>
259
+				    <!-- Experiment: replace macros in text as well, to allow parameterized assertions
260
+				        and so on, without having to have spurious <iso:value-of> calls and multiple
261
+				        delimiting.
262
+                NOTE: THIS FUNCTIONALITY WILL BE REMOVED IN THE FUTURE    -->
263
+					<xsl:when test="self::text()">	
264
+						<xslt:call-template name="iae:macro-expand">
265
+							<xslt:with-param name="text"><xslt:value-of select="."/></xslt:with-param>
266
+							<xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
267
+						</xslt:call-template>
268
+					</xsl:when>
269
+					<xsl:otherwise>
270
+						<xslt:apply-templates select="." mode="iae:do-pattern">
271
+							<xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
272
+						</xslt:apply-templates>		
273
+					</xsl:otherwise>
274
+				</xsl:choose>
275
+			</xsl:for-each>			
276
+		</xslt:copy>
277
+	</xslt:template>
278
+	
279
+	<!-- UTILITIES --> 
280
+	<!-- Simple version of replace-substring function -->
281
+	<xslt:template name="iae:replace-substring">
282
+		<xslt:param name="original" />    
283
+		<xslt:param name="substring" />   
284
+		<xslt:param name="replacement" select="''"/>
285
+		
286
+  <xsl:choose>
287
+    <xsl:when test="not($original)" /> 
288
+    <xsl:when test="not(string($substring))">
289
+      <xsl:value-of select="$original" />
290
+    </xsl:when> 
291
+        <xsl:when test="contains($original, $substring)">
292
+          <xsl:variable name="before" select="substring-before($original, $substring)" />
293
+          <xsl:variable name="after" select="substring-after($original, $substring)" />
294
+          
295
+          <xsl:value-of select="$before" />
296
+          <xsl:value-of select="$replacement" />
297
+          <!-- recursion -->
298
+          <xsl:call-template name="iae:replace-substring">
299
+            <xsl:with-param name="original" select="$after" />
300
+            <xsl:with-param name="substring" select="$substring" />
301
+            <xsl:with-param name="replacement" select="$replacement" /> 
302
+            </xsl:call-template>
303
+        </xsl:when>
304
+        <xsl:otherwise>
305
+        	<!-- no substitution -->
306
+        	<xsl:value-of select="$original" />
307
+        </xsl:otherwise>
308
+      </xsl:choose> 
309
+</xslt:template>
310
+
311
+
312
+
313
+</xslt:stylesheet>
0 314
\ No newline at end of file
1 315
new file mode 100644
... ...
@@ -0,0 +1,1519 @@
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
+Open Source Initiative OSI - The MIT License:Licensing
44
+[OSI Approved License]
45
+
46
+This source code was previously available under the zlib/libpng license. 
47
+Attribution is polite.
48
+
49
+The MIT License
50
+
51
+Copyright (c) 2008-2010 Rick Jelliffe
52
+
53
+Permission is hereby granted, free of charge, to any person obtaining a copy
54
+of this software and associated documentation files (the "Software"), to deal
55
+in the Software without restriction, including without limitation the rights
56
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
57
+copies of the Software, and to permit persons to whom the Software is
58
+furnished to do so, subject to the following conditions:
59
+
60
+The above copyright notice and this permission notice shall be included in
61
+all copies or substantial portions of the Software.
62
+
63
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
64
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
65
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
66
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
67
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
68
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
69
+THE SOFTWARE.
70
+-->
71
+
72
+<!-- 
73
+  VERSION INFORMATION
74
+    2010-07-10
75
+    * Move to MIT license
76
+    2010-04-21
77
+    * Add basic syntax checks on XPaths belonging to Schematron elements only
78
+    * Unlocalized messages are put out using xsl:message. The intent is to allow
79
+    * problems to be caught at compile time. 
80
+	2009-02-25 
81
+	* Update DSDL namespace to use schematron.com
82
+	* Tested with SAXON9, Xalan 2.7.1, IE7, 
83
+	* IE does not like multiple variables in same template with same name: rename.   
84
+	2008-09-18
85
+	* Remove new behaviour for include, because it conflicts with existing usage [KH]
86
+	* Add extends[@href] element with that merge functionality
87
+	* Generate PIs to notate source of inclusions for potential better diagnostics
88
+	
89
+	2008-09-16
90
+	* Fix for XSLT1
91
+	
92
+	2008-08-28
93
+	* New behaviour for schematron includes: if the pointed to element is the same as the current,
94
+	include the children. [Note: this has been removed: use sch:extends with @href.]
95
+	
96
+	2008-08-20
97
+	* Fix bug: in XSLT1 cannot do $document/id('x') but need to use for-each
98
+	
99
+	2008-08-04
100
+	* Add support for inclusions in old namespace  
101
+	
102
+	2008-08-03
103
+	* Fix wrong param name include-relaxng & include-crdl (KH, PH)
104
+	* Allow inclusion of XSLT and XHTML (KH)
105
+	* Fix inclusion of fragments (KH)
106
+	
107
+	2008-07-25
108
+	* Add selectable input parameter
109
+	
110
+	2008-07-24  
111
+	* RJ New
112
+-->
113
+
114
+<xslt:stylesheet version="1.0"
115
+	xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
116
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
117
+	xmlns:iso="http://purl.oclc.org/dsdl/schematron"
118
+	xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl"
119
+	xmlns:xhtml="http://www.w3.org/1999/xhtml"
120
+	xmlns:schold="http://www.ascc.net/xml/schematron"
121
+	xmlns:crdl="http://purl.oclc.org/dsdl/crepdl/ns/structure/1.0"
122
+	xmlns:xi="http://www.w3.org/2001/XInclude"
123
+	xmlns:dtll="http://www.jenitennison.com/datatypes"
124
+	xmlns:dsdl="http://www.schematron.com/namespace/dsdl"
125
+	xmlns:relax="http://relaxng.org/ns/structure/1.0"
126
+	xmlns:xlink="http://www.w3.org/1999/xlink"
127
+	
128
+	
129
+     xmlns:sch-check="http://www.schematron.com/namespace/sch-check" 
130
+	>
131
+	<!-- Note: The URL for the dsdl namespace is not official -->
132
+
133
+
134
+	<xsl:param name="include-schematron">true</xsl:param>
135
+	<xsl:param name="include-crdl">true</xsl:param>
136
+	<xsl:param name="include-xinclude">true</xsl:param>
137
+	<xsl:param name="include-dtll">true</xsl:param>
138
+	<xsl:param name="include-relaxng">true</xsl:param>
139
+	<xsl:param name="include-xlink">true</xsl:param>
140
+
141
+   
142
+    <!-- ========================================================== -->
143
+    <!-- Output and process contents, check Schematron XPaths too   -->
144
+    <!-- ========================================================== -->
145
+    
146
+	<xsl:template match="/">
147
+		<xsl:apply-templates select="." mode="dsdl:go" />
148
+	</xsl:template>
149
+
150
+	<!-- output everything else unchanged. But check Xpaths here.  -->
151
+
152
+	<xslt:template match="iso:rule[@context]"  mode="dsdl:go">
153
+	  <xsl:call-template name="sch-check:xpath-wf-message">
154
+          <xsl:with-param name="string" select=" @context "  />
155
+          <xsl:with-param name="subject" select=" 'Bad rule: ' "  />
156
+        </xsl:call-template>
157
+        
158
+		<xslt:copy>
159
+			<xslt:copy-of select="@*" />
160
+			<xslt:apply-templates mode="dsdl:go" />
161
+		</xslt:copy>
162
+	</xslt:template>
163
+	
164
+	<xslt:template match="iso:assert[@test]"  mode="dsdl:go">
165
+	  <xsl:call-template name="sch-check:xpath-wf-message">
166
+          <xsl:with-param name="string" select=" @test "  />
167
+          <xsl:with-param name="subject" select=" 'Bad assert: ' "  />
168
+        </xsl:call-template>
169
+        
170
+		<xslt:copy>
171
+			<xslt:copy-of select="@*" />
172
+			<xslt:apply-templates mode="dsdl:go" />
173
+		</xslt:copy>
174
+	</xslt:template>
175
+	
176
+	<xslt:template match="iso:report[@test]"  mode="dsdl:go">
177
+	  <xsl:call-template name="sch-check:xpath-wf-message">
178
+          <xsl:with-param name="string" select=" @test "  />
179
+          <xsl:with-param name="subject" select=" 'Bad report: ' "  />
180
+        </xsl:call-template>
181
+        
182
+		<xslt:copy>
183
+			<xslt:copy-of select="@*" />
184
+			<xslt:apply-templates mode="dsdl:go" />
185
+		</xslt:copy>
186
+	</xslt:template>
187
+	
188
+	<xslt:template match="iso:let[@value]"  mode="dsdl:go">
189
+	  <xsl:call-template name="sch-check:xpath-wf-message">
190
+          <xsl:with-param name="string" select=" @value "  />
191
+          <xsl:with-param name="subject" select=" 'Bad let: ' "  />
192
+        </xsl:call-template>
193
+        
194
+		<xslt:copy>
195
+			<xslt:copy-of select="@*" />
196
+			<xslt:apply-templates mode="dsdl:go" />
197
+		</xslt:copy>
198
+	</xslt:template>
199
+	
200
+	
201
+		<xslt:template match="iso:value-of[@select]" mode="dsdl:go">
202
+	  <xsl:call-template name="sch-check:xpath-wf-message">
203
+          <xsl:with-param name="string" select=" @select "  />
204
+          <xsl:with-param name="subject" select=" 'Bad value-of: ' "  />
205
+        </xsl:call-template>
206
+        
207
+		<xslt:copy>
208
+			<xslt:copy-of select="@*" />
209
+			<xslt:apply-templates mode="dsdl:go" />
210
+		</xslt:copy>
211
+	</xslt:template>
212
+	
213
+		<xslt:template match="iso:name[@path]" mode="dsdl:go">
214
+	  <xsl:call-template name="sch-check:xpath-wf-message">
215
+          <xsl:with-param name="string" select=" @select "  />
216
+          <xsl:with-param name="subject" select=" 'Bad name element: ' "  />
217
+        </xsl:call-template>
218
+        
219
+		<xslt:copy>
220
+			<xslt:copy-of select="@*" />
221
+			<xslt:apply-templates mode="dsdl:go" />
222
+		</xslt:copy>
223
+	</xslt:template>
224
+
225
+		<!-- output everything else unchanged -->
226
+	<xslt:template match="node()" priority="-1" mode="dsdl:go">
227
+		<xslt:copy>
228
+			<xslt:copy-of select="@*" />
229
+			<xslt:apply-templates mode="dsdl:go" />
230
+		</xslt:copy>
231
+	</xslt:template>
232
+
233
+
234
+
235
+	<!-- =========================================================== -->
236
+	<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages   -->
237
+	<!-- Part 2 - Regular grammar-based validation - RELAX NG        -->
238
+	<!-- This only implements relax:extRef not relax:include which   -->
239
+	<!-- is complex.                                                 -->
240
+	<!-- =========================================================== -->
241
+	<xslt:template match="relax:extRef" mode="dsdl:go">
242
+
243
+
244
+		<!-- Insert subschema -->
245
+
246
+		<xsl:variable name="document-uri"
247
+			select="substring-before(concat(@href,'#'), '#')" />
248
+		<xsl:variable name="fragment-id"
249
+			select="substring-after(@href, '#')" />
250
+
251
+		<xsl:processing-instruction name="DSDL_INCLUDE_START">
252
+			<xsl:value-of select="@href" />
253
+		</xsl:processing-instruction>
254
+		<xsl:choose>
255
+			<xsl:when test="not( $include-relaxng = 'true' )">
256
+				<xslt:copy>
257
+					<xslt:copy-of select="@*" />
258
+					<xslt:apply-templates mode="dsdl:go" />
259
+				</xslt:copy>
260
+			</xsl:when>
261
+			<xsl:otherwise>
262
+
263
+				<xsl:choose>
264
+
265
+					<xsl:when
266
+						test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
267
+						<xsl:message>
268
+							Error: Impossible URL in RELAX NG extRef
269
+							include
270
+						</xsl:message>
271
+					</xsl:when>
272
+
273
+					<!-- this case is when there is in embedded schema in the same document elsewhere -->
274
+					<xslt:when
275
+						test="string-length( $document-uri ) = 0">
276
+						<xslt:apply-templates mode="dsdl:go"
277
+							select="//*[@xml:id= $fragment-id ] | id( $fragment-id) | //*[@id= $fragment-id ]" />
278
+					</xslt:when>
279
+
280
+					<xsl:when
281
+						test="string-length( $fragment-id ) &gt; 0">
282
+						<xsl:variable name="theDocument_1"
283
+							select="document( $document-uri,/ )" />
284
+
285
+						<xsl:if test="not($theDocument_1)">
286
+							<xsl:message terminate="no">
287
+								<xsl:text>Unable to open referenced included file: </xsl:text>
288
+								<xsl:value-of select="@href" />
289
+							</xsl:message>
290
+						</xsl:if>
291
+						<!-- use a for-each so that the id() function works correctly on the external document -->
292
+						<xsl:for-each select="$theDocument_1">
293
+							<xsl:variable name="theFragment_1"
294
+								select="$theDocument_1//*[@xml:id= $fragment-id ]        
295
+                  |  id( $fragment-id)          
296
+              | $theDocument_1//*[@id= $fragment-id ]" />
297
+							<xsl:if test="not($theFragment_1)">
298
+								<xsl:message terminate="no">
299
+									<xsl:text>Unable to locate id attribute: </xsl:text>
300
+									<xsl:value-of select="@href" />
301
+								</xsl:message>
302
+							</xsl:if>
303
+							<xsl:apply-templates
304
+								select=" $theFragment_1[1]" mode="dsdl:go" />
305
+						</xsl:for-each>
306
+					</xsl:when>
307
+
308
+					<xsl:otherwise>
309
+						<xsl:variable name="theDocument_2"
310
+							select="document( $document-uri,/ )" />
311
+						<xsl:variable name="theFragment_2"
312
+							select="$theDocument_2/*" />
313
+						<xsl:if test="not($theDocument_2)">
314
+							<xsl:message terminate="no">
315
+								<xsl:text>Unable to open referenced included file: </xsl:text>
316
+								<xsl:value-of select="@href" />
317
+							</xsl:message>
318
+						</xsl:if>
319
+
320
+						<xsl:if test="not($theFragment_2)">
321
+							<xsl:message terminate="no">
322
+								<xsl:text>Unable to locate id attribute: </xsl:text>
323
+								<xsl:value-of select="@href" />
324
+							</xsl:message>
325
+						</xsl:if>
326
+						<xsl:apply-templates select="$theFragment_2 "
327
+							mode="dsdl:go" />
328
+					</xsl:otherwise>
329
+				</xsl:choose>
330
+
331
+			</xsl:otherwise>
332
+		</xsl:choose>
333
+
334
+		<xsl:processing-instruction name="DSDL_INCLUDE_END">
335
+			<xsl:value-of select="@href" />
336
+		</xsl:processing-instruction>
337
+	</xslt:template>
338
+
339
+
340
+
341
+	<!-- =========================================================== -->
342
+	<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages   -->
343
+	<!-- Part 3 - Rule-based validation - Schematron                 -->
344
+	<!-- =========================================================== -->
345
+
346
+
347
+	<!-- Extend the URI syntax to allow # references -->
348
+	<!-- Add experimental support for simple containers like  /xxx:xxx/iso:pattern to allow better includes -->
349
+	<xsl:template match="iso:include" mode="dsdl:go">
350
+
351
+		<xsl:variable name="document-uri"
352
+			select="substring-before(concat(@href,'#'), '#')" />
353
+		<xsl:variable name="fragment-id"
354
+			select="substring-after(@href, '#')" />
355
+
356
+
357
+		<xsl:processing-instruction name="DSDL_INCLUDE_START">
358
+			<xsl:value-of select="@href" />
359
+		</xsl:processing-instruction>
360
+
361
+		<xsl:choose>
362
+			<xsl:when test="not( $include-schematron = 'true' )">
363
+				<xslt:copy>
364
+					<xslt:copy-of select="@*" />
365
+					<xslt:apply-templates mode="dsdl:go" />
366
+				</xslt:copy>
367
+			</xsl:when>
368
+			<xsl:otherwise>
369
+
370
+				<xsl:choose>
371
+
372
+					<xsl:when
373
+						test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
374
+						<xsl:message>
375
+							Error: Impossible URL in Schematron include
376
+						</xsl:message>
377
+					</xsl:when>
378
+
379
+					<!-- this case is when there is in embedded schema in the same document elsewhere -->
380
+					<xslt:when
381
+						test="string-length( $document-uri ) = 0">
382
+						<xslt:apply-templates mode="dsdl:go"
383
+							select="//iso:*[@xml:id= $fragment-id ] 
384
+              	 |id( $fragment-id)
385
+              	 | //iso:*[@id= $fragment-id ]" />
386
+					</xslt:when>
387
+
388
+					<!-- case where there is a fragment in another document (should be an iso: element) -->
389
+					<!-- There are three cases for includes with fragment:
390
+						0) No href file or no matching id - error!
391
+						1) REMOVED
392
+						
393
+						2) The linked-to element is sch:schema however the parent of the include
394
+						is not a schema. In this case, it is an error. (Actually, it should
395
+						be an error for other kinds of containment problems, but we won't
396
+						check for them in this version.)
397
+						
398
+						3) Otherwise, include the pointed-to element
399
+					-->
400
+
401
+					<xsl:when
402
+						test="string-length( $fragment-id ) &gt; 0">
403
+						<xsl:variable name="theDocument_1"
404
+							select="document( $document-uri,/ )" />
405
+						<xsl:variable name="originalParent" select=".." />
406
+
407
+						<!-- case 0 -->
408
+						<xsl:if test="not($theDocument_1)">
409
+							<xsl:message terminate="no">
410
+								<xsl:text>Unable to open referenced included file: </xsl:text>
411
+								<xsl:value-of select="@href" />
412
+							</xsl:message>
413
+						</xsl:if>
414
+						<!-- use for-each to rebase id() to external document -->
415
+						<xsl:for-each select="$theDocument_1">
416
+							<xsl:variable name="theFragment_1"
417
+								select=" $theDocument_1//iso:*[@xml:id= $fragment-id ] |
418
+              	 		id($fragment-id) |
419
+              			$theDocument_1//iso:*[@id= $fragment-id ]" />
420
+
421
+
422
+							<xsl:choose>
423
+								<!-- case 0 -->
424
+								<xsl:when test="not($theFragment_1)">
425
+									<xsl:message terminate="no">
426
+										<xsl:text>Unable to locate id attribute: </xsl:text>
427
+										<xsl:value-of select="@href" />
428
+									</xsl:message>
429
+								</xsl:when>
430
+
431
+
432
+								<!-- case 1 REMOVED -->
433
+
434
+								<!-- case 2 -->
435
+								<xsl:when
436
+									test=" $theFragment_1/self::iso:schema ">
437
+									<xsl:message>
438
+										Schema error: Use include to
439
+										include fragments, not a whole
440
+										schema
441
+									</xsl:message>
442
+								</xsl:when>
443
+
444
+								<!-- case 3 -->
445
+								<xsl:otherwise>
446
+									<xsl:apply-templates
447
+										select=" $theFragment_1[1]" mode="dsdl:go" />
448
+								</xsl:otherwise>
449
+							</xsl:choose>
450
+						</xsl:for-each>
451
+					</xsl:when>
452
+
453
+					<!-- Case where there is no ID so we include the whole document -->
454
+					<!-- Experimental addition: include fragments of children -->
455
+					<xsl:otherwise>
456
+						<xsl:variable name="theDocument_2"
457
+							select="document( $document-uri,/ )" />
458
+						<xsl:variable name="theFragment_2"
459
+							select="$theDocument_2/iso:*" />
460
+						<xsl:variable name="theContainedFragments"
461
+							select="$theDocument_2/*/iso:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
462
+						<xsl:if test="not($theDocument_2)">
463
+							<xsl:message terminate="no">
464
+								<xsl:text>Unable to open referenced included file: </xsl:text>
465
+								<xsl:value-of select="@href" />
466
+							</xsl:message>
467
+						</xsl:if>
468
+
469
+						<!-- There are three cases for includes:
470
+							0) No text specified- error!
471
+							
472
+							1) REMOVED
473
+							
474
+							2) The linked-to element is sch:schema however the parent of the include
475
+							is not a schema. In this case, it is an error. (Actually, it should
476
+							be an error for other kinds of containment problems, but we won't
477
+							check for them in this version.)
478
+							
479
+							3) Otherwise, include the pointed-to element
480
+						-->
481
+						<xsl:choose>
482
+							<!-- case 0 -->
483
+							<xsl:when
484
+								test="not($theFragment_2) and not ($theContainedFragments)">
485
+								<xsl:message terminate="no">
486
+									<xsl:text>Unable to locate id attribute: </xsl:text>
487
+									<xsl:value-of select="@href" />
488
+								</xsl:message>
489
+							</xsl:when>
490
+
491
+							<!-- case 1 removed -->
492
+
493
+							<!-- case 2 -->
494
+							<xsl:when
495
+								test=" $theFragment_2/self::iso:schema or $theContainedFragments/self::iso:schema">
496
+								<xsl:message>
497
+									Schema error: Use include to include
498
+									fragments, not a whole schema
499
+								</xsl:message>
500
+							</xsl:when>
501
+
502
+							<!-- If this were XLST 2, we could use  
503
+								if ($theFragment) then $theFragment else $theContainedFragments
504
+								here (thanks to KN)
505
+							-->
506
+							<!-- case 3 -->
507
+							<xsl:otherwise>
508
+								<xsl:apply-templates
509
+									select="$theFragment_2 " mode="dsdl:go" />
510
+							</xsl:otherwise>
511
+						</xsl:choose>
512
+					</xsl:otherwise>
513
+				</xsl:choose>
514
+			</xsl:otherwise>
515
+		</xsl:choose>
516
+
517
+		<xsl:processing-instruction name="DSDL_INCLUDE_END">
518
+			<xsl:value-of select="@href" />
519
+		</xsl:processing-instruction>
520
+	</xsl:template>
521
+
522
+
523
+	<!-- WARNING   sch:extends[@href] is experimental and non standard  -->
524
+	<!-- Basically, it adds the children of the selected element, not the element itself.  -->
525
+	<xsl:template match="iso:extends[@href]" mode="dsdl:go">
526
+
527
+		<xsl:variable name="document-uri"
528
+			select="substring-before(concat(@href,'#'), '#')" />
529
+		<xsl:variable name="fragment-id"
530
+			select="substring-after(@href, '#')" />
531
+
532
+
533
+		<xsl:processing-instruction name="DSDL_INCLUDE_START">
534
+			<xsl:value-of select="@href" />
535
+		</xsl:processing-instruction>
536
+
537
+		<xsl:choose>
538
+			<xsl:when test="not( $include-schematron = 'true' )">
539
+				<xslt:copy>
540
+					<xslt:copy-of select="@*" />
541
+					<xslt:apply-templates mode="dsdl:go" />
542
+				</xslt:copy>
543
+			</xsl:when>
544
+			<xsl:otherwise>
545
+
546
+				<xsl:choose>
547
+
548
+					<xsl:when
549
+						test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
550
+						<xsl:message>
551
+							Error: Impossible URL in Schematron include
552
+						</xsl:message>
553
+					</xsl:when>
554
+
555
+					<!-- this case is when there is in embedded schema in the same document elsewhere -->
556
+					<xslt:when
557
+						test="string-length( $document-uri ) = 0">
558
+						<xslt:apply-templates mode="dsdl:go"
559
+							select="//iso:*[@xml:id= $fragment-id ]/* 
560
+              	 |id( $fragment-id)/*
561
+              	 | //iso:*[@id= $fragment-id ]/*" />
562
+					</xslt:when>
563
+
564
+					<!-- case where there is a fragment in another document (should be an iso: element) -->
565
+					<!-- There are three cases for includes with fragment:
566
+						0) No href file or no matching id - error!
567
+						1) REMOVED
568
+						
569
+						2) REMOVED
570
+						
571
+						3) Otherwise, include the pointed-to element
572
+					-->
573
+
574
+					<xsl:when
575
+						test="string-length( $fragment-id ) &gt; 0">
576
+						<xsl:variable name="theDocument_1"
577
+							select="document( $document-uri,/ )" />
578
+						<xsl:variable name="originalParent" select=".." />
579
+
580
+						<!-- case 0 -->
581
+						<xsl:if test="not($theDocument_1)">
582
+							<xsl:message terminate="no">
583
+								<xsl:text>Unable to open referenced included file: </xsl:text>
584
+								<xsl:value-of select="@href" />
585
+							</xsl:message>
586
+						</xsl:if>
587
+						<!-- use for-each to rebase id() to external document -->
588
+						<xsl:for-each select="$theDocument_1">
589
+							<xsl:variable name="theFragment_1"
590
+								select=" $theDocument_1//iso:*[@xml:id= $fragment-id ] |
591
+              	 		id($fragment-id) |
592
+              			$theDocument_1//iso:*[@id= $fragment-id ]" />
593
+
594
+
595
+							<xsl:choose>
596
+								<!-- case 0 -->
597
+								<xsl:when test="not($theFragment_1)">
598
+									<xsl:message terminate="no">
599
+										<xsl:text>Unable to locate id attribute: </xsl:text>
600
+										<xsl:value-of select="@href" />
601
+									</xsl:message>
602
+								</xsl:when>
603
+
604
+
605
+								<!-- case 1 REMOVED -->
606
+
607
+								<!-- case 2 REMOVED -->
608
+
609
+
610
+								<!-- case 3 -->
611
+								<xsl:otherwise>
612
+
613
+									<xsl:apply-templates
614
+										select=" $theFragment_1[1]/*" mode="dsdl:go" />
615
+								</xsl:otherwise>
616
+							</xsl:choose>
617
+						</xsl:for-each>
618
+					</xsl:when>
619
+
620
+					<!-- Case where there is no ID so we include the whole document -->
621
+					<!-- Experimental addition: include fragments of children -->
622
+					<xsl:otherwise>
623
+						<xsl:variable name="theDocument_2"
624
+							select="document( $document-uri,/ )" />
625
+						<xsl:variable name="theFragment_2"
626
+							select="$theDocument_2/iso:*" />
627
+						<xsl:variable name="theContainedFragments"
628
+							select="$theDocument_2/*/iso:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
629
+						<xsl:if test="not($theDocument_2)">
630
+							<xsl:message terminate="no">
631
+								<xsl:text>Unable to open referenced included file: </xsl:text>
632
+								<xsl:value-of select="@href" />
633
+							</xsl:message>
634
+						</xsl:if>
635
+
636
+						<!-- There are three cases for includes:
637
+							0) No text specified- error!
638
+							
639
+							1) REMOVED
640
+							
641
+							2) REMOVED
642
+							
643
+							3) Otherwise, include the pointed-to element
644
+						-->
645
+						<xsl:choose>
646
+							<!-- case 0 -->
647
+							<xsl:when
648
+								test="not($theFragment_2) and not ($theContainedFragments)">
649
+								<xsl:message terminate="no">
650
+									<xsl:text>Unable to locate id attribute: </xsl:text>
651
+									<xsl:value-of select="@href" />
652
+								</xsl:message>
653
+							</xsl:when>
654
+
655
+							<!-- case 1 removed -->
656
+
657
+							<!-- case 2 removed -->
658
+
659
+							<!-- If this were XLST 2, we could use  
660
+								if ($theFragment) then $theFragment else $theContainedFragments
661
+								here (thanks to KN)
662
+							-->
663
+							<!-- case 3 -->
664
+							<xsl:otherwise>
665
+								<xsl:apply-templates
666
+									select="$theFragment_2/* " mode="dsdl:go" />
667
+							</xsl:otherwise>
668
+						</xsl:choose>
669
+					</xsl:otherwise>
670
+				</xsl:choose>
671
+			</xsl:otherwise>
672
+		</xsl:choose>
673
+
674
+		<xsl:processing-instruction name="DSDL_INCLUDE_END">
675
+			<xsl:value-of select="@href" />
676
+		</xsl:processing-instruction>
677
+	</xsl:template>
678
+
679
+
680
+
681
+	<!-- =========================================================== -->
682
+	<!-- Handle Schematron 1.6 inclusions: clone of ISO code above   -->
683
+	<!-- =========================================================== -->
684
+
685
+
686
+	<!-- Extend the URI syntax to allow # references -->
687
+	<!-- Add experimental support for simple containers like  /xxx:xxx/schold:pattern to allow better includes -->
688
+	<xsl:template match="schold:include" mode="dsdl:go">
689
+		<xsl:variable name="document-uri"
690
+			select="substring-before(concat(@href,'#'), '#')" />
691
+		<xsl:variable name="fragment-id"
692
+			select="substring-after(@href, '#')" />
693
+
694
+		<xsl:processing-instruction name="DSDL_INCLUDE_START">
695
+			<xsl:value-of select="@href" />
696
+		</xsl:processing-instruction>
697
+
698
+		<xsl:choose>
699
+			<xsl:when test="not( $include-schematron = 'true' )">
700
+				<xslt:copy>
701
+					<xslt:copy-of select="@*" />
702
+					<xslt:apply-templates mode="dsdl:go" />
703
+				</xslt:copy>
704
+			</xsl:when>
705
+			<xsl:otherwise>
706
+				<xsl:choose>
707
+
708
+					<xsl:when
709
+						test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
710
+						<xsl:message>
711
+							Error: Impossible URL in Schematron include
712
+						</xsl:message>
713
+					</xsl:when>
714
+
715
+					<!-- this case is when there is in embedded schema in the same document elsewhere -->
716
+					<xslt:when
717
+						test="string-length( $document-uri ) = 0">
718
+						<xslt:apply-templates mode="dsdl:go"
719
+							select="//schold:*[@xml:id= $fragment-id ] 
720
+              	 |id( $fragment-id)
721
+              	 | //schold:*[@id= $fragment-id ]" />
722
+					</xslt:when>
723
+
724
+					<!-- case where there is a fragment in another document (should be an iso: element) -->
725
+					<xsl:when
726
+						test="string-length( $fragment-id ) &gt; 0">
727
+						<xsl:variable name="theDocument_1"
728
+							select="document( $document-uri,/ )" />
729
+						<xsl:if test="not($theDocument_1)">
730
+							<xsl:message terminate="no">
731
+								<xsl:text>Unable to open referenced included file: </xsl:text>
732
+								<xsl:value-of select="@href" />
733
+							</xsl:message>
734
+						</xsl:if>
735
+						<!-- use for-each to rebase id() to $theDocument -->
736
+						<xsl:for-each select="$theDocument_1">
737
+							<xsl:variable name="theFragment_1"
738
+								select=" $theDocument_1//schold:*[@xml:id= $fragment-id ] |
739
+              	id($fragment-id) |
740
+              	$theDocument_1//schold:*[@id= $fragment-id ]" />
741
+							<xsl:if
742
+								test=" $theFragment_1/self::schold:schema ">
743
+								<xsl:message>
744
+									Schema error: Use include to include
745
+									fragments, not a whole schema
746
+								</xsl:message>
747
+							</xsl:if>
748
+							<xsl:if test="not($theFragment_1)">
749
+								<xsl:message terminate="no">
750
+									<xsl:text>Unable to locate id attribute: </xsl:text>
751
+									<xsl:value-of select="@href" />
752
+								</xsl:message>
753
+							</xsl:if>
754
+							<xsl:apply-templates
755
+								select=" $theFragment_1[1]" mode="dsdl:go" />
756
+						</xsl:for-each>
757
+					</xsl:when>
758
+
759
+					<!-- Case where there is no ID so we include the whole document -->
760
+					<!-- Experimental addition: include fragments of children -->
761
+					<xsl:otherwise>
762
+						<xsl:variable name="theDocument_2"
763
+							select="document( $document-uri,/ )" />
764
+						<xsl:variable name="theFragment_2"
765
+							select="$theDocument_2/iso:*" />
766
+						<xsl:variable name="theContainedFragments"
767
+							select="$theDocument_2/*/schold:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
768
+						<xsl:if test="not($theDocument_2)">
769
+							<xsl:message terminate="no">
770
+								<xsl:text>Unable to open referenced included file: </xsl:text>
771
+								<xsl:value-of select="@href" />
772
+							</xsl:message>
773
+						</xsl:if>
774
+
775
+						<xsl:if
776
+							test=" $theFragment_2/self::schold:schema or $theContainedFragments/self::schold:schema">
777
+							<xsl:message>
778
+								Schema error: Use include to include
779
+								fragments, not a whole schema
780
+							</xsl:message>
781
+						</xsl:if>
782
+						<xsl:if
783
+							test="not($theFragment_2) and not ($theContainedFragments)">
784
+							<xsl:message terminate="no">
785
+								<xsl:text>Unable to locate id attribute: </xsl:text>
786
+								<xsl:value-of select="@href" />
787
+							</xsl:message>
788
+						</xsl:if>
789
+						<!-- If this were XLST 2, we could use  
790
+							if ($theFragment) then $theFragment else $theContainedFragments
791
+							here (thanks to KN)
792
+						-->
793
+						<xsl:choose>
794
+							<xsl:when test=" $theFragment_2 ">
795
+								<xsl:apply-templates
796
+									select="$theFragment_2 " mode="dsdl:go" />
797
+							</xsl:when>
798
+							<xsl:otherwise>
799
+								<!-- WARNING!  EXPERIMENTAL! Use at your own risk. This may be discontinued! -->
800
+								<xsl:apply-templates
801
+									select="  $theContainedFragments " mode="dsdl:go" />
802
+							</xsl:otherwise>
803
+						</xsl:choose>
804
+					</xsl:otherwise>
805
+				</xsl:choose>
806
+
807
+			</xsl:otherwise>
808
+		</xsl:choose>
809
+
810
+		<xsl:processing-instruction name="DSDL_INCLUDE_END">
811
+			<xsl:value-of select="@href" />
812
+		</xsl:processing-instruction>
813
+	</xsl:template>
814
+	<!-- =========================================================== -->
815
+	<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages   -->
816
+	<!-- Part 5 - DataType Library Language - DTLL                   -->
817
+	<!-- Committee Draft  Experimental support only                  -->
818
+	<!-- The <include> element may well be replaced by XInclude in   -->
819
+	<!-- any final version.                                          -->
820
+	<!-- =========================================================== -->
821
+	<xslt:template match="dtll:include" 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-dtll = '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 DTLL 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
+						<xslt:apply-templates mode="dsdl:go"
852
+							select="//*[@xml:id= $fragment-id ] | id( $fragment-id) 
853
+              	| //*[@id= $fragment-id ]" />
854
+					</xslt:when>
855
+
856
+					<xsl:when
857
+						test="string-length( $fragment-id ) &gt; 0">
858
+						<xsl:variable name="theDocument_1"
859
+							select="document( $document-uri,/ )" />
860
+						<xsl:if test="not($theDocument_1)">
861
+							<xsl:message terminate="no">
862
+								<xsl:text>Unable to open referenced included file: </xsl:text>
863
+								<xsl:value-of select="@href" />
864
+							</xsl:message>
865
+						</xsl:if>
866
+						<!-- use for-each to rebase id() to $theDocument -->
867
+						<xsl:for-each select="$theDocument_1">
868
+							<xsl:variable name="theFragment_1"
869
+								select="$theDocument_1//*[@xml:id= $fragment-id ]
870
+               | id( $fragment-id ) 
871
+               | $theDocument_1//*[@id= $fragment-id ]" />
872
+							<xsl:if test="not($theFragment_1)">
873
+								<xsl:message terminate="no">
874
+									<xsl:text>Unable to locate id attribute: </xsl:text>
875
+									<xsl:value-of select="@href" />
876
+								</xsl:message>
877
+							</xsl:if>
878
+							<xsl:apply-templates
879
+								select=" $theFragment_1[1]" mode="dsdl:go" />
880
+						</xsl:for-each>
881
+					</xsl:when>
882
+
883
+					<xsl:otherwise>
884
+						<xsl:variable name="theDocument_2"
885
+							select="document( $document-uri,/ )" />
886
+						<xsl:variable name="theFragment_2"
887
+							select="$theDocument_2/*" />
888
+
889
+						<xsl:if test="not($theDocument_2)">
890
+							<xsl:message terminate="no">
891
+								<xsl:text>Unable to open referenced included file: </xsl:text>
892
+								<xsl:value-of select="@href" />
893
+							</xsl:message>
894
+						</xsl:if>
895
+
896
+						<xsl:if test="not($theFragment_2)">
897
+							<xsl:message terminate="no">
898
+								<xsl:text>Unable to locate id attribute: </xsl:text>
899
+								<xsl:value-of select="@href" />
900
+							</xsl:message>
901
+						</xsl:if>
902
+						<xsl:apply-templates select="$theFragment_2 "
903
+							mode="dsdl:go" />
904
+					</xsl:otherwise>
905
+				</xsl:choose>
906
+
907
+			</xsl:otherwise>
908
+		</xsl:choose>
909
+		<xsl:processing-instruction name="DSDL_INCLUDE_END">
910
+			<xsl:value-of select="@href" />
911
+		</xsl:processing-instruction>
912
+	</xslt:template>
913
+
914
+	<!-- =========================================================== -->
915
+	<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages   -->
916
+	<!-- Part 7 - Character Repertoire Description Language - CRDL   -->
917
+	<!-- Final Committee Draft 2008-01-11 Experimental support only  -->
918
+	<!-- =========================================================== -->
919
+	<xslt:template match="crdl:ref" mode="dsdl:go">
920
+		<!-- Insert subschema -->
921
+
922
+		<xsl:variable name="document-uri"
923
+			select="substring-before(concat(@href,'#'), '#')" />
924
+		<xsl:variable name="fragment-id"
925
+			select="substring-after(@href, '#')" />
926
+		<xsl:processing-instruction name="DSDL_INCLUDE_START">
927
+			<xsl:value-of select="@href" />
928
+		</xsl:processing-instruction>
929
+		<xsl:choose>
930
+			<xsl:when test="not( $include-crdl = 'true' )">
931
+				<xslt:copy>
932
+					<xslt:copy-of select="@*" />
933
+					<xslt:apply-templates mode="dsdl:go" />
934
+				</xslt:copy>
935
+			</xsl:when>
936
+			<xsl:otherwise>
937
+				<xsl:choose>
938
+
939
+					<xsl:when
940
+						test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
941
+						<xsl:message>
942
+							Error: Impossible URL in CRDL include
943
+						</xsl:message>
944
+					</xsl:when>
945
+
946
+					<!-- this case is when there is in embedded schema in the same document elsewhere -->
947
+					<xslt:when
948
+						test="string-length( $document-uri ) = 0">
949
+
950
+						<xslt:apply-templates mode="dsdl:go"
951
+							select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
952
+              	| //*[@id= $fragment-id ]" />
953
+					</xslt:when>
954
+
955
+					<xsl:when
956
+						test="string-length( $fragment-id ) &gt; 0">
957
+						<xsl:variable name="theDocument_1"
958
+							select="document( $document-uri,/ )" />
959
+						<xsl:if test="not($theDocument_1)">
960
+							<xsl:message terminate="no">
961
+								<xsl:text>Unable to open referenced included file: </xsl:text>
962
+								<xsl:value-of select="@href" />
963
+							</xsl:message>
964
+						</xsl:if>
965
+						<!-- use for-each to rebase id() to $theDocument -->
966
+						<xsl:for-each select="$theDocument_1">
967
+							<xsl:variable name="theFragment_1"
968
+								select="$theDocument_1//*[@xml:id= $fragment-id ]
969
+               | id( $fragment-id )
970
+               | $theDocument_1//*[@id= $fragment-id ]" />
971
+
972
+							<xsl:if test="not($theFragment_1)">
973
+								<xsl:message terminate="no">
974
+									<xsl:text>Unable to locate id attribute: </xsl:text>
975
+									<xsl:value-of select="@href" />
976
+								</xsl:message>
977
+							</xsl:if>
978
+							<xsl:apply-templates select=" $theFragment_1 "
979
+								mode="dsdl:go" />
980
+						</xsl:for-each>
981
+					</xsl:when>
982
+
983
+					<xsl:otherwise>
984
+						<xsl:variable name="theDocument_2"
985
+							select="document( $document-uri,/ )" />
986
+						<xsl:variable name="theFragment_2"
987
+							select="$theDocument_2/*" />
988
+
989
+						<xsl:if test="not($theDocument_2)">
990
+							<xsl:message terminate="no">
991
+								<xsl:text>Unable to open referenced included file: </xsl:text>
992
+								<xsl:value-of select="@href" />
993
+							</xsl:message>
994
+						</xsl:if>
995
+						<xsl:if test="not($theFragment_2)">
996
+							<xsl:message terminate="no">
997
+								<xsl:text>Unable to locate id attribute: </xsl:text>
998
+								<xsl:value-of select="@href" />
999
+							</xsl:message>
1000
+						</xsl:if>
1001
+
1002
+						<xsl:apply-templates select="$theFragment_2"
1003
+							mode="dsdl:go" />
1004
+					</xsl:otherwise>
1005
+				</xsl:choose>
1006
+
1007
+			</xsl:otherwise>
1008
+		</xsl:choose>
1009
+		<xsl:processing-instruction name="DSDL_INCLUDE_END">
1010
+			<xsl:value-of select="@href" />
1011
+		</xsl:processing-instruction>
1012
+	</xslt:template>
1013
+
1014
+
1015
+	<!-- =========================================================== -->