Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / odds2 / odd2relax.xsl @ 187

History | View | Annotate | Download (21.9 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet 
3
    xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
4
    xmlns:fo="http://www.w3.org/1999/XSL/Format" 
5
    xmlns:html="http://www.w3.org/1999/xhtml" 
6
    xmlns:i="http://www.iso.org/ns/1.0"
7
    xmlns:rng="http://relaxng.org/ns/structure/1.0"
8
    xmlns:s="http://www.ascc.net/xml/schematron" 
9
    xmlns:sch="http://purl.oclc.org/dsdl/schematron" 
10
    xmlns:tei="http://www.tei-c.org/ns/1.0"
11
    xmlns:teix="http://www.tei-c.org/ns/Examples" 
12
    xmlns:xi="http://www.w3.org/2001/XInclude"
13
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
14
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
15
    exclude-result-prefixes="a fo html i rng s sch tei teix xi xs xsl" 
16
    version="2.0">
17
  <xsl:import href="teiodds.xsl"/>
18
  <xsl:import href="../common2/i18n.xsl"/>
19
  <xsl:import href="../common2/tei-param.xsl"/>
20
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
21
      <desc>
22
         <p> TEI stylesheet for making Relax NG schema from ODD </p>
23
         <p>This software is dual-licensed:
24

    
25
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
26
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
27

    
28
2. http://www.opensource.org/licenses/BSD-2-Clause
29
		
30
All rights reserved.
31

    
32
Redistribution and use in source and binary forms, with or without
33
modification, are permitted provided that the following conditions are
34
met:
35

    
36
* Redistributions of source code must retain the above copyright
37
notice, this list of conditions and the following disclaimer.
38

    
39
* Redistributions in binary form must reproduce the above copyright
40
notice, this list of conditions and the following disclaimer in the
41
documentation and/or other materials provided with the distribution.
42

    
43
This software is provided by the copyright holders and contributors
44
"as is" and any express or implied warranties, including, but not
45
limited to, the implied warranties of merchantability and fitness for
46
a particular purpose are disclaimed. In no event shall the copyright
47
holder or contributors be liable for any direct, indirect, incidental,
48
special, exemplary, or consequential damages (including, but not
49
limited to, procurement of substitute goods or services; loss of use,
50
data, or profits; or business interruption) however caused and on any
51
theory of liability, whether in contract, strict liability, or tort
52
(including negligence or otherwise) arising in any way out of the use
53
of this software, even if advised of the possibility of such damage.
54
</p>
55
         <p>Author: See AUTHORS</p>
56
         <p>Id: $Id: odd2relax.xsl 9669 2011-11-07 19:17:54Z rahtz $</p>
57
         <p>Copyright: 2011, TEI Consortium</p>
58
      </desc>
59
   </doc>
60
  <xsl:output encoding="utf-8" indent="yes" method="xml"/>
61
  <xsl:key name="PATTERNS" match="rng:define[rng:element/@name]" use="'true'"/>
62
  <xsl:key name="REFED" match="rng:ref" use="@name"/>
63
  <xsl:key name="DEFED" match="rng:define" use="@name"/>
64
  <xsl:key name="EDEF" match="rng:define[rng:element]" use="1"/>
65
  <xsl:param name="verbose"/>
66
  <xsl:param name="outputDir"/>
67
  <xsl:param name="appendixWords"/>
68
  <xsl:template name="makeAnchor">
69
      <xsl:param name="name"/>
70
  </xsl:template>
71
  <xsl:param name="splitLevel">-1</xsl:param>
72
  <xsl:variable name="oddmode">dtd</xsl:variable>
73
  <xsl:variable name="filesuffix"/>
74
   <!-- get list of output files -->
75
  <xsl:variable name="linkColor"/>
76
  <xsl:template match="tei:moduleSpec[@type='decls']"/>
77
  <xsl:template match="/">
78
      <xsl:choose>
79
         <xsl:when test="key('SCHEMASPECS',1)">
80
            <xsl:apply-templates select="key('LISTSCHEMASPECS',$whichSchemaSpec)"/>
81
         </xsl:when>
82
         <xsl:otherwise>
83
            <xsl:apply-templates select="key('Modules',1)"/>
84
         </xsl:otherwise>
85
      </xsl:choose>
86
  </xsl:template>
87
  <xsl:template match="tei:schemaSpec">
88
      <xsl:variable name="documentationLanguage">
89
         <xsl:call-template name="generateDoc"/>
90
      </xsl:variable>
91
      <xsl:if test="$verbose='true'">
92
         <xsl:message> 
93
	           <xsl:text>I18N setup: Pattern prefix: </xsl:text>
94
	           <xsl:value-of select="$generalPrefix"/> 
95
	           <xsl:text>. Target  language: </xsl:text>
96
	           <xsl:value-of select="$targetLanguage"/>
97
	           <xsl:text>. Documentation language: </xsl:text>
98
	           <xsl:value-of select="$documentationLanguage"/>
99
         </xsl:message>
100
      </xsl:if>
101
      <xsl:variable name="filename" select="@ident"/>
102
      <xsl:if test="$verbose='true'">
103
         <xsl:message> process schemaSpec [<xsl:value-of select="@ident"/>] </xsl:message>
104
      </xsl:if>
105
      <xsl:call-template name="generateOutput">
106
         <xsl:with-param name="method">xml</xsl:with-param>
107
         <xsl:with-param name="suffix">.rng</xsl:with-param>
108
         <xsl:with-param name="body">
109
            <grammar xmlns="http://relaxng.org/ns/structure/1.0"
110
		     xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
111
		     xmlns:xlink="http://www.w3.org/1999/xlink"
112
                     datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
113
               <xsl:attribute name="ns">
114
                  <xsl:choose>
115
                     <xsl:when test="@ns">
116
                        <xsl:value-of select="@ns"/>
117
                     </xsl:when>
118
                     <xsl:otherwise>
119
                        <xsl:text>http://www.tei-c.org/ns/1.0</xsl:text>
120
		     </xsl:otherwise>
121
                  </xsl:choose>
122
               </xsl:attribute>
123
               <xsl:comment>
124
                  <xsl:text>&#10;Schema generated from ODD source </xsl:text>
125
                  <xsl:call-template name="showDate"/>
126
                  <xsl:text>. </xsl:text>
127
                  <xsl:call-template name="makeTEIVersion"/>
128
                  <xsl:call-template name="makeDescription"/>
129
                  <xsl:text>&#10;</xsl:text>
130
               </xsl:comment>
131
	       <xsl:comment>
132
		 <xsl:call-template name="copyright"/>
133
	       </xsl:comment>
134
               <xsl:choose>
135
                  <xsl:when test="tei:specGrpRef">
136
                     <xsl:variable name="SPECS">
137
                        <tei:schemaSpec>
138
                           <xsl:copy-of select="@*"/>
139
                           <xsl:apply-templates mode="expandSpecs"/>
140
                        </tei:schemaSpec>
141
                     </xsl:variable>
142
                     <xsl:for-each select="$SPECS/tei:schemaSpec">
143
                        <xsl:call-template name="schemaSpecBody"/>
144
                     </xsl:for-each>
145
                  </xsl:when>
146
                  <xsl:otherwise>
147
                     <xsl:call-template name="schemaSpecBody"/>
148
                  </xsl:otherwise>
149
               </xsl:choose>
150
	              <xsl:apply-templates select="tei:constraintSpec"/>
151
            </grammar>
152
         </xsl:with-param>
153
      </xsl:call-template>
154
  </xsl:template>
155

    
156
  <xsl:template name="schemaSpecBody">
157
      <xsl:variable name="pass1">
158
         <root>
159
	   <xsl:if test="$verbose='true'">
160
	     <xsl:message>start importing moduleRef components</xsl:message>
161
	   </xsl:if>
162
	   <xsl:apply-templates mode="tangle" select="tei:moduleRef"/>
163
	   <xsl:for-each select="tei:macroSpec">
164
	     <xsl:apply-templates mode="tangle" select="."/>
165
	   </xsl:for-each>
166
	   <xsl:apply-templates mode="tangle" select="tei:elementSpec|tei:classSpec"/>
167
	   <xsl:choose>
168
	     <xsl:when test="@start and @start=''"/>
169
	     <xsl:when test="@start and contains(@start,' ')">
170
	       <start xmlns="http://relaxng.org/ns/structure/1.0">
171
		 <choice>
172
		   <xsl:call-template name="startNames">
173
		     <xsl:with-param name="toks" select="@start"/>
174
		   </xsl:call-template>
175
		 </choice>
176
	       </start>
177
	     </xsl:when>
178
	     <xsl:when test="@start">
179
	       <start xmlns="http://relaxng.org/ns/structure/1.0">
180
		 <ref name="{$generalPrefix}{@start}"/>
181
	       </start>
182
	     </xsl:when>
183
	     <xsl:when test="key('IDENTS','teiCorpus')">
184
	       <start xmlns="http://relaxng.org/ns/structure/1.0">
185
		 <choice>
186
		   <ref name="{$generalPrefix}TEI"/>
187
		   <ref name="{$generalPrefix}teiCorpus"/>
188
		 </choice>
189
	       </start>
190
	     </xsl:when>
191
	     <xsl:otherwise>
192
	       <start xmlns="http://relaxng.org/ns/structure/1.0">
193
		 <ref name="{$generalPrefix}TEI"/>
194
	       </start>
195
	     </xsl:otherwise>
196
	   </xsl:choose>
197
         </root>
198
      </xsl:variable>
199

    
200
      <!-- in 2nd and 3rd  passes, throw away any RNG <define> elements
201
    which do not have a <ref>, any <ref> which has no <define>
202
    to point to, and any empty <choice> -->
203
      <xsl:variable name="pass2">
204
	<xsl:for-each select="$pass1/root">
205
	  <root>
206
	    <xsl:apply-templates mode="pass2"/>
207
	  </root>
208
	</xsl:for-each>
209
      </xsl:variable>
210
      <xsl:for-each select="$pass2/root">
211
	<xsl:apply-templates mode="pass3"/>
212
      </xsl:for-each>
213
  </xsl:template>
214

    
215
  <xsl:template name="startNames">
216
      <xsl:param name="toks"/>
217
      <xsl:if test="not($toks='')">
218
         <xsl:choose>
219
            <xsl:when test="contains($toks,' ')">
220
               <ref xmlns="http://relaxng.org/ns/structure/1.0"
221
                    name="{$generalPrefix}{substring-before($toks, ' ')}"/>
222
               <xsl:call-template name="startNames">
223
                  <xsl:with-param name="toks" select="substring-after($toks, ' ')"/>
224
               </xsl:call-template>
225
            </xsl:when>
226
            <xsl:otherwise>
227
               <ref xmlns="http://relaxng.org/ns/structure/1.0" name="{$generalPrefix}{$toks}"/>
228
            </xsl:otherwise>
229
         </xsl:choose>
230
      </xsl:if>
231
  </xsl:template>
232
  <xsl:template match="tei:moduleSpec">
233
      <xsl:if test="@ident and not(@mode='change' or @mode='replace' or   @mode='delete')">
234
         <xsl:choose>
235
            <xsl:when test="parent::tei:schemaSpec">
236
               <xsl:call-template name="moduleSpec-body"/>
237
            </xsl:when>
238
            <xsl:otherwise>
239
               <xsl:call-template name="generateOutput">
240
                  <xsl:with-param name="method">xml</xsl:with-param>
241
                  <xsl:with-param name="suffix">.rng</xsl:with-param>
242
                  <xsl:with-param name="body">
243
                     <grammar xmlns="http://relaxng.org/ns/structure/1.0"
244
                              datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
245
                        <xsl:comment>
246
                           <xsl:text>Schema generated </xsl:text>
247
                           <xsl:call-template name="showDate"/>
248
                           <xsl:call-template name="makeTEIVersion"/>
249
			   <xsl:call-template name="copyright"/>
250
                           <xsl:call-template name="makeDescription"/>
251
                        </xsl:comment>
252
                        <xsl:call-template name="moduleSpec-body"/>
253
                     </grammar>
254
                  </xsl:with-param>
255
               </xsl:call-template>
256
            </xsl:otherwise>
257
         </xsl:choose>
258
      </xsl:if>
259
  </xsl:template>
260
  <xsl:template name="moduleSpec-body">
261
      <xsl:variable name="filename" select="@ident"/>
262
      <xsl:comment>Definitions from module <xsl:value-of select="@ident"/>
263
      </xsl:comment>
264
      <xsl:comment>Set global predeclared macros</xsl:comment>
265
      <xsl:if test="@type='core'">
266
         <xsl:call-template name="NameList"/>
267
         <xsl:for-each select="key('PredeclareAllMacros',1)">
268
            <define xmlns="http://relaxng.org/ns/structure/1.0" name="{@ident}">
269
               <choice>
270
                  <notAllowed/>
271
               </choice>
272
            </define>
273
         </xsl:for-each>
274
      </xsl:if>
275
      <xsl:comment>Set predeclared macros</xsl:comment>
276
      <xsl:for-each select="key('PredeclareMacrosModule',@ident)">
277
         <xsl:apply-templates mode="tangle" select="."/>
278
      </xsl:for-each>
279
      <xsl:if test="@type='core'">
280
         <xsl:call-template name="predeclare-classes"/>
281
      </xsl:if>
282
      <xsl:comment>0. predeclared macros</xsl:comment>
283
      <xsl:for-each select="key('PredeclareMacrosModule',@ident)">
284
         <xsl:apply-templates mode="tangle" select="."/>
285
      </xsl:for-each>
286
      <xsl:comment>1. classes</xsl:comment>
287
      <xsl:for-each select="key('ClassModule',@ident)">
288
         <xsl:choose>
289
            <xsl:when test="@module='core' and @predeclare='true'"> </xsl:when>
290
            <xsl:otherwise>
291
               <xsl:apply-templates mode="tangle" select="."/>
292
            </xsl:otherwise>
293
         </xsl:choose>
294
      </xsl:for-each>
295
      <xsl:comment>2. elements</xsl:comment>
296
      <xsl:apply-templates mode="tangle" select="key('ElementModule',@ident)">
297
         <xsl:sort select="@ident"/>
298
      </xsl:apply-templates>
299
      <xsl:comment>3. macros</xsl:comment>
300
      <xsl:for-each select="key('MacroModule',@ident)">
301
         <xsl:choose>
302
            <xsl:when test="@predeclare='true'"/>
303
            <!--	<xsl:when test="key('PredeclareMacros',@ident)"/>-->
304
        <xsl:otherwise>
305
               <xsl:apply-templates mode="tangle" select="."/>
306
            </xsl:otherwise>
307
         </xsl:choose>
308
      </xsl:for-each>
309
  </xsl:template>
310
  <xsl:template name="NameList">
311
<!-- walk over all the elementSpec elements and make list of 
312
       elements -->
313
    <xsl:for-each select="key('ELEMENTDOCS',1)">
314
         <xsl:sort select="@ident"/>
315
         <define xmlns="http://relaxng.org/ns/structure/1.0" combine="choice" name="{@ident}">
316
            <notAllowed/>
317
         </define>
318
      </xsl:for-each>
319
  </xsl:template>
320
  <xsl:template name="predeclare-classes">
321
      <xsl:comment>0. predeclared classes</xsl:comment>
322
      <xsl:for-each select="key('predeclaredClasses',1)">
323
         <xsl:choose>
324
            <xsl:when test="@type='model'">
325
               <xsl:apply-templates mode="processModel" select=".">
326
                  <xsl:with-param name="declare">true</xsl:with-param>
327
               </xsl:apply-templates>
328
            </xsl:when>
329
            <xsl:when test="@type='atts'">
330
               <xsl:apply-templates mode="processDefaultAtts" select="."/>
331
            </xsl:when>
332
         </xsl:choose>
333
      </xsl:for-each>
334
  </xsl:template>
335
  <xsl:template match="tei:specGrpRef" mode="tangle">
336
      <xsl:param name="filename"/>
337
      <xsl:if test="$verbose='true'">
338
         <xsl:message> specGrpRef to <xsl:value-of select="@target"/>
339
         </xsl:message>
340
      </xsl:if>
341
      <xsl:choose>
342
         <xsl:when test="starts-with(@target,'#')">
343
            <xsl:for-each select="id(substring(@target,2))">
344
               <xsl:apply-templates mode="ok" select=".">
345
                  <xsl:with-param name="filename" select="$filename"/>
346
               </xsl:apply-templates>
347
            </xsl:for-each>
348
         </xsl:when>
349
         <xsl:otherwise>
350
            <xsl:for-each select="document(@target)/tei:specGrp">
351
               <xsl:apply-templates mode="ok" select=".">
352
                  <xsl:with-param name="filename" select="$filename"/>
353
               </xsl:apply-templates>
354
            </xsl:for-each>
355
         </xsl:otherwise>
356
      </xsl:choose>
357
  </xsl:template>
358
  <xsl:template name="bitOut">
359
      <xsl:param name="grammar"/>
360
      <xsl:param name="element"/>
361
      <xsl:param name="content"/>
362
      <xsl:for-each select="$content/Wrapper">
363
         <xsl:apply-templates mode="justcopy" select="*"/>
364
      </xsl:for-each>
365
  </xsl:template>
366
  <xsl:template name="refdoc"/>
367
  <xsl:template name="typewriter">
368
      <xsl:param name="text"/>
369
  </xsl:template>
370

    
371
  <xsl:template match="processing-instruction()" mode="tangle">
372
    <xsl:copy-of select="."/>
373
  </xsl:template>
374

    
375
  <xsl:template match="tei:constraintSpec[@scheme='schematron']">
376
      <xsl:apply-templates/>
377
  </xsl:template>
378

    
379
  <xsl:template match="tei:constraintSpec[@scheme='isoschematron']">
380
      <xsl:apply-templates/>
381
  </xsl:template>
382

    
383
  <xsl:template match="s:*">
384
      <xsl:call-template name="processSchematron"/>
385
  </xsl:template>
386

    
387
  <xsl:template match="sch:*">
388
      <xsl:call-template name="processSchematron"/>
389
  </xsl:template>
390

    
391

    
392
<!-- pass 2, clean up unused elements -->
393
  <xsl:template
394
      match="rng:anyName[parent::rng:define]"
395
      mode='pass2'>
396
    <zeroOrMore xmlns="http://relaxng.org/ns/structure/1.0">
397
      <choice>
398
	<xsl:for-each select="key('EDEF',1)">	  
399
	  <ref name="{@name}"/>
400
	</xsl:for-each>
401
      </choice>
402
    </zeroOrMore>
403
  </xsl:template>
404

    
405
  <xsl:template match="processing-instruction()" mode="pass2">
406
    <xsl:copy-of select="."/>
407
  </xsl:template>
408

    
409
  <xsl:template match="@*|text()|comment()" mode="pass2">
410
      <xsl:copy-of select="."/>
411
  </xsl:template>
412
    
413
  <xsl:template match="*" mode="pass2">
414
      <xsl:copy>
415
         <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass2"/>
416
      </xsl:copy>
417
  </xsl:template>
418

    
419
  <xsl:template match="rng:define" mode="pass2">
420
      <xsl:choose>
421
         <xsl:when test="key('REFED',@name)">
422
	   <define xmlns="http://relaxng.org/ns/structure/1.0" >
423
	     <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass2"/>
424
	   </define>
425
	 </xsl:when>
426
	 <xsl:otherwise>
427
	   <xsl:if test="$verbose='true'">
428
	     <xsl:message>ZAP definition of unused pattern <xsl:value-of select="@name"/></xsl:message>
429
	   </xsl:if>
430
	 </xsl:otherwise>
431
      </xsl:choose>
432
  </xsl:template>
433
  
434
  <xsl:template match="rng:ref" mode="pass2">
435
      <xsl:choose>
436
	<!--
437
	<xsl:when test="(ancestor::rng:element[@name='egXML' or
438
			 @name='constraint']         or
