schematron-nokogiri 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.semver +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/bin/stron-nokogiri +34 -0
- data/iso-schematron-xslt1/iso_abstract_expand.xsl +296 -0
- data/iso-schematron-xslt1/iso_dsdl_include.xsl +1160 -0
- data/iso-schematron-xslt1/iso_schematron_message.xsl +55 -0
- data/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl +1821 -0
- data/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl +588 -0
- data/iso-schematron-xslt1/readme.txt +83 -0
- data/lib/schematron-nokogiri.rb +85 -0
- data/schematron-nokogiri.gemspec +17 -0
- data/spec/command_spec.rb +22 -0
- data/spec/feature_requests_spec.rb +5 -0
- data/spec/instances/daitss-sip/Example1.xml +37 -0
- data/spec/instances/daitss-sip/Example2.xml +68 -0
- data/spec/instances/premis-in-mets/bad.xml +102 -0
- data/spec/instances/premis-in-mets/good.xml +103 -0
- data/spec/schema/fda_sip.sch +72 -0
- data/spec/schema/pim.sch +35 -0
- data/spec/schema_spec.rb +54 -0
- data/spec/spec_helper.rb +1 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 93b3c578c594fa237dced9bf66ea90ab12b788ae
|
4
|
+
data.tar.gz: 2e27b501f3a38c9d640b4c02c40a434cd8f1d716
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b031babcb6dde5cac58f73c432209031c2248969ac88b22e528a80218bccb49d5b8bc19fc0d1f24a08e3ac4324c1c8330239541054142f182db796a532840ffe
|
7
|
+
data.tar.gz: e8e645f2310de19713adcd0f2ce2809df98546c88a4a79a171be327af8745bb86b26c2feb4a2a065040b6b8227a6a9785a0c753dbc3a9e798795ed029a496ddb
|
data/.semver
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Francesco Lazzarino
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
ISO Schematron
|
2
|
+
==============
|
3
|
+
|
4
|
+
Ruby gem for validating XML against schematron schema
|
5
|
+
|
6
|
+
Uses [ISO Schematron](http://www.schematron.com) version: 2010-01-25
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
% gem install schematron-nokogiri
|
12
|
+
|
13
|
+
Command line example
|
14
|
+
-------------------
|
15
|
+
|
16
|
+
% stron-nokogiri my_schema.stron my_xml_document.xml
|
17
|
+
|
18
|
+
Ruby API example
|
19
|
+
----------------
|
20
|
+
|
21
|
+
# overhead
|
22
|
+
require "nokogiri"
|
23
|
+
require "schematron"
|
24
|
+
|
25
|
+
# load the schematron xml
|
26
|
+
stron_doc = Nokogiri::XML File.open "/path/to/my_schema.stron"
|
27
|
+
|
28
|
+
# make a schematron object
|
29
|
+
stron = SchematronNokogiri::Schema.new stron_doc
|
30
|
+
|
31
|
+
# load the xml document you wish to validate
|
32
|
+
xml_doc = Nokogiri::XML File.open "/path/to/my_xml_document.xml"
|
33
|
+
|
34
|
+
# validate it
|
35
|
+
results = stron.validate xml_doc
|
36
|
+
|
37
|
+
# print out the results
|
38
|
+
stron.validate(instance_doc).each do |error|
|
39
|
+
puts "#{error[:line]}: #{error[:message]}"
|
40
|
+
end
|
41
|
+
|
42
|
+
---
|
43
|
+
This gem replaces the libxml and libxslt-ruby with Nokogiri in the gem https://github.com/flazz/schematron
|
44
|
+
The replacement was done by Alexandru Szasz at https://github.com/alexxed/schematron
|
45
|
+
Copyright © 2009-2010 [Francesco Lazzarino](mailto:flazzarino@gmail.com).
|
46
|
+
|
47
|
+
Sponsored by [Florida Center for Library Automation](http://www.fcla.edu).
|
48
|
+
|
49
|
+
See LICENSE.txt for terms.
|
data/bin/stron-nokogiri
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'schematron-nokogiri'
|
5
|
+
|
6
|
+
begin
|
7
|
+
|
8
|
+
# get args
|
9
|
+
schema_file = ARGV.shift or raise "schematron file required"
|
10
|
+
instance_file = ARGV.shift or raise "instance doc file required"
|
11
|
+
|
12
|
+
# parse the xml
|
13
|
+
schema_doc = Nokogiri::XML File.open(schema_file)
|
14
|
+
instance_doc = Nokogiri::XML File.open(instance_file)
|
15
|
+
stron = SchematronNokogiri::Schema.new schema_doc
|
16
|
+
|
17
|
+
# validate
|
18
|
+
errors = stron.validate(instance_doc)
|
19
|
+
if errors.empty?
|
20
|
+
exit 0
|
21
|
+
else
|
22
|
+
|
23
|
+
errors.each do |error|
|
24
|
+
puts '%s "%s" on line %d: %s' % error.values_at(:type, :name, :line, :message)
|
25
|
+
end
|
26
|
+
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
rescue => e
|
31
|
+
puts "Usage: stron [schematron] [instance doc]"
|
32
|
+
puts e.message
|
33
|
+
exit 2
|
34
|
+
end
|
@@ -0,0 +1,296 @@
|
|
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
|
+
* experimentally, allows parameter recognition and substitution inside
|
11
|
+
text as well as @context, @test, & @select.
|
12
|
+
|
13
|
+
|
14
|
+
This should be used after iso-dsdl-include.xsl and before the skeleton or
|
15
|
+
meta-stylesheet (e.g. iso-svrl.xsl) . It only requires XSLT 1.
|
16
|
+
|
17
|
+
Each kind of inclusion can be turned off (or on) on the command line.
|
18
|
+
|
19
|
+
-->
|
20
|
+
<!--
|
21
|
+
VERSION INFORMATION
|
22
|
+
2008-09-18 RJ
|
23
|
+
* move out param test from iso:schema template to work with XSLT 1. (Noah Fontes)
|
24
|
+
|
25
|
+
2008-07-29 RJ
|
26
|
+
* Create. Pull out as distinct XSL in its own namespace from old iso_pre_pro.xsl
|
27
|
+
* Put everything in private namespace
|
28
|
+
* Rewrite replace_substring named template so that copyright is clear
|
29
|
+
|
30
|
+
2008-07-24 RJ
|
31
|
+
* correct abstract patterns so for correct names: param/@name and
|
32
|
+
param/@value
|
33
|
+
|
34
|
+
2007-01-12 RJ
|
35
|
+
* Use ISO namespace
|
36
|
+
* Use pattern/@id not pattern/@name
|
37
|
+
* Add Oliver Becker's suggests from old Schematron-love-in list for <copy>
|
38
|
+
* Add XT -ism?
|
39
|
+
2003 RJ
|
40
|
+
* Original written for old namespace
|
41
|
+
* http://www.topologi.com/resources/iso-pre-pro.xsl
|
42
|
+
-->
|
43
|
+
<!--
|
44
|
+
LEGAL INFORMATION
|
45
|
+
|
46
|
+
Copyright (c) 2000-2008 Rick Jelliffe and Academia Sinica Computing Center, Taiwan
|
47
|
+
|
48
|
+
This software is provided 'as-is', without any express or implied warranty.
|
49
|
+
In no event will the authors be held liable for any damages arising from
|
50
|
+
the use of this software.
|
51
|
+
|
52
|
+
Permission is granted to anyone to use this software for any purpose,
|
53
|
+
including commercial applications, and to alter it and redistribute it freely,
|
54
|
+
subject to the following restrictions:
|
55
|
+
|
56
|
+
1. The origin of this software must not be misrepresented; you must not claim
|
57
|
+
that you wrote the original software. If you use this software in a product,
|
58
|
+
an acknowledgment in the product documentation would be appreciated but is
|
59
|
+
not required.
|
60
|
+
|
61
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
62
|
+
misrepresented as being the original software.
|
63
|
+
|
64
|
+
3. This notice may not be removed or altered from any source distribution.
|
65
|
+
-->
|
66
|
+
<xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
|
67
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
68
|
+
xmlns:iso="http://purl.oclc.org/dsdl/schematron"
|
69
|
+
xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl"
|
70
|
+
|
71
|
+
|
72
|
+
xmlns:iae="http://www.schematron.com/namespace/iae"
|
73
|
+
|
74
|
+
>
|
75
|
+
|
76
|
+
<xslt:param name="schema-id"></xslt:param>
|
77
|
+
|
78
|
+
|
79
|
+
<!-- Driver for the mode -->
|
80
|
+
<xsl:template match="/">
|
81
|
+
<xsl:apply-templates select="." mode="iae:go" />
|
82
|
+
</xsl:template>
|
83
|
+
|
84
|
+
|
85
|
+
<!-- ================================================================================== -->
|
86
|
+
<!-- Normal processing rules -->
|
87
|
+
<!-- ================================================================================== -->
|
88
|
+
<!-- Output only the selected schema -->
|
89
|
+
<xslt:template match="iso:schema" >
|
90
|
+
<xsl:if test="string-length($schema-id) =0 or @id= $schema-id ">
|
91
|
+
<xslt:copy>
|
92
|
+
<xslt:copy-of select="@*" />
|
93
|
+
<xslt:apply-templates mode="iae:go" />
|
94
|
+
</xslt:copy>
|
95
|
+
</xsl:if>
|
96
|
+
</xslt:template>
|
97
|
+
|
98
|
+
|
99
|
+
<!-- Strip out any foreign elements above the Schematron schema .
|
100
|
+
-->
|
101
|
+
<xslt:template match="*[not(ancestor-or-self::iso:*)]" mode="iae:go" >
|
102
|
+
<xslt:apply-templates mode="iae:go" />
|
103
|
+
</xslt:template>
|
104
|
+
|
105
|
+
|
106
|
+
<!-- ================================================================================== -->
|
107
|
+
<!-- Handle Schematron abstract pattern preprocessing -->
|
108
|
+
<!-- abstract-to-real calls
|
109
|
+
do-pattern calls
|
110
|
+
macro-expand calls
|
111
|
+
multi-macro-expand
|
112
|
+
replace-substring -->
|
113
|
+
<!-- ================================================================================== -->
|
114
|
+
|
115
|
+
<!--
|
116
|
+
Abstract patterns allow you to say, for example
|
117
|
+
|
118
|
+
<pattern name="htmlTable" is-a="table">
|
119
|
+
<param name="row" value="html:tr"/>
|
120
|
+
<param name="cell" value="html:td" />
|
121
|
+
<param name="table" value="html:table" />
|
122
|
+
</pattern>
|
123
|
+
|
124
|
+
For a good introduction, see Uche Ogbujii's article for IBM DeveloperWorks
|
125
|
+
"Discover the flexibility of Schematron abstract patterns"
|
126
|
+
http://www-128.ibm.com/developerworks/xml/library/x-stron.html
|
127
|
+
However, note that ISO Schematron uses @name and @value attributes on
|
128
|
+
the iso:param element, and @id not @name on the pattern element.
|
129
|
+
|
130
|
+
-->
|
131
|
+
|
132
|
+
<!-- Suppress declarations of abstract patterns -->
|
133
|
+
<xslt:template match="iso:pattern[@abstract='true']" mode="iae:go" >
|
134
|
+
<xslt:comment>Suppressed abstract pattern <xslt:value-of select="@id"/> was here</xslt:comment>
|
135
|
+
</xslt:template>
|
136
|
+
|
137
|
+
|
138
|
+
<!-- Suppress uses of abstract patterns -->
|
139
|
+
<xslt:template match="iso:pattern[@is-a]" mode="iae:go" >
|
140
|
+
|
141
|
+
<xslt:comment>Start pattern based on abstract <xslt:value-of select="@is-a"/></xslt:comment>
|
142
|
+
|
143
|
+
<xslt:call-template name="iae:abstract-to-real" >
|
144
|
+
<xslt:with-param name="caller" select="@id" />
|
145
|
+
<xslt:with-param name="is-a" select="@is-a" />
|
146
|
+
</xslt:call-template>
|
147
|
+
|
148
|
+
</xslt:template>
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
<!-- output everything else unchanged -->
|
153
|
+
<xslt:template match="*" priority="-1" mode="iae:go" >
|
154
|
+
<xslt:copy>
|
155
|
+
<xslt:copy-of select="@*" />
|
156
|
+
<xslt:apply-templates mode="iae:go"/>
|
157
|
+
</xslt:copy>
|
158
|
+
</xslt:template>
|
159
|
+
|
160
|
+
<!-- Templates for macro expansion of abstract patterns -->
|
161
|
+
<!-- Sets up the initial conditions for the recursive call -->
|
162
|
+
<xslt:template name="iae:macro-expand">
|
163
|
+
<xslt:param name="caller"/>
|
164
|
+
<xslt:param name="text" />
|
165
|
+
<xslt:call-template name="iae:multi-macro-expand">
|
166
|
+
<xslt:with-param name="caller" select="$caller"/>
|
167
|
+
<xslt:with-param name="text" select="$text"/>
|
168
|
+
<xslt:with-param name="paramNumber" select="1"/>
|
169
|
+
</xslt:call-template>
|
170
|
+
|
171
|
+
</xslt:template>
|
172
|
+
|
173
|
+
<!-- Template to replace the current parameter and then
|
174
|
+
recurse to replace subsequent parameters. -->
|
175
|
+
|
176
|
+
<xslt:template name="iae:multi-macro-expand">
|
177
|
+
<xslt:param name="caller"/>
|
178
|
+
<xslt:param name="text" />
|
179
|
+
<xslt:param name="paramNumber" />
|
180
|
+
|
181
|
+
|
182
|
+
<xslt:choose>
|
183
|
+
<xslt:when test="//iso:pattern[@id=$caller]/iso:param[ $paramNumber]">
|
184
|
+
|
185
|
+
<xslt:call-template name="iae:multi-macro-expand">
|
186
|
+
<xslt:with-param name="caller" select="$caller"/>
|
187
|
+
<xslt:with-param name="paramNumber" select="$paramNumber + 1"/>
|
188
|
+
<xslt:with-param name="text" >
|
189
|
+
<xslt:call-template name="iae:replace-substring">
|
190
|
+
<xslt:with-param name="original" select="$text"/>
|
191
|
+
<xslt:with-param name="substring"
|
192
|
+
select="concat('$', //iso:pattern[@id=$caller]/iso:param[ $paramNumber ]/@name)"/>
|
193
|
+
<xslt:with-param name="replacement"
|
194
|
+
select="//iso:pattern[@id=$caller]/iso:param[ $paramNumber ]/@value"/>
|
195
|
+
</xslt:call-template>
|
196
|
+
</xslt:with-param>
|
197
|
+
</xslt:call-template>
|
198
|
+
</xslt:when>
|
199
|
+
<xslt:otherwise><xslt:value-of select="$text" /></xslt:otherwise>
|
200
|
+
|
201
|
+
</xslt:choose>
|
202
|
+
</xslt:template>
|
203
|
+
|
204
|
+
|
205
|
+
<!-- generate the real pattern from an abstract pattern + parameters-->
|
206
|
+
<xslt:template name="iae:abstract-to-real" >
|
207
|
+
<xslt:param name="caller"/>
|
208
|
+
<xslt:param name="is-a" />
|
209
|
+
<xslt:for-each select="//iso:pattern[@id= $is-a]">
|
210
|
+
<xslt:copy>
|
211
|
+
|
212
|
+
<xslt:choose>
|
213
|
+
<xslt:when test=" string-length( $caller ) = 0">
|
214
|
+
<xslt:attribute name="id"><xslt:value-of select="concat( generate-id(.) , $is-a)" /></xslt:attribute>
|
215
|
+
</xslt:when>
|
216
|
+
<xslt:otherwise>
|
217
|
+
<xslt:attribute name="id"><xslt:value-of select="$caller" /></xslt:attribute>
|
218
|
+
</xslt:otherwise>
|
219
|
+
</xslt:choose>
|
220
|
+
|
221
|
+
<xslt:apply-templates select="*|text()" mode="iae:do-pattern" >
|
222
|
+
<xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
|
223
|
+
</xslt:apply-templates>
|
224
|
+
|
225
|
+
</xslt:copy>
|
226
|
+
</xslt:for-each>
|
227
|
+
</xslt:template>
|
228
|
+
|
229
|
+
|
230
|
+
<!-- Generate a non-abstract pattern -->
|
231
|
+
<xslt:template mode="iae:do-pattern" match="*">
|
232
|
+
<xslt:param name="caller"/>
|
233
|
+
<xslt:copy>
|
234
|
+
<xslt:for-each select="@*[name()='test' or name()='context' or name()='select']">
|
235
|
+
<xslt:attribute name="{name()}">
|
236
|
+
<xslt:call-template name="iae:macro-expand">
|
237
|
+
<xslt:with-param name="text"><xslt:value-of select="."/></xslt:with-param>
|
238
|
+
<xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
|
239
|
+
</xslt:call-template>
|
240
|
+
</xslt:attribute>
|
241
|
+
</xslt:for-each>
|
242
|
+
<xslt:copy-of select="@*[name()!='test'][name()!='context'][name()!='select']" />
|
243
|
+
<xsl:for-each select="node()">
|
244
|
+
<xsl:choose>
|
245
|
+
<!-- Experiment: replace macros in text as well, to allow parameterized assertions
|
246
|
+
and so on, without having to have spurious <iso:value-of> calls and multiple
|
247
|
+
delimiting -->
|
248
|
+
<xsl:when test="self::text()">
|
249
|
+
<xslt:call-template name="iae:macro-expand">
|
250
|
+
<xslt:with-param name="text"><xslt:value-of select="."/></xslt:with-param>
|
251
|
+
<xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
|
252
|
+
</xslt:call-template>
|
253
|
+
</xsl:when>
|
254
|
+
<xsl:otherwise>
|
255
|
+
<xslt:apply-templates select="." mode="iae:do-pattern">
|
256
|
+
<xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
|
257
|
+
</xslt:apply-templates>
|
258
|
+
</xsl:otherwise>
|
259
|
+
</xsl:choose>
|
260
|
+
</xsl:for-each>
|
261
|
+
</xslt:copy>
|
262
|
+
</xslt:template>
|
263
|
+
|
264
|
+
<!-- UTILITIES -->
|
265
|
+
<!-- Simple version of replace-substring function -->
|
266
|
+
<xslt:template name="iae:replace-substring">
|
267
|
+
<xslt:param name="original" />
|
268
|
+
<xslt:param name="substring" />
|
269
|
+
<xslt:param name="replacement" select="''"/>
|
270
|
+
|
271
|
+
<xsl:choose>
|
272
|
+
<xsl:when test="not($original)" />
|
273
|
+
<xsl:when test="not(string($substring))">
|
274
|
+
<xsl:value-of select="$original" />
|
275
|
+
</xsl:when>
|
276
|
+
<xsl:when test="contains($original, $substring)">
|
277
|
+
<xsl:variable name="before" select="substring-before($original, $substring)" />
|
278
|
+
<xsl:variable name="after" select="substring-after($original, $substring)" />
|
279
|
+
|
280
|
+
<xsl:value-of select="$before" />
|
281
|
+
<xsl:value-of select="$replacement" />
|
282
|
+
<!-- recursion -->
|
283
|
+
<xsl:call-template name="iae:replace-substring">
|
284
|
+
<xsl:with-param name="original" select="$after" />
|
285
|
+
<xsl:with-param name="substring" select="$substring" />
|
286
|
+
<xsl:with-param name="replacement" select="$replacement" />
|
287
|
+
</xsl:call-template>
|
288
|
+
</xsl:when>
|
289
|
+
<xsl:otherwise>
|
290
|
+
<!-- no substitution -->
|
291
|
+
<xsl:value-of select="$original" />
|
292
|
+
</xsl:otherwise>
|
293
|
+
</xsl:choose>
|
294
|
+
</xslt:template>
|
295
|
+
|
296
|
+
</xslt:stylesheet>
|
@@ -0,0 +1,1160 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?><?xar XSLT?>
|
2
|
+
|
3
|
+
<!--
|
4
|
+
OVERVIEW : iso_dsdl_include.xsl
|
5
|
+
|
6
|
+
This is an inclusion preprocessor for the non-smart text inclusions
|
7
|
+
of ISO DSDL. It handles
|
8
|
+
<relax:extRef> for ISO RELAX NG
|
9
|
+
<sch:include> for ISO Schematron and Schematron 1.n
|
10
|
+
<sch:extends> for 2009 draft ISO Schematron
|
11
|
+
<xi:xinclude> simple W3C XIncludes for ISO NVRL and DSRL
|
12
|
+
<crdl:ref> for draft ISO CRDL
|
13
|
+
<dtll:include> for draft ISO DTLL
|
14
|
+
<* @xlink:href> for simple W3C XLink 1.1 embedded links
|
15
|
+
|
16
|
+
|
17
|
+
This should be the first in any chain of processing. It only requires
|
18
|
+
XSLT 1. Each kind of inclusion can be turned off (or on) on the command line.
|
19
|
+
|
20
|
+
Ids in fragment identifiers or xpointers will be sought in the following
|
21
|
+
order:
|
22
|
+
* @xml:id
|
23
|
+
* id() for typed schemas (e.g. from DTD) [NOTE: XInclude does not support this]
|
24
|
+
* untyped @id
|
25
|
+
|
26
|
+
The proposed behaviour for the update to ISO Schematron has been implemented. If an
|
27
|
+
include points to an element with the same name as the parent, then that element's
|
28
|
+
contents will be included. This supports the merge style of inclusion.
|
29
|
+
|
30
|
+
When an inclusion is made, it is preceded by a PI with target DSDL_INCLUDE_START
|
31
|
+
and the href and closed by a PI with target DSDL_INCLUDE_START and the href. This is
|
32
|
+
to allow better location of problems, though only to the file level.
|
33
|
+
|
34
|
+
Limitations:
|
35
|
+
* No rebasing: relative paths will be interpreted based on the initial document's
|
36
|
+
path, not the including document. (Severe limitation!)
|
37
|
+
* No checking for circular references
|
38
|
+
* Not full xpointers: only ID matching
|
39
|
+
* <relax:include> not implemented
|
40
|
+
* XInclude handling of xml:base and xml:lang not implemented
|
41
|
+
-->
|
42
|
+
<!--
|
43
|
+
VERSION INFORMATION
|
44
|
+
2009-02-25
|
45
|
+
* Update DSDL namespace to use schematron.com
|
46
|
+
* Tested with SAXON9, Xalan 2.7.1, IE7,
|
47
|
+
* IE does not like multiple variables in same template with same name: rename.
|
48
|
+
2008-09-18
|
49
|
+
* Remove new behaviour for include, because it conflicts with existing usage [KH]
|
50
|
+
* Add extends[@href] element with that merge functionality
|
51
|
+
* Generate PIs to notate source of inclusions for potential better diagnostics
|
52
|
+
|
53
|
+
2008-09-16
|
54
|
+
* Fix for XSLT1
|
55
|
+
|
56
|
+
2008-08-28
|
57
|
+
* New behaviour for schematron includes: if the pointed to element is the same as the current,
|
58
|
+
include the children.
|
59
|
+
|
60
|
+
2008-08-20
|
61
|
+
* Fix bug: in XSLT1 cannot do $document/id('x') but need to use for-each
|
62
|
+
|
63
|
+
2008-08-04
|
64
|
+
* Add support for inclusions in old namespace
|
65
|
+
|
66
|
+
2008-08-03
|
67
|
+
* Fix wrong param name include-relaxng & include-crdl (KH, PH)
|
68
|
+
* Allow inclusion of XSLT and XHTML (KH)
|
69
|
+
* Fix inclusion of fragments (KH)
|
70
|
+
|
71
|
+
2008-07-25
|
72
|
+
* Add selectable input parameter
|
73
|
+
|
74
|
+
2008-07-24
|
75
|
+
* RJ New
|
76
|
+
-->
|
77
|
+
<!--
|
78
|
+
LEGAL INFORMATION
|
79
|
+
|
80
|
+
Copyright (c) 2008 Rick Jelliffe
|
81
|
+
|
82
|
+
This software is provided 'as-is', without any express or implied warranty.
|
83
|
+
In no event will the authors be held liable for any damages arising from
|
84
|
+
the use of this software.
|
85
|
+
|
86
|
+
Permission is granted to anyone to use this software for any purpose,
|
87
|
+
including commercial applications, and to alter it and redistribute it freely,
|
88
|
+
subject to the following restrictions:
|
89
|
+
|
90
|
+
1. The origin of this software must not be misrepresented; you must not claim
|
91
|
+
that you wrote the original software. If you use this software in a product,
|
92
|
+
an acknowledgment in the product documentation would be appreciated but is
|
93
|
+
not required.
|
94
|
+
|
95
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
96
|
+
misrepresented as being the original software.
|
97
|
+
|
98
|
+
3. This notice may not be removed or altered from any source distribution.
|
99
|
+
-->
|
100
|
+
<xslt:stylesheet version="1.0"
|
101
|
+
xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
|
102
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
103
|
+
xmlns:iso="http://purl.oclc.org/dsdl/schematron"
|
104
|
+
xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl"
|
105
|
+
xmlns:xhtml="http://www.w3.org/1999/xhtml"
|
106
|
+
xmlns:schold="http://www.ascc.net/xml/schematron"
|
107
|
+
xmlns:crdl="http://purl.oclc.org/dsdl/crepdl/ns/structure/1.0"
|
108
|
+
xmlns:xi="http://www.w3.org/2001/XInclude"
|
109
|
+
xmlns:dtll="http://www.jenitennison.com/datatypes"
|
110
|
+
xmlns:dsdl="http://www.schematron.com/namespace/dsdl"
|
111
|
+
xmlns:relax="http://relaxng.org/ns/structure/1.0"
|
112
|
+
xmlns:xlink="http://www.w3.org/1999/xlink">
|
113
|
+
<!-- Note: The URL for the dsdl namespace is not official -->
|
114
|
+
|
115
|
+
|
116
|
+
<xsl:param name="include-schematron">true</xsl:param>
|
117
|
+
<xsl:param name="include-crdl">true</xsl:param>
|
118
|
+
<xsl:param name="include-xinclude">true</xsl:param>
|
119
|
+
<xsl:param name="include-dtll">true</xsl:param>
|
120
|
+
<xsl:param name="include-relaxng">true</xsl:param>
|
121
|
+
<xsl:param name="include-xlink">true</xsl:param>
|
122
|
+
|
123
|
+
<xsl:template match="/">
|
124
|
+
<xsl:apply-templates select="." mode="dsdl:go" />
|
125
|
+
</xsl:template>
|
126
|
+
|
127
|
+
<!-- output everything else unchanged -->
|
128
|
+
<xslt:template match="node()" priority="-1" mode="dsdl:go">
|
129
|
+
<xslt:copy>
|
130
|
+
<xslt:copy-of select="@*" />
|
131
|
+
<xslt:apply-templates mode="dsdl:go" />
|
132
|
+
</xslt:copy>
|
133
|
+
</xslt:template>
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
<!-- =========================================================== -->
|
138
|
+
<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
|
139
|
+
<!-- Part 2 - Regular grammar-based validation - RELAX NG -->
|
140
|
+
<!-- This only implements relax:extRef not relax:include which -->
|
141
|
+
<!-- is complex. -->
|
142
|
+
<!-- =========================================================== -->
|
143
|
+
<xslt:template match="relax:extRef" mode="dsdl:go">
|
144
|
+
|
145
|
+
|
146
|
+
<!-- Insert subschema -->
|
147
|
+
|
148
|
+
<xsl:variable name="document-uri"
|
149
|
+
select="substring-before(concat(@href,'#'), '#')" />
|
150
|
+
<xsl:variable name="fragment-id"
|
151
|
+
select="substring-after(@href, '#')" />
|
152
|
+
|
153
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
154
|
+
<xsl:value-of select="@href" />
|
155
|
+
</xsl:processing-instruction>
|
156
|
+
<xsl:choose>
|
157
|
+
<xsl:when test="not( $include-relaxng = 'true' )">
|
158
|
+
<xslt:copy>
|
159
|
+
<xslt:copy-of select="@*" />
|
160
|
+
<xslt:apply-templates mode="dsdl:go" />
|
161
|
+
</xslt:copy>
|
162
|
+
</xsl:when>
|
163
|
+
<xsl:otherwise>
|
164
|
+
|
165
|
+
<xsl:choose>
|
166
|
+
|
167
|
+
<xsl:when
|
168
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
169
|
+
<xsl:message>
|
170
|
+
Error: Impossible URL in RELAX NG extRef
|
171
|
+
include
|
172
|
+
</xsl:message>
|
173
|
+
</xsl:when>
|
174
|
+
|
175
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
176
|
+
<xslt:when
|
177
|
+
test="string-length( $document-uri ) = 0">
|
178
|
+
<xslt:apply-templates mode="dsdl:go"
|
179
|
+
select="//*[@xml:id= $fragment-id ] | id( $fragment-id) | //*[@id= $fragment-id ]" />
|
180
|
+
</xslt:when>
|
181
|
+
|
182
|
+
<xsl:when
|
183
|
+
test="string-length( $fragment-id ) > 0">
|
184
|
+
<xsl:variable name="theDocument_1"
|
185
|
+
select="document( $document-uri,/ )" />
|
186
|
+
|
187
|
+
<xsl:if test="not($theDocument_1)">
|
188
|
+
<xsl:message terminate="no">
|
189
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
190
|
+
<xsl:value-of select="@href" />
|
191
|
+
</xsl:message>
|
192
|
+
</xsl:if>
|
193
|
+
<!-- use a for-each so that the id() function works correctly on the external document -->
|
194
|
+
<xsl:for-each select="$theDocument_1">
|
195
|
+
<xsl:variable name="theFragment_1"
|
196
|
+
select="$theDocument_1//*[@xml:id= $fragment-id ]
|
197
|
+
| id( $fragment-id)
|
198
|
+
| $theDocument_1//*[@id= $fragment-id ]" />
|
199
|
+
<xsl:if test="not($theFragment_1)">
|
200
|
+
<xsl:message terminate="no">
|
201
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
202
|
+
<xsl:value-of select="@href" />
|
203
|
+
</xsl:message>
|
204
|
+
</xsl:if>
|
205
|
+
<xsl:apply-templates
|
206
|
+
select=" $theFragment_1[1]" mode="dsdl:go" />
|
207
|
+
</xsl:for-each>
|
208
|
+
</xsl:when>
|
209
|
+
|
210
|
+
<xsl:otherwise>
|
211
|
+
<xsl:variable name="theDocument_2"
|
212
|
+
select="document( $document-uri,/ )" />
|
213
|
+
<xsl:variable name="theFragment_2"
|
214
|
+
select="$theDocument_2/*" />
|
215
|
+
<xsl:if test="not($theDocument_2)">
|
216
|
+
<xsl:message terminate="no">
|
217
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
218
|
+
<xsl:value-of select="@href" />
|
219
|
+
</xsl:message>
|
220
|
+
</xsl:if>
|
221
|
+
|
222
|
+
<xsl:if test="not($theFragment_2)">
|
223
|
+
<xsl:message terminate="no">
|
224
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
225
|
+
<xsl:value-of select="@href" />
|
226
|
+
</xsl:message>
|
227
|
+
</xsl:if>
|
228
|
+
<xsl:apply-templates select="$theFragment_2 "
|
229
|
+
mode="dsdl:go" />
|
230
|
+
</xsl:otherwise>
|
231
|
+
</xsl:choose>
|
232
|
+
|
233
|
+
</xsl:otherwise>
|
234
|
+
</xsl:choose>
|
235
|
+
|
236
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
237
|
+
<xsl:value-of select="@href" />
|
238
|
+
</xsl:processing-instruction>
|
239
|
+
</xslt:template>
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
<!-- =========================================================== -->
|
244
|
+
<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
|
245
|
+
<!-- Part 3 - Rule-based validation - Schematron -->
|
246
|
+
<!-- =========================================================== -->
|
247
|
+
|
248
|
+
|
249
|
+
<!-- Extend the URI syntax to allow # references -->
|
250
|
+
<!-- Add experimental support for simple containers like /xxx:xxx/iso:pattern to allow better includes -->
|
251
|
+
<xsl:template match="iso:include" mode="dsdl:go">
|
252
|
+
|
253
|
+
<xsl:variable name="document-uri"
|
254
|
+
select="substring-before(concat(@href,'#'), '#')" />
|
255
|
+
<xsl:variable name="fragment-id"
|
256
|
+
select="substring-after(@href, '#')" />
|
257
|
+
|
258
|
+
|
259
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
260
|
+
<xsl:value-of select="@href" />
|
261
|
+
</xsl:processing-instruction>
|
262
|
+
|
263
|
+
<xsl:choose>
|
264
|
+
<xsl:when test="not( $include-schematron = 'true' )">
|
265
|
+
<xslt:copy>
|
266
|
+
<xslt:copy-of select="@*" />
|
267
|
+
<xslt:apply-templates mode="dsdl:go" />
|
268
|
+
</xslt:copy>
|
269
|
+
</xsl:when>
|
270
|
+
<xsl:otherwise>
|
271
|
+
|
272
|
+
<xsl:choose>
|
273
|
+
|
274
|
+
<xsl:when
|
275
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
276
|
+
<xsl:message>
|
277
|
+
Error: Impossible URL in Schematron include
|
278
|
+
</xsl:message>
|
279
|
+
</xsl:when>
|
280
|
+
|
281
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
282
|
+
<xslt:when
|
283
|
+
test="string-length( $document-uri ) = 0">
|
284
|
+
<xslt:apply-templates mode="dsdl:go"
|
285
|
+
select="//iso:*[@xml:id= $fragment-id ]
|
286
|
+
|id( $fragment-id)
|
287
|
+
| //iso:*[@id= $fragment-id ]" />
|
288
|
+
</xslt:when>
|
289
|
+
|
290
|
+
<!-- case where there is a fragment in another document (should be an iso: element) -->
|
291
|
+
<!-- There are three cases for includes with fragment:
|
292
|
+
0) No href file or no matching id - error!
|
293
|
+
1) REMOVED
|
294
|
+
|
295
|
+
2) The linked-to element is sch:schema however the parent of the include
|
296
|
+
is not a schema. In this case, it is an error. (Actually, it should
|
297
|
+
be an error for other kinds of containment problems, but we won't
|
298
|
+
check for them in this version.)
|
299
|
+
|
300
|
+
3) Otherwise, include the pointed-to element
|
301
|
+
-->
|
302
|
+
|
303
|
+
<xsl:when
|
304
|
+
test="string-length( $fragment-id ) > 0">
|
305
|
+
<xsl:variable name="theDocument_1"
|
306
|
+
select="document( $document-uri,/ )" />
|
307
|
+
<xsl:variable name="originalParent" select=".." />
|
308
|
+
|
309
|
+
<!-- case 0 -->
|
310
|
+
<xsl:if test="not($theDocument_1)">
|
311
|
+
<xsl:message terminate="no">
|
312
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
313
|
+
<xsl:value-of select="@href" />
|
314
|
+
</xsl:message>
|
315
|
+
</xsl:if>
|
316
|
+
<!-- use for-each to rebase id() to external document -->
|
317
|
+
<xsl:for-each select="$theDocument_1">
|
318
|
+
<xsl:variable name="theFragment_1"
|
319
|
+
select=" $theDocument_1//iso:*[@xml:id= $fragment-id ] |
|
320
|
+
id($fragment-id) |
|
321
|
+
$theDocument_1//iso:*[@id= $fragment-id ]" />
|
322
|
+
|
323
|
+
|
324
|
+
<xsl:choose>
|
325
|
+
<!-- case 0 -->
|
326
|
+
<xsl:when test="not($theFragment_1)">
|
327
|
+
<xsl:message terminate="no">
|
328
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
329
|
+
<xsl:value-of select="@href" />
|
330
|
+
</xsl:message>
|
331
|
+
</xsl:when>
|
332
|
+
|
333
|
+
|
334
|
+
<!-- case 1 REMOVED -->
|
335
|
+
|
336
|
+
<!-- case 2 -->
|
337
|
+
<xsl:when
|
338
|
+
test=" $theFragment_1/self::iso:schema ">
|
339
|
+
<xsl:message>
|
340
|
+
Schema error: Use include to
|
341
|
+
include fragments, not a whole
|
342
|
+
schema
|
343
|
+
</xsl:message>
|
344
|
+
</xsl:when>
|
345
|
+
|
346
|
+
<!-- case 3 -->
|
347
|
+
<xsl:otherwise>
|
348
|
+
<xsl:apply-templates
|
349
|
+
select=" $theFragment_1[1]" mode="dsdl:go" />
|
350
|
+
</xsl:otherwise>
|
351
|
+
</xsl:choose>
|
352
|
+
</xsl:for-each>
|
353
|
+
</xsl:when>
|
354
|
+
|
355
|
+
<!-- Case where there is no ID so we include the whole document -->
|
356
|
+
<!-- Experimental addition: include fragments of children -->
|
357
|
+
<xsl:otherwise>
|
358
|
+
<xsl:variable name="theDocument_2"
|
359
|
+
select="document( $document-uri,/ )" />
|
360
|
+
<xsl:variable name="theFragment_2"
|
361
|
+
select="$theDocument_2/iso:*" />
|
362
|
+
<xsl:variable name="theContainedFragments"
|
363
|
+
select="$theDocument_2/*/iso:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
|
364
|
+
<xsl:if test="not($theDocument_2)">
|
365
|
+
<xsl:message terminate="no">
|
366
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
367
|
+
<xsl:value-of select="@href" />
|
368
|
+
</xsl:message>
|
369
|
+
</xsl:if>
|
370
|
+
|
371
|
+
<!-- There are three cases for includes:
|
372
|
+
0) No text specified- error!
|
373
|
+
|
374
|
+
1) REMOVED
|
375
|
+
|
376
|
+
2) The linked-to element is sch:schema however the parent of the include
|
377
|
+
is not a schema. In this case, it is an error. (Actually, it should
|
378
|
+
be an error for other kinds of containment problems, but we won't
|
379
|
+
check for them in this version.)
|
380
|
+
|
381
|
+
3) Otherwise, include the pointed-to element
|
382
|
+
-->
|
383
|
+
<xsl:choose>
|
384
|
+
<!-- case 0 -->
|
385
|
+
<xsl:when
|
386
|
+
test="not($theFragment_2) and not ($theContainedFragments)">
|
387
|
+
<xsl:message terminate="no">
|
388
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
389
|
+
<xsl:value-of select="@href" />
|
390
|
+
</xsl:message>
|
391
|
+
</xsl:when>
|
392
|
+
|
393
|
+
<!-- case 1 removed -->
|
394
|
+
|
395
|
+
<!-- case 2 -->
|
396
|
+
<xsl:when
|
397
|
+
test=" $theFragment_2/self::iso:schema or $theContainedFragments/self::iso:schema">
|
398
|
+
<xsl:message>
|
399
|
+
Schema error: Use include to include
|
400
|
+
fragments, not a whole schema
|
401
|
+
</xsl:message>
|
402
|
+
</xsl:when>
|
403
|
+
|
404
|
+
<!-- If this were XLST 2, we could use
|
405
|
+
if ($theFragment) then $theFragment else $theContainedFragments
|
406
|
+
here (thanks to KN)
|
407
|
+
-->
|
408
|
+
<!-- case 3 -->
|
409
|
+
<xsl:otherwise>
|
410
|
+
<xsl:apply-templates
|
411
|
+
select="$theFragment_2 " mode="dsdl:go" />
|
412
|
+
</xsl:otherwise>
|
413
|
+
</xsl:choose>
|
414
|
+
</xsl:otherwise>
|
415
|
+
</xsl:choose>
|
416
|
+
</xsl:otherwise>
|
417
|
+
</xsl:choose>
|
418
|
+
|
419
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
420
|
+
<xsl:value-of select="@href" />
|
421
|
+
</xsl:processing-instruction>
|
422
|
+
</xsl:template>
|
423
|
+
|
424
|
+
|
425
|
+
<!-- WARNING sch:extends[@href] is experimental and non standard -->
|
426
|
+
<!-- Basically, it adds the children of the selected element, not the element itself. -->
|
427
|
+
<xsl:template match="iso:extends[@href]" mode="dsdl:go">
|
428
|
+
|
429
|
+
<xsl:variable name="document-uri"
|
430
|
+
select="substring-before(concat(@href,'#'), '#')" />
|
431
|
+
<xsl:variable name="fragment-id"
|
432
|
+
select="substring-after(@href, '#')" />
|
433
|
+
|
434
|
+
|
435
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
436
|
+
<xsl:value-of select="@href" />
|
437
|
+
</xsl:processing-instruction>
|
438
|
+
|
439
|
+
<xsl:choose>
|
440
|
+
<xsl:when test="not( $include-schematron = 'true' )">
|
441
|
+
<xslt:copy>
|
442
|
+
<xslt:copy-of select="@*" />
|
443
|
+
<xslt:apply-templates mode="dsdl:go" />
|
444
|
+
</xslt:copy>
|
445
|
+
</xsl:when>
|
446
|
+
<xsl:otherwise>
|
447
|
+
|
448
|
+
<xsl:choose>
|
449
|
+
|
450
|
+
<xsl:when
|
451
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
452
|
+
<xsl:message>
|
453
|
+
Error: Impossible URL in Schematron include
|
454
|
+
</xsl:message>
|
455
|
+
</xsl:when>
|
456
|
+
|
457
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
458
|
+
<xslt:when
|
459
|
+
test="string-length( $document-uri ) = 0">
|
460
|
+
<xslt:apply-templates mode="dsdl:go"
|
461
|
+
select="//iso:*[@xml:id= $fragment-id ]/*
|
462
|
+
|id( $fragment-id)/*
|
463
|
+
| //iso:*[@id= $fragment-id ]/*" />
|
464
|
+
</xslt:when>
|
465
|
+
|
466
|
+
<!-- case where there is a fragment in another document (should be an iso: element) -->
|
467
|
+
<!-- There are three cases for includes with fragment:
|
468
|
+
0) No href file or no matching id - error!
|
469
|
+
1) REMOVED
|
470
|
+
|
471
|
+
2) REMOVED
|
472
|
+
|
473
|
+
3) Otherwise, include the pointed-to element
|
474
|
+
-->
|
475
|
+
|
476
|
+
<xsl:when
|
477
|
+
test="string-length( $fragment-id ) > 0">
|
478
|
+
<xsl:variable name="theDocument_1"
|
479
|
+
select="document( $document-uri,/ )" />
|
480
|
+
<xsl:variable name="originalParent" select=".." />
|
481
|
+
|
482
|
+
<!-- case 0 -->
|
483
|
+
<xsl:if test="not($theDocument_1)">
|
484
|
+
<xsl:message terminate="no">
|
485
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
486
|
+
<xsl:value-of select="@href" />
|
487
|
+
</xsl:message>
|
488
|
+
</xsl:if>
|
489
|
+
<!-- use for-each to rebase id() to external document -->
|
490
|
+
<xsl:for-each select="$theDocument_1">
|
491
|
+
<xsl:variable name="theFragment_1"
|
492
|
+
select=" $theDocument_1//iso:*[@xml:id= $fragment-id ] |
|
493
|
+
id($fragment-id) |
|
494
|
+
$theDocument_1//iso:*[@id= $fragment-id ]" />
|
495
|
+
|
496
|
+
|
497
|
+
<xsl:choose>
|
498
|
+
<!-- case 0 -->
|
499
|
+
<xsl:when test="not($theFragment_1)">
|
500
|
+
<xsl:message terminate="no">
|
501
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
502
|
+
<xsl:value-of select="@href" />
|
503
|
+
</xsl:message>
|
504
|
+
</xsl:when>
|
505
|
+
|
506
|
+
|
507
|
+
<!-- case 1 REMOVED -->
|
508
|
+
|
509
|
+
<!-- case 2 REMOVED -->
|
510
|
+
|
511
|
+
|
512
|
+
<!-- case 3 -->
|
513
|
+
<xsl:otherwise>
|
514
|
+
|
515
|
+
<xsl:apply-templates
|
516
|
+
select=" $theFragment_1[1]/*" mode="dsdl:go" />
|
517
|
+
</xsl:otherwise>
|
518
|
+
</xsl:choose>
|
519
|
+
</xsl:for-each>
|
520
|
+
</xsl:when>
|
521
|
+
|
522
|
+
<!-- Case where there is no ID so we include the whole document -->
|
523
|
+
<!-- Experimental addition: include fragments of children -->
|
524
|
+
<xsl:otherwise>
|
525
|
+
<xsl:variable name="theDocument_2"
|
526
|
+
select="document( $document-uri,/ )" />
|
527
|
+
<xsl:variable name="theFragment_2"
|
528
|
+
select="$theDocument_2/iso:*" />
|
529
|
+
<xsl:variable name="theContainedFragments"
|
530
|
+
select="$theDocument_2/*/iso:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
|
531
|
+
<xsl:if test="not($theDocument_2)">
|
532
|
+
<xsl:message terminate="no">
|
533
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
534
|
+
<xsl:value-of select="@href" />
|
535
|
+
</xsl:message>
|
536
|
+
</xsl:if>
|
537
|
+
|
538
|
+
<!-- There are three cases for includes:
|
539
|
+
0) No text specified- error!
|
540
|
+
|
541
|
+
1) REMOVED
|
542
|
+
|
543
|
+
2) REMOVED
|
544
|
+
|
545
|
+
3) Otherwise, include the pointed-to element
|
546
|
+
-->
|
547
|
+
<xsl:choose>
|
548
|
+
<!-- case 0 -->
|
549
|
+
<xsl:when
|
550
|
+
test="not($theFragment_2) and not ($theContainedFragments)">
|
551
|
+
<xsl:message terminate="no">
|
552
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
553
|
+
<xsl:value-of select="@href" />
|
554
|
+
</xsl:message>
|
555
|
+
</xsl:when>
|
556
|
+
|
557
|
+
<!-- case 1 removed -->
|
558
|
+
|
559
|
+
<!-- case 2 removed -->
|
560
|
+
|
561
|
+
<!-- If this were XLST 2, we could use
|
562
|
+
if ($theFragment) then $theFragment else $theContainedFragments
|
563
|
+
here (thanks to KN)
|
564
|
+
-->
|
565
|
+
<!-- case 3 -->
|
566
|
+
<xsl:otherwise>
|
567
|
+
<xsl:apply-templates
|
568
|
+
select="$theFragment_2/* " mode="dsdl:go" />
|
569
|
+
</xsl:otherwise>
|
570
|
+
</xsl:choose>
|
571
|
+
</xsl:otherwise>
|
572
|
+
</xsl:choose>
|
573
|
+
</xsl:otherwise>
|
574
|
+
</xsl:choose>
|
575
|
+
|
576
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
577
|
+
<xsl:value-of select="@href" />
|
578
|
+
</xsl:processing-instruction>
|
579
|
+
</xsl:template>
|
580
|
+
|
581
|
+
|
582
|
+
|
583
|
+
<!-- =========================================================== -->
|
584
|
+
<!-- Handle Schematron 1.6 inclusions: clone of ISO code above -->
|
585
|
+
<!-- =========================================================== -->
|
586
|
+
|
587
|
+
|
588
|
+
<!-- Extend the URI syntax to allow # references -->
|
589
|
+
<!-- Add experimental support for simple containers like /xxx:xxx/schold:pattern to allow better includes -->
|
590
|
+
<xsl:template match="schold:include" mode="dsdl:go">
|
591
|
+
<xsl:variable name="document-uri"
|
592
|
+
select="substring-before(concat(@href,'#'), '#')" />
|
593
|
+
<xsl:variable name="fragment-id"
|
594
|
+
select="substring-after(@href, '#')" />
|
595
|
+
|
596
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
597
|
+
<xsl:value-of select="@href" />
|
598
|
+
</xsl:processing-instruction>
|
599
|
+
|
600
|
+
<xsl:choose>
|
601
|
+
<xsl:when test="not( $include-schematron = 'true' )">
|
602
|
+
<xslt:copy>
|
603
|
+
<xslt:copy-of select="@*" />
|
604
|
+
<xslt:apply-templates mode="dsdl:go" />
|
605
|
+
</xslt:copy>
|
606
|
+
</xsl:when>
|
607
|
+
<xsl:otherwise>
|
608
|
+
<xsl:choose>
|
609
|
+
|
610
|
+
<xsl:when
|
611
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
612
|
+
<xsl:message>
|
613
|
+
Error: Impossible URL in Schematron include
|
614
|
+
</xsl:message>
|
615
|
+
</xsl:when>
|
616
|
+
|
617
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
618
|
+
<xslt:when
|
619
|
+
test="string-length( $document-uri ) = 0">
|
620
|
+
<xslt:apply-templates mode="dsdl:go"
|
621
|
+
select="//schold:*[@xml:id= $fragment-id ]
|
622
|
+
|id( $fragment-id)
|
623
|
+
| //schold:*[@id= $fragment-id ]" />
|
624
|
+
</xslt:when>
|
625
|
+
|
626
|
+
<!-- case where there is a fragment in another document (should be an iso: element) -->
|
627
|
+
<xsl:when
|
628
|
+
test="string-length( $fragment-id ) > 0">
|
629
|
+
<xsl:variable name="theDocument_1"
|
630
|
+
select="document( $document-uri,/ )" />
|
631
|
+
<xsl:if test="not($theDocument_1)">
|
632
|
+
<xsl:message terminate="no">
|
633
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
634
|
+
<xsl:value-of select="@href" />
|
635
|
+
</xsl:message>
|
636
|
+
</xsl:if>
|
637
|
+
<!-- use for-each to rebase id() to $theDocument -->
|
638
|
+
<xsl:for-each select="$theDocument_1">
|
639
|
+
<xsl:variable name="theFragment_1"
|
640
|
+
select=" $theDocument_1//schold:*[@xml:id= $fragment-id ] |
|
641
|
+
id($fragment-id) |
|
642
|
+
$theDocument_1//schold:*[@id= $fragment-id ]" />
|
643
|
+
<xsl:if
|
644
|
+
test=" $theFragment_1/self::schold:schema ">
|
645
|
+
<xsl:message>
|
646
|
+
Schema error: Use include to include
|
647
|
+
fragments, not a whole schema
|
648
|
+
</xsl:message>
|
649
|
+
</xsl:if>
|
650
|
+
<xsl:if test="not($theFragment_1)">
|
651
|
+
<xsl:message terminate="no">
|
652
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
653
|
+
<xsl:value-of select="@href" />
|
654
|
+
</xsl:message>
|
655
|
+
</xsl:if>
|
656
|
+
<xsl:apply-templates
|
657
|
+
select=" $theFragment_1[1]" mode="dsdl:go" />
|
658
|
+
</xsl:for-each>
|
659
|
+
</xsl:when>
|
660
|
+
|
661
|
+
<!-- Case where there is no ID so we include the whole document -->
|
662
|
+
<!-- Experimental addition: include fragments of children -->
|
663
|
+
<xsl:otherwise>
|
664
|
+
<xsl:variable name="theDocument_2"
|
665
|
+
select="document( $document-uri,/ )" />
|
666
|
+
<xsl:variable name="theFragment_2"
|
667
|
+
select="$theDocument_2/iso:*" />
|
668
|
+
<xsl:variable name="theContainedFragments"
|
669
|
+
select="$theDocument_2/*/schold:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
|
670
|
+
<xsl:if test="not($theDocument_2)">
|
671
|
+
<xsl:message terminate="no">
|
672
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
673
|
+
<xsl:value-of select="@href" />
|
674
|
+
</xsl:message>
|
675
|
+
</xsl:if>
|
676
|
+
|
677
|
+
<xsl:if
|
678
|
+
test=" $theFragment_2/self::schold:schema or $theContainedFragments/self::schold:schema">
|
679
|
+
<xsl:message>
|
680
|
+
Schema error: Use include to include
|
681
|
+
fragments, not a whole schema
|
682
|
+
</xsl:message>
|
683
|
+
</xsl:if>
|
684
|
+
<xsl:if
|
685
|
+
test="not($theFragment_2) and not ($theContainedFragments)">
|
686
|
+
<xsl:message terminate="no">
|
687
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
688
|
+
<xsl:value-of select="@href" />
|
689
|
+
</xsl:message>
|
690
|
+
</xsl:if>
|
691
|
+
<!-- If this were XLST 2, we could use
|
692
|
+
if ($theFragment) then $theFragment else $theContainedFragments
|
693
|
+
here (thanks to KN)
|
694
|
+
-->
|
695
|
+
<xsl:choose>
|
696
|
+
<xsl:when test=" $theFragment_2 ">
|
697
|
+
<xsl:apply-templates
|
698
|
+
select="$theFragment_2 " mode="dsdl:go" />
|
699
|
+
</xsl:when>
|
700
|
+
<xsl:otherwise>
|
701
|
+
<!-- WARNING! EXPERIMENTAL! Use at your own risk. This may be discontinued! -->
|
702
|
+
<xsl:apply-templates
|
703
|
+
select=" $theContainedFragments " mode="dsdl:go" />
|
704
|
+
</xsl:otherwise>
|
705
|
+
</xsl:choose>
|
706
|
+
</xsl:otherwise>
|
707
|
+
</xsl:choose>
|
708
|
+
|
709
|
+
</xsl:otherwise>
|
710
|
+
</xsl:choose>
|
711
|
+
|
712
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
713
|
+
<xsl:value-of select="@href" />
|
714
|
+
</xsl:processing-instruction>
|
715
|
+
</xsl:template>
|
716
|
+
<!-- =========================================================== -->
|
717
|
+
<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
|
718
|
+
<!-- Part 5 - DataType Library Language - DTLL -->
|
719
|
+
<!-- Committee Draft Experimental support only -->
|
720
|
+
<!-- The <include> element may well be replaced by XInclude in -->
|
721
|
+
<!-- any final version. -->
|
722
|
+
<!-- =========================================================== -->
|
723
|
+
<xslt:template match="dtll:include" mode="dsdl:go">
|
724
|
+
<!-- Insert subschema -->
|
725
|
+
|
726
|
+
<xsl:variable name="document-uri"
|
727
|
+
select="substring-before(concat(@href,'#'), '#')" />
|
728
|
+
<xsl:variable name="fragment-id"
|
729
|
+
select="substring-after(@href, '#')" />
|
730
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
731
|
+
<xsl:value-of select="@href" />
|
732
|
+
</xsl:processing-instruction>
|
733
|
+
<xsl:choose>
|
734
|
+
<xsl:when test="not( $include-dtll = 'true' )">
|
735
|
+
<xslt:copy>
|
736
|
+
<xslt:copy-of select="@*" />
|
737
|
+
<xslt:apply-templates mode="dsdl:go" />
|
738
|
+
</xslt:copy>
|
739
|
+
</xsl:when>
|
740
|
+
<xsl:otherwise>
|
741
|
+
<xsl:choose>
|
742
|
+
|
743
|
+
<xsl:when
|
744
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
745
|
+
<xsl:message>
|
746
|
+
Error: Impossible URL in DTLL include
|
747
|
+
</xsl:message>
|
748
|
+
</xsl:when>
|
749
|
+
|
750
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
751
|
+
<xslt:when
|
752
|
+
test="string-length( $document-uri ) = 0">
|
753
|
+
<xslt:apply-templates mode="dsdl:go"
|
754
|
+
select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
|
755
|
+
| //*[@id= $fragment-id ]" />
|
756
|
+
</xslt:when>
|
757
|
+
|
758
|
+
<xsl:when
|
759
|
+
test="string-length( $fragment-id ) > 0">
|
760
|
+
<xsl:variable name="theDocument_1"
|
761
|
+
select="document( $document-uri,/ )" />
|
762
|
+
<xsl:if test="not($theDocument_1)">
|
763
|
+
<xsl:message terminate="no">
|
764
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
765
|
+
<xsl:value-of select="@href" />
|
766
|
+
</xsl:message>
|
767
|
+
</xsl:if>
|
768
|
+
<!-- use for-each to rebase id() to $theDocument -->
|
769
|
+
<xsl:for-each select="$theDocument_1">
|
770
|
+
<xsl:variable name="theFragment_1"
|
771
|
+
select="$theDocument_1//*[@xml:id= $fragment-id ]
|
772
|
+
| id( $fragment-id )
|
773
|
+
| $theDocument_1//*[@id= $fragment-id ]" />
|
774
|
+
<xsl:if test="not($theFragment_1)">
|
775
|
+
<xsl:message terminate="no">
|
776
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
777
|
+
<xsl:value-of select="@href" />
|
778
|
+
</xsl:message>
|
779
|
+
</xsl:if>
|
780
|
+
<xsl:apply-templates
|
781
|
+
select=" $theFragment_1[1]" mode="dsdl:go" />
|
782
|
+
</xsl:for-each>
|
783
|
+
</xsl:when>
|
784
|
+
|
785
|
+
<xsl:otherwise>
|
786
|
+
<xsl:variable name="theDocument_2"
|
787
|
+
select="document( $document-uri,/ )" />
|
788
|
+
<xsl:variable name="theFragment_2"
|
789
|
+
select="$theDocument_2/*" />
|
790
|
+
|
791
|
+
<xsl:if test="not($theDocument_2)">
|
792
|
+
<xsl:message terminate="no">
|
793
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
794
|
+
<xsl:value-of select="@href" />
|
795
|
+
</xsl:message>
|
796
|
+
</xsl:if>
|
797
|
+
|
798
|
+
<xsl:if test="not($theFragment_2)">
|
799
|
+
<xsl:message terminate="no">
|
800
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
801
|
+
<xsl:value-of select="@href" />
|
802
|
+
</xsl:message>
|
803
|
+
</xsl:if>
|
804
|
+
<xsl:apply-templates select="$theFragment_2 "
|
805
|
+
mode="dsdl:go" />
|
806
|
+
</xsl:otherwise>
|
807
|
+
</xsl:choose>
|
808
|
+
|
809
|
+
</xsl:otherwise>
|
810
|
+
</xsl:choose>
|
811
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
812
|
+
<xsl:value-of select="@href" />
|
813
|
+
</xsl:processing-instruction>
|
814
|
+
</xslt:template>
|
815
|
+
|
816
|
+
<!-- =========================================================== -->
|
817
|
+
<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
|
818
|
+
<!-- Part 7 - Character Repertoire Description Language - CRDL -->
|
819
|
+
<!-- Final Committee Draft 2008-01-11 Experimental support only -->
|
820
|
+
<!-- =========================================================== -->
|
821
|
+
<xslt:template match="crdl:ref" mode="dsdl:go">
|
822
|
+
<!-- Insert subschema -->
|
823
|
+
|
824
|
+
<xsl:variable name="document-uri"
|
825
|
+
select="substring-before(concat(@href,'#'), '#')" />
|
826
|
+
<xsl:variable name="fragment-id"
|
827
|
+
select="substring-after(@href, '#')" />
|
828
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
829
|
+
<xsl:value-of select="@href" />
|
830
|
+
</xsl:processing-instruction>
|
831
|
+
<xsl:choose>
|
832
|
+
<xsl:when test="not( $include-crdl = 'true' )">
|
833
|
+
<xslt:copy>
|
834
|
+
<xslt:copy-of select="@*" />
|
835
|
+
<xslt:apply-templates mode="dsdl:go" />
|
836
|
+
</xslt:copy>
|
837
|
+
</xsl:when>
|
838
|
+
<xsl:otherwise>
|
839
|
+
<xsl:choose>
|
840
|
+
|
841
|
+
<xsl:when
|
842
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
843
|
+
<xsl:message>
|
844
|
+
Error: Impossible URL in CRDL include
|
845
|
+
</xsl:message>
|
846
|
+
</xsl:when>
|
847
|
+
|
848
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
849
|
+
<xslt:when
|
850
|
+
test="string-length( $document-uri ) = 0">
|
851
|
+
|
852
|
+
<xslt:apply-templates mode="dsdl:go"
|
853
|
+
select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
|
854
|
+
| //*[@id= $fragment-id ]" />
|
855
|
+
</xslt:when>
|
856
|
+
|
857
|
+
<xsl:when
|
858
|
+
test="string-length( $fragment-id ) > 0">
|
859
|
+
<xsl:variable name="theDocument_1"
|
860
|
+
select="document( $document-uri,/ )" />
|
861
|
+
<xsl:if test="not($theDocument_1)">
|
862
|
+
<xsl:message terminate="no">
|
863
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
864
|
+
<xsl:value-of select="@href" />
|
865
|
+
</xsl:message>
|
866
|
+
</xsl:if>
|
867
|
+
<!-- use for-each to rebase id() to $theDocument -->
|
868
|
+
<xsl:for-each select="$theDocument_1">
|
869
|
+
<xsl:variable name="theFragment_1"
|
870
|
+
select="$theDocument_1//*[@xml:id= $fragment-id ]
|
871
|
+
| id( $fragment-id )
|
872
|
+
| $theDocument_1//*[@id= $fragment-id ]" />
|
873
|
+
|
874
|
+
<xsl:if test="not($theFragment_1)">
|
875
|
+
<xsl:message terminate="no">
|
876
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
877
|
+
<xsl:value-of select="@href" />
|
878
|
+
</xsl:message>
|
879
|
+
</xsl:if>
|
880
|
+
<xsl:apply-templates select=" $theFragment_1 "
|
881
|
+
mode="dsdl:go" />
|
882
|
+
</xsl:for-each>
|
883
|
+
</xsl:when>
|
884
|
+
|
885
|
+
<xsl:otherwise>
|
886
|
+
<xsl:variable name="theDocument_2"
|
887
|
+
select="document( $document-uri,/ )" />
|
888
|
+
<xsl:variable name="theFragment_2"
|
889
|
+
select="$theDocument_2/*" />
|
890
|
+
|
891
|
+
<xsl:if test="not($theDocument_2)">
|
892
|
+
<xsl:message terminate="no">
|
893
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
894
|
+
<xsl:value-of select="@href" />
|
895
|
+
</xsl:message>
|
896
|
+
</xsl:if>
|
897
|
+
<xsl:if test="not($theFragment_2)">
|
898
|
+
<xsl:message terminate="no">
|
899
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
900
|
+
<xsl:value-of select="@href" />
|
901
|
+
</xsl:message>
|
902
|
+
</xsl:if>
|
903
|
+
|
904
|
+
<xsl:apply-templates select="$theFragment_2"
|
905
|
+
mode="dsdl:go" />
|
906
|
+
</xsl:otherwise>
|
907
|
+
</xsl:choose>
|
908
|
+
|
909
|
+
</xsl:otherwise>
|
910
|
+
</xsl:choose>
|
911
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
912
|
+
<xsl:value-of select="@href" />
|
913
|
+
</xsl:processing-instruction>
|
914
|
+
</xslt:template>
|
915
|
+
|
916
|
+
|
917
|
+
<!-- =========================================================== -->
|
918
|
+
<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
|
919
|
+
<!-- Part 4 - Namespace-based Validation Dispatching Language - NVDL -->
|
920
|
+
<!-- Note: This does not include schemas referenced for -->
|
921
|
+
<!-- validation, it merely handles any simple XIncludes -->
|
922
|
+
<!-- =========================================================== -->
|
923
|
+
<!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
|
924
|
+
<!-- Part 8 - Document Schema Renaming Language - DSRL -->
|
925
|
+
<!-- Note: Final? Committee Draft Experimental support only -->
|
926
|
+
<!-- =========================================================== -->
|
927
|
+
<!-- XInclude support for id based references only, with 1 level -->
|
928
|
+
<!-- of fallback. -->
|
929
|
+
<!-- =========================================================== -->
|
930
|
+
|
931
|
+
<xslt:template mode="dsdl:go"
|
932
|
+
match="xi:include[@href][not(@parseType) or @parseType ='xml']">
|
933
|
+
<!-- Simple inclusions only here -->
|
934
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
935
|
+
<xsl:value-of select="@href" />
|
936
|
+
</xsl:processing-instruction>
|
937
|
+
<xsl:choose>
|
938
|
+
<xsl:when test="not( $include-xinclude = 'true' )">
|
939
|
+
<xslt:copy>
|
940
|
+
<xslt:copy-of select="@*" />
|
941
|
+
<xslt:apply-templates mode="dsdl:go" />
|
942
|
+
</xslt:copy>
|
943
|
+
</xsl:when>
|
944
|
+
<xsl:otherwise>
|
945
|
+
<xsl:choose>
|
946
|
+
|
947
|
+
<xsl:when test="contains( @href, '#')">
|
948
|
+
<xsl:message terminate="yes">
|
949
|
+
Fatal error: Xinclude href contains fragment
|
950
|
+
identifier #
|
951
|
+
</xsl:message>
|
952
|
+
</xsl:when>
|
953
|
+
|
954
|
+
|
955
|
+
<xsl:when test="contains( @xpointer, '(')">
|
956
|
+
<xsl:message terminate="yes">
|
957
|
+
Fatal error: Sorry, this software only
|
958
|
+
supports simple ids in XInclude xpointers
|
959
|
+
</xsl:message>
|
960
|
+
</xsl:when>
|
961
|
+
|
962
|
+
<xsl:when
|
963
|
+
test="string-length( @href ) = 0 and string-length( @xpointer ) = 0">
|
964
|
+
|
965
|
+
<xsl:message terminate="yes">
|
966
|
+
Fatal Error: Impossible URL in XInclude
|
967
|
+
include
|
968
|
+
</xsl:message>
|
969
|
+
</xsl:when>
|
970
|
+
|
971
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
972
|
+
<xslt:when test="string-length( @href ) = 0">
|
973
|
+
|
974
|
+
<xslt:apply-templates mode="dsdl:go"
|
975
|
+
select="//*[@xml:id= current()/@xpointer ] | id( @xpointer)
|
976
|
+
| //*[@id= current()/@xpointer ]" />
|
977
|
+
</xslt:when>
|
978
|
+
|
979
|
+
<xsl:when
|
980
|
+
test="string-length( @xpointer ) > 0">
|
981
|
+
<xsl:variable name="theDocument_1"
|
982
|
+
select="document( @href,/ )" />
|
983
|
+
<xsl:variable name="theFragment_1"
|
984
|
+
select="$theDocument_1//*[@xml:id= current()/@xpointer ]
|
985
|
+
|
986
|
+
| $theDocument_1//*[@id= current()/@xpointer ]" />
|
987
|
+
<!-- removed
|
988
|
+
| $theDocument_1/id( @xpointer)
|
989
|
+
because it requires rebasing in XSLT1 and that would mess up the use of current()
|
990
|
+
-->
|
991
|
+
|
992
|
+
|
993
|
+
<!-- Allow one level of fallback, to another XInclude -->
|
994
|
+
<xsl:if test="not($theDocument_1)">
|
995
|
+
<xsl:choose>
|
996
|
+
<xsl:when test="xi:fallback">
|
997
|
+
<xsl:variable name="theDocument_2"
|
998
|
+
select="document( xi:fallback[1]/xi:include[not(@parseType)
|
999
|
+
or @parseType='xml']/@href,/ )" />
|
1000
|
+
<xsl:variable name="theFragment_2"
|
1001
|
+
select="$theDocument_2//*[@xml:id= current()/xi:fallback[1]/xi:include/@xpointer ]
|
1002
|
+
| $theDocument_2//*[@id= current()/xi:fallback[1]/xi:include/@xpointer ]" />
|
1003
|
+
<!-- removed
|
1004
|
+
| $theDocument_2/id( xi:fallback[1]/xi:include/@xpointer)
|
1005
|
+
because it id() would need rebasing in XSLT1 and that would mess up use of current()
|
1006
|
+
-->
|
1007
|
+
|
1008
|
+
<xsl:if
|
1009
|
+
test="not($theDocument_2)">
|
1010
|
+
|
1011
|
+
<xsl:message terminate="no">
|
1012
|
+
<xsl:text>Unable to open referenced included file and fallback
|
1013
|
+
file: </xsl:text>
|
1014
|
+
<xsl:value-of
|
1015
|
+
select="@href" />
|
1016
|
+
</xsl:message>
|
1017
|
+
</xsl:if>
|
1018
|
+
</xsl:when>
|
1019
|
+
<xsl:otherwise>
|
1020
|
+
<xsl:message terminate="no">
|
1021
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
1022
|
+
<xsl:value-of select="@href" />
|
1023
|
+
</xsl:message>
|
1024
|
+
</xsl:otherwise>
|
1025
|
+
</xsl:choose>
|
1026
|
+
</xsl:if>
|
1027
|
+
<xsl:apply-templates select=" $theFragment_1"
|
1028
|
+
mode="dsdl:go" />
|
1029
|
+
</xsl:when>
|
1030
|
+
|
1031
|
+
<!-- Document but no fragment specified -->
|
1032
|
+
<xsl:otherwise>
|
1033
|
+
<xsl:variable name="theDocument_3"
|
1034
|
+
select="document( @href,/ )" />
|
1035
|
+
<xsl:variable name="theFragment_3"
|
1036
|
+
select="$theDocument_3/*" />
|
1037
|
+
|
1038
|
+
<xsl:if test="not($theDocument_3)">
|
1039
|
+
<xsl:message terminate="no">
|
1040
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
1041
|
+
<xsl:value-of select="@href" />
|
1042
|
+
</xsl:message>
|
1043
|
+
</xsl:if>
|
1044
|
+
|
1045
|
+
<xsl:apply-templates select="$theFragment_3 "
|
1046
|
+
mode="dsdl:go" />
|
1047
|
+
</xsl:otherwise>
|
1048
|
+
</xsl:choose>
|
1049
|
+
|
1050
|
+
</xsl:otherwise>
|
1051
|
+
</xsl:choose>
|
1052
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
1053
|
+
<xsl:value-of select="@href" />
|
1054
|
+
</xsl:processing-instruction>
|
1055
|
+
</xslt:template>
|
1056
|
+
|
1057
|
+
<!-- =========================================================== -->
|
1058
|
+
<!-- W3C XLink 1.1 embedded simple links -->
|
1059
|
+
<!-- =========================================================== -->
|
1060
|
+
<xslt:template
|
1061
|
+
match="*[@xlink:href][not(parent::*[@xlink:type='complex'])]
|
1062
|
+
[not(@xlink:type) or (@xlink:type='simple')]
|
1063
|
+
[@xlink:show='embed']
|
1064
|
+
[not(@xlink:actuate) or (@xlink:actuate='onLoad')]"
|
1065
|
+
mode="dsdl:go" priority="1">
|
1066
|
+
|
1067
|
+
<xsl:variable name="document-uri"
|
1068
|
+
select="substring-before(concat(@xlink:href,'#'), '#')" />
|
1069
|
+
<xsl:variable name="fragment-id"
|
1070
|
+
select="substring-after(@xlink:href, '#')" />
|
1071
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_START">
|
1072
|
+
<xsl:value-of select="@xlink:href" />
|
1073
|
+
</xsl:processing-instruction>
|
1074
|
+
<xsl:choose>
|
1075
|
+
<xsl:when test="not( $include-xlink = 'true' )">
|
1076
|
+
<xslt:copy>
|
1077
|
+
<xslt:copy-of select="@*" />
|
1078
|
+
<xslt:apply-templates mode="dsdl:go" />
|
1079
|
+
</xslt:copy>
|
1080
|
+
</xsl:when>
|
1081
|
+
<xsl:otherwise>
|
1082
|
+
<xsl:choose>
|
1083
|
+
|
1084
|
+
<xsl:when
|
1085
|
+
test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
|
1086
|
+
<xsl:message>
|
1087
|
+
Error: Impossible URL in XLink embedding
|
1088
|
+
link
|
1089
|
+
</xsl:message>
|
1090
|
+
</xsl:when>
|
1091
|
+
|
1092
|
+
<!-- this case is when there is in embedded schema in the same document elsewhere -->
|
1093
|
+
<xslt:when
|
1094
|
+
test="string-length( $document-uri ) = 0">
|
1095
|
+
<xslt:apply-templates mode="dsdl:go"
|
1096
|
+
select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
|
1097
|
+
| //*[@id= $fragment-id ]" />
|
1098
|
+
</xslt:when>
|
1099
|
+
|
1100
|
+
<xsl:when
|
1101
|
+
test="string-length( $fragment-id ) > 0">
|
1102
|
+
<xsl:variable name="theDocument_1"
|
1103
|
+
select="document( $document-uri,/ )" />
|
1104
|
+
<xsl:if test="not($theDocument_1)">
|
1105
|
+
<xsl:message terminate="no">
|
1106
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
1107
|
+
<xsl:value-of select="@xlink:href" />
|
1108
|
+
</xsl:message>
|
1109
|
+
</xsl:if>
|
1110
|
+
<!-- use for-each to rebase id() to $theDocument -->
|
1111
|
+
<xsl:for-each select="$theDocument_1">
|
1112
|
+
<xsl:variable name="theFragment_1"
|
1113
|
+
select="$theDocument_1//*[@xml:id= $fragment-id ]
|
1114
|
+
| id( $fragment-id )
|
1115
|
+
| $theDocument_1//*[@id= $fragment-id ]" />
|
1116
|
+
<xsl:if test="not($theFragment_1)">
|
1117
|
+
<xsl:message terminate="no">
|
1118
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
1119
|
+
<xsl:value-of select="@xlink:href" />
|
1120
|
+
</xsl:message>
|
1121
|
+
</xsl:if>
|
1122
|
+
<xsl:apply-templates
|
1123
|
+
select=" $theFragment_1[1]" mode="dsdl:go" />
|
1124
|
+
</xsl:for-each>
|
1125
|
+
</xsl:when>
|
1126
|
+
|
1127
|
+
<xsl:otherwise>
|
1128
|
+
<xsl:variable name="theDocument_2"
|
1129
|
+
select="document( $document-uri,/ )" />
|
1130
|
+
<xsl:variable name="theFragment_2"
|
1131
|
+
select="$theDocument_2/*" />
|
1132
|
+
|
1133
|
+
<xsl:if test="not($theDocument_2)">
|
1134
|
+
<xsl:message terminate="no">
|
1135
|
+
<xsl:text>Unable to open referenced included file: </xsl:text>
|
1136
|
+
<xsl:value-of select="@xlink:href" />
|
1137
|
+
</xsl:message>
|
1138
|
+
</xsl:if>
|
1139
|
+
|
1140
|
+
<xsl:if test="not($theFragment_2)">
|
1141
|
+
<xsl:message terminate="no">
|
1142
|
+
<xsl:text>Unable to locate id attribute: </xsl:text>
|
1143
|
+
<xsl:value-of select="@xlink:href" />
|
1144
|
+
</xsl:message>
|
1145
|
+
</xsl:if>
|
1146
|
+
<xsl:apply-templates select="$theFragment_2 "
|
1147
|
+
mode="dsdl:go" />
|
1148
|
+
</xsl:otherwise>
|
1149
|
+
</xsl:choose>
|
1150
|
+
|
1151
|
+
</xsl:otherwise>
|
1152
|
+
</xsl:choose>
|
1153
|
+
|
1154
|
+
<xsl:processing-instruction name="DSDL_INCLUDE_END">
|
1155
|
+
<xsl:value-of select="@xlink:href" />
|
1156
|
+
</xsl:processing-instruction>
|
1157
|
+
</xslt:template>
|
1158
|
+
|
1159
|
+
|
1160
|
+
</xslt:stylesheet>
|