439
			 ancestor::rng:define[contains(@name,'macro.schemaPattern')])
440
			 and         starts-with(@name, 'macro.any')">
441
	           <xsl:for-each select="key('DEFED', @name)">
442
	              <xsl:apply-templates mode="justcopy"
443
					   select="*"/>
444
	           </xsl:for-each>
445
         </xsl:when>
446
	 -->
447
         <xsl:when test="key('DEFED',@name)">
448
	   <ref xmlns="http://relaxng.org/ns/structure/1.0" name="{@name}"/>
449
         </xsl:when>
450
	 <xsl:when test="ancestor::tei:content[@autoPrefix='false']">
451
	   <ref xmlns="http://relaxng.org/ns/structure/1.0" name="{@name}"/>
452
         </xsl:when>
453
         <xsl:when test="count(parent::*/*)=1">
454
	   <xsl:if test="$verbose='true'">
455
	     <xsl:message>ZAP reference to undefined [<xsl:value-of select="@name"/>] and leave empty behind</xsl:message>
456
	   </xsl:if>
457
	   <empty xmlns="http://relaxng.org/ns/structure/1.0"/>
458
         </xsl:when>
459
         <xsl:otherwise>
460
	   <xsl:if test="$verbose='true'">
461
	     <xsl:message>ZAP reference to undefined [<xsl:value-of select="@name"/>]</xsl:message>
462
	   </xsl:if>
463
         </xsl:otherwise>
464
      </xsl:choose>
465
  </xsl:template>
466

    
467
<!-- and again -->
468

    
469
  <xsl:template match="processing-instruction()" mode="pass3">
470
    <xsl:choose>
471
      <xsl:when test="name()='NameList'">
472
	<xsl:if test="$verbose='true'">
473
	  <xsl:message>Expand 'NameList' processing-instruction</xsl:message>
474
	</xsl:if>
475
	<choice xmlns="http://relaxng.org/ns/structure/1.0">
476
	  <xsl:for-each select="key('PATTERNS','true')">
477
	    <ref name="{@name}" />
478
	  </xsl:for-each>
479
	</choice>
480
      </xsl:when>
481
    </xsl:choose>
482
  </xsl:template>
483

    
484
  <xsl:template match="rng:choice" mode="pass3">
485
      <xsl:choose>
486
	<xsl:when test="rng:value|rng:name|.//rng:ref|.//rng:text|.//rng:data">
487
	   <choice xmlns="http://relaxng.org/ns/structure/1.0">
488
	     <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass3"/>
489
	   </choice>
490
	</xsl:when>
491
	<xsl:otherwise>
492
      <xsl:if test="$verbose='true'">
493
        <xsl:message>KILLED <xsl:copy-of select="."/></xsl:message>
494
      </xsl:if>
495
	  <empty xmlns="http://relaxng.org/ns/structure/1.0"/>
496
	</xsl:otherwise>
497
      </xsl:choose>			   
498
  </xsl:template>
499

    
500
  <xsl:template match="rng:optional" mode="pass3">
501
      <xsl:choose>
502
	<xsl:when test="rng:zeroOrMore and count(*)=1">
503
	     <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass3"/>
504
	</xsl:when>
505
	<xsl:when test="count(*)=1 and rng:group[count(*)=1 and	rng:zeroOrMore]">
506
	     <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass3"/>
507
	</xsl:when>
508
	<xsl:otherwise>
509
	  <optional xmlns="http://relaxng.org/ns/structure/1.0">
510
	     <xsl:apply-templates
511
		 select="*|@*|processing-instruction()|comment()|text()"
512
		 mode="pass3"/>
513
	  </optional>
514
	</xsl:otherwise>
515
      </xsl:choose>			   
516
  </xsl:template>
517

    
518
  <xsl:template match="rng:oneOrMore" mode="pass3">
519
      <xsl:choose>
520
	<xsl:when test="rng:zeroOrMore and count(*)=1">
521
	     <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass3"/>
522
	</xsl:when>
523
	<xsl:when test="count(*)=1 and rng:group[count(*)=1 and	rng:zeroOrMore]">
524
	     <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass3"/>
525
	</xsl:when>
526
	<xsl:otherwise>
527
	  <oneOrMore xmlns="http://relaxng.org/ns/structure/1.0">
528
	     <xsl:apply-templates
529
		 select="*|@*|processing-instruction()|comment()|text()"
530
		 mode="pass3"/>
531
	  </oneOrMore>
532
	</xsl:otherwise>
533
      </xsl:choose>			   
534
  </xsl:template>
535

    
536
  <xsl:template match="rng:zeroOrMore" mode="pass3">
537
      <xsl:choose>
538
	<xsl:when test="rng:zeroOrMore and count(*)=1">
539
	     <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass3"/>
540
	</xsl:when>
541
	<xsl:when test="count(*)=1 and rng:group[count(*)=1 and	rng:zeroOrMore]">
542
	     <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass3"/>
543
	</xsl:when>
544
	<xsl:otherwise>
545
	  <zeroOrMore xmlns="http://relaxng.org/ns/structure/1.0">
546
	     <xsl:apply-templates
547
		 select="*|@*|processing-instruction()|comment()|text()"
548
		 mode="pass3"/>
549
	  </zeroOrMore>
550
	</xsl:otherwise>
551
      </xsl:choose>			   
552
  </xsl:template>
553

    
554
  <xsl:template match="@*|text()|comment()" mode="pass3">
555
      <xsl:copy-of select="."/>
556
  </xsl:template>
557
    
558
  <xsl:template match="*" mode="pass3">
559
      <xsl:copy>
560
         <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="pass3"/>
561
      </xsl:copy>
562
  </xsl:template>
563

    
564
  <xsl:template name="copyright">
565
    <xsl:for-each
566
	select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:availability">
567
      <xsl:if test="count(tei:licence)&gt;1">
568
	<xsl:text>This material is dual-licensed.&#10;</xsl:text>
569
      </xsl:if>
570
      <xsl:apply-templates/>
571
    </xsl:for-each>
572
  </xsl:template>
573

    
574
  <xsl:template match="tei:licence">
575
    <xsl:if test="@target">
576
      <xsl:text>[</xsl:text>
577
      <xsl:value-of select="@target"/>
578
      <xsl:text>] </xsl:text>
579
    </xsl:if>
580
    <xsl:apply-templates/>
581
  </xsl:template>
582

    
583
</xsl:stylesheet>