Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / common2 / verbatim.xsl @ 187

History | View | Annotate | Download (29.4 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:i="http://www.iso.org/ns/1.0" xmlns:rng="http://relaxng.org/ns/structure/1.0" xmlns:s="http://www.ascc.net/xml/schematron" xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:teix="http://www.tei-c.org/ns/Examples" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dbk="http://docbook.org/ns/docbook" exclude-result-prefixes="a fo html i rng s sch tei teix xi xs xsl         m atom xlink xhtml dbk" version="2.0">
3
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
4
    <desc>
5
      <p> TEI stylesheet dealing with elements from the core module. </p>
6
      <p>This software is dual-licensed:
7

    
8
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
9
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
10

    
11
2. http://www.opensource.org/licenses/BSD-2-Clause
12
		
13
All rights reserved.
14

    
15
Redistribution and use in source and binary forms, with or without
16
modification, are permitted provided that the following conditions are
17
met:
18

    
19
* Redistributions of source code must retain the above copyright
20
notice, this list of conditions and the following disclaimer.
21

    
22
* Redistributions in binary form must reproduce the above copyright
23
notice, this list of conditions and the following disclaimer in the
24
documentation and/or other materials provided with the distribution.
25

    
26
This software is provided by the copyright holders and contributors
27
"as is" and any express or implied warranties, including, but not
28
limited to, the implied warranties of merchantability and fitness for
29
a particular purpose are disclaimed. In no event shall the copyright
30
holder or contributors be liable for any direct, indirect, incidental,
31
special, exemplary, or consequential damages (including, but not
32
limited to, procurement of substitute goods or services; loss of use,
33
data, or profits; or business interruption) however caused and on any
34
theory of liability, whether in contract, strict liability, or tort
35
(including negligence or otherwise) arising in any way out of the use
36
of this software, even if advised of the possibility of such damage.
37
</p>
38
      <p>Author: See AUTHORS</p>
39
      <p>Id: $Id: verbatim.xsl 9646 2011-11-05 23:39:08Z rahtz $</p>
40
      <p>Copyright: 2011, TEI Consortium</p>
41
    </desc>
42
  </doc>
43
  <xsl:strip-space elements="teix:* rng:* xsl:* xhtml:* atom:* m:*"/>
44
  <xsl:param name="useNSPrefixes">true</xsl:param>
45
  <xsl:param name="startComment">&lt;span class="comment"&gt;</xsl:param>
46
  <xsl:param name="endComment">&lt;/span&gt;</xsl:param>
47
  <xsl:param name="startElement">&lt;span class="element"&gt;</xsl:param>
48
  <xsl:param name="endElement">&lt;/span&gt;</xsl:param>
49
  <xsl:param name="startElementName">&lt;span class="elementname"&gt;</xsl:param>
50
  <xsl:param name="endElementName">&lt;/span&gt;</xsl:param>
51
  <xsl:param name="highlightStartElementName">&lt;span class="highlightelementname"&gt;</xsl:param>
52
  <xsl:param name="highlightEndElementName">&lt;/span&gt;</xsl:param>
53
  <xsl:param name="startAttribute">&lt;span class="attribute"&gt;</xsl:param>
54
  <xsl:param name="endAttribute">&lt;/span&gt;</xsl:param>
55
  <xsl:param name="startAttributeValue">&lt;span class="attributevalue"&gt;</xsl:param>
56
  <xsl:param name="endAttributeValue">&lt;/span&gt;</xsl:param>
57
  <xsl:param name="startNamespace">&lt;span class="namespace"&gt;</xsl:param>
58
  <xsl:param name="endNamespace">&lt;/span&gt;</xsl:param>
59
  <xsl:param name="spaceCharacter">&#160;</xsl:param>
60
  <xsl:param name="showNamespaceDecls">true</xsl:param>
61
  <xsl:param name="forceWrap">false</xsl:param>
62
  <xsl:param name="wrapLength">65</xsl:param>
63
  <xsl:param name="attLength">40</xsl:param>
64
  <xsl:param name="attsOnSameLine">3</xsl:param>
65
  <xsl:param name="omitNSDecls">http://www.tei-c.org/ns/1.0</xsl:param>
66
  <xsl:key name="NSUsed" match="*" use="namespace-uri()"/>
67
  <xsl:key name="NSUsed" match="@*" use="namespace-uri()"/>
68
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
69
    <desc>
70
      <p>Work out a namespace prefix for verbatim elements</p>
71
      <p>[common] </p>
72
    </desc>
73
  </doc>
74
  <xsl:template name="verbatim-getNamespacePrefix">
75
    <xsl:variable name="ns" select="namespace-uri()"/>
76
    <xsl:variable name="prefix" select="tei:getPrefix($ns,ancestor-or-self::*[1])[1]"/>
77
    <xsl:choose>
78
      <xsl:when test="$prefix !=''">
79
        <xsl:value-of select="$prefix"/>
80
      </xsl:when>
81
      <xsl:when test="$ns='http://docbook.org/ns/docbook'">dbk</xsl:when>
82
      <xsl:when test="$ns='http://earth.google.com/kml/2.1'">kml</xsl:when>
83
      <xsl:when test="$ns='http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0'">nvdl</xsl:when>
84
      <xsl:when test="$ns='http://purl.org/rss/1.0/modules/event/'">ev</xsl:when>
85
      <xsl:when test="$ns='http://purl.oclc.org/dsdl/schematron'">s</xsl:when>
86
      <xsl:when test="$ns='http://relaxng.org/ns/compatibility/annotations/1.0'">a</xsl:when>
87
      <xsl:when test="$ns='http://relaxng.org/ns/structure/1.0'">rng</xsl:when>
88
      <xsl:when test="$ns='http://www.ascc.net/xml/schematron'">sch</xsl:when>
89
      <xsl:when test="$ns='http://www.w3.org/1998/Math/MathML'">m</xsl:when>
90
      <xsl:when test="$ns='http://www.w3.org/1999/XSL/Transform'">xsl</xsl:when>
91
      <xsl:when test="$ns='http://www.w3.org/1999/xhtml'">xhtml</xsl:when>
92
      <xsl:when test="$ns='http://www.w3.org/1999/xlink'">xlink</xsl:when>
93
      <xsl:when test="$ns='http://www.w3.org/2001/XMLSchema'">xsd</xsl:when>
94
      <xsl:when test="$ns='http://www.w3.org/2005/11/its'">its</xsl:when>
95
      <xsl:when test="$ns='http://www.w3.org/2005/Atom'">atom</xsl:when>
96
      <xsl:when test="$ns='http://www.w3.org/XML/1998/namespace'">xml</xsl:when>
97
      <xsl:when test="$ns='http://www.tei-c.org/ns/geneticEditions'">ge</xsl:when>
98
    </xsl:choose>
99
  </xsl:template>
100
  <xsl:template name="verbatim-newLine"/>
101
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
102
    <desc>
103
      <p>Make newline</p>
104
      <p>[common] </p>
105
      <param name="id">identifier for debugging only</param>
106
    </desc>
107
  </doc>
108
  <xsl:template name="verbatim-lineBreak">
109
    <xsl:param name="id"/>
110
    <xsl:text>&#10;</xsl:text>
111
  </xsl:template>
112
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
113
    <desc>
114
      <p>Process comments in verbatim mode</p>
115
      <p>[common] </p>
116
    </desc>
117
  </doc>
118
  <xsl:template match="comment()" mode="verbatim">
119
    <xsl:choose>
120
      <xsl:when test="ancestor::Wrapper"/>
121
      <xsl:when test="ancestor::xhtml:Wrapper"/>
122
      <xsl:otherwise>
123
        <xsl:call-template name="verbatim-lineBreak">
124
          <xsl:with-param name="id">21</xsl:with-param>
125
        </xsl:call-template>
126
        <xsl:value-of disable-output-escaping="yes" select="$startComment"/>
127
        <xsl:text>&lt;!--</xsl:text>
128
        <xsl:choose>
129
          <xsl:when test="$forceWrap='true'">
130
            <xsl:call-template name="verbatim-reformatText">
131
              <xsl:with-param name="sofar">0</xsl:with-param>
132
              <xsl:with-param name="indent">
133
                <xsl:text> </xsl:text>
134
              </xsl:with-param>
135
              <xsl:with-param name="text">
136
                <xsl:value-of select="normalize-space(.)"/>
137
              </xsl:with-param>
138
            </xsl:call-template>
139
          </xsl:when>
140
          <xsl:otherwise>
141
            <xsl:value-of select="."/>
142
          </xsl:otherwise>
143
        </xsl:choose>
144
        <xsl:text>--&gt;</xsl:text>
145
        <xsl:value-of disable-output-escaping="yes" select="$endComment"/>
146
      </xsl:otherwise>
147
    </xsl:choose>
148
  </xsl:template>
149
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
150
    <desc>
151
      <p>Process text nodes in verbatim mode</p>
152
      <p>[common] </p>
153
    </desc>
154
  </doc>
155
  <xsl:template match="text()" mode="verbatim">
156
    <xsl:choose>
157
      <xsl:when test="$forceWrap='true'">
158
        <xsl:variable name="indent">
159
          <xsl:for-each select="parent::*">
160
            <xsl:call-template name="verbatim-makeIndent"/>
161
          </xsl:for-each>
162
        </xsl:variable>
163
        <xsl:if test="string-length(.)&gt;$wrapLength or parent::sch:assert">
164
          <xsl:text>&#10;</xsl:text>
165
          <xsl:value-of select="$indent"/>
166
        </xsl:if>
167
        <xsl:call-template name="verbatim-reformatText">
168
          <xsl:with-param name="sofar">0</xsl:with-param>
169
          <xsl:with-param name="indent">
170
            <xsl:value-of select="$indent"/>
171
          </xsl:with-param>
172
          <xsl:with-param name="text">
173
            <xsl:value-of select="normalize-space(.)"/>
174
          </xsl:with-param>
175
        </xsl:call-template>
176
        <xsl:if test="string-length(.)&gt;$wrapLength or parent::sch:assert">
177
          <xsl:text>&#10;</xsl:text>
178
          <xsl:value-of select="$indent"/>
179
        </xsl:if>
180
      </xsl:when>
181
      <xsl:when test="not(preceding-sibling::node() or         contains(.,'&#10;'))">
182
        <xsl:if test="starts-with(.,' ')">
183
          <xsl:text> </xsl:text>
184
        </xsl:if>
185
        <xsl:call-template name="verbatim-Text">
186
          <xsl:with-param name="words">
187
            <xsl:value-of select="normalize-space(.)"/>
188
          </xsl:with-param>
189
        </xsl:call-template>
190
        <xsl:if test="substring(.,string-length(.),1)=' '">
191
          <xsl:text> </xsl:text>
192
        </xsl:if>
193
      </xsl:when>
194
      <xsl:when test="normalize-space(.)=''">
195
        <xsl:for-each select="following-sibling::*[1]">
196
          <xsl:call-template name="verbatim-lineBreak">
197
            <xsl:with-param name="id">7</xsl:with-param>
198
          </xsl:call-template>
199
          <xsl:call-template name="verbatim-makeIndent"/>
200
        </xsl:for-each>
201
      </xsl:when>
202
      <xsl:otherwise>
203
        <xsl:call-template name="verbatim-wraptext">
204
          <xsl:with-param name="count">0</xsl:with-param>
205
          <xsl:with-param name="indent">
206
            <xsl:for-each select="parent::*">
207
              <xsl:call-template name="verbatim-makeIndent"/>
208
            </xsl:for-each>
209
          </xsl:with-param>
210
          <xsl:with-param name="text">
211
            <xsl:choose>
212
              <xsl:when test="starts-with(.,'&#10;') and not          (preceding-sibling::node())">
213
                <xsl:value-of select="translate(substring(.,2),'&#10;','⌤')"/>
214
              </xsl:when>
215
              <xsl:otherwise>
216
                <xsl:value-of select="translate(.,'&#10;','⌤')"/>
217
              </xsl:otherwise>
218
            </xsl:choose>
219
          </xsl:with-param>
220
        </xsl:call-template>
221
        <!--
222
	<xsl:if test="substring(.,string-length(.))=' '">
223
	  <xsl:text> </xsl:text>
224
	</xsl:if>
225
	-->
226
      </xsl:otherwise>
227
    </xsl:choose>
228
  </xsl:template>
229
  <xsl:template name="verbatim-reformatText">
230
    <xsl:param name="indent"/>
231
    <xsl:param name="text"/>
232
    <xsl:param name="sofar"/>
233
    <xsl:choose>
234
      <xsl:when test="number($sofar) &gt; $wrapLength">
235
        <xsl:text>&#10;</xsl:text>
236
        <xsl:value-of select="$indent"/>
237
        <xsl:call-template name="verbatim-reformatText">
238
          <xsl:with-param name="text">
239
            <xsl:value-of select="$text"/>
240
          </xsl:with-param>
241
          <xsl:with-param name="sofar">
242
            <xsl:text>0</xsl:text>
243
          </xsl:with-param>
244
          <xsl:with-param name="indent">
245
            <xsl:value-of select="$indent"/>
246
          </xsl:with-param>
247
        </xsl:call-template>
248
      </xsl:when>
249
      <xsl:when test="not(contains($text,' '))">
250
        <xsl:call-template name="verbatim-Text">
251
          <xsl:with-param name="words">
252
            <xsl:value-of select="$text"/>
253
          </xsl:with-param>
254
        </xsl:call-template>
255
      </xsl:when>
256
      <xsl:otherwise>
257
        <xsl:variable name="chunk">
258
          <xsl:value-of select="substring-before($text,' ')"/>
259
        </xsl:variable>
260
        <xsl:call-template name="verbatim-Text">
261
          <xsl:with-param name="words">
262
            <xsl:value-of select="$chunk"/>
263
            <xsl:text> </xsl:text>
264
          </xsl:with-param>
265
        </xsl:call-template>
266
        <xsl:call-template name="verbatim-reformatText">
267
          <xsl:with-param name="text">
268
            <xsl:value-of select="substring-after($text,' ')"/>
269
          </xsl:with-param>
270
          <xsl:with-param name="sofar">
271
            <xsl:value-of select="$sofar + string-length($chunk) + 1"/>
272
          </xsl:with-param>
273
          <xsl:with-param name="indent">
274
            <xsl:value-of select="$indent"/>
275
          </xsl:with-param>
276
        </xsl:call-template>
277
      </xsl:otherwise>
278
    </xsl:choose>
279
  </xsl:template>
280
  <xsl:template name="verbatim-wraptext">
281
    <xsl:param name="indent"/>
282
    <xsl:param name="text"/>
283
    <xsl:param name="count">0</xsl:param>
284
    <xsl:variable name="finalSpace">
285
      <xsl:choose>
286
        <xsl:when test="substring($text,string-length($text),1)=' '">
287
          <xsl:text> </xsl:text>
288
        </xsl:when>
289
        <xsl:when test="substring($text,string-length($text),1)='⌤'">
290
          <xsl:text> </xsl:text>
291
        </xsl:when>
292
        <xsl:otherwise>
293
          <xsl:text/>
294
        </xsl:otherwise>
295
      </xsl:choose>
296
    </xsl:variable>
297
    <!--
298
<xsl:message>my text is [<xsl:value-of select="$text"/>]</xsl:message>
299
<xsl:message>my space is [<xsl:value-of select="$finalSpace"/>]</xsl:message>
300
-->
301
    <xsl:choose>
302
      <xsl:when test="normalize-space($text)=''"/>
303
      <xsl:when test="contains($text,'⌤')">
304
        <xsl:if test="$count &gt; 0">
305
          <xsl:value-of select="$indent"/>
306
          <xsl:text> </xsl:text>
307
        </xsl:if>
308
        <xsl:if test="starts-with($text,' ')">
309
          <xsl:text> </xsl:text>
310
        </xsl:if>
311
        <xsl:call-template name="verbatim-Text">
312
          <xsl:with-param name="words">
313
            <xsl:value-of select="normalize-space(substring-before($text,'⌤'))"/>
314
          </xsl:with-param>
315
        </xsl:call-template>
316
        <!--	<xsl:if test="not(substring-after($text,'&#10;')='')">-->
317
        <xsl:call-template name="verbatim-lineBreak">
318
          <xsl:with-param name="id">6</xsl:with-param>
319
        </xsl:call-template>
320
        <xsl:value-of select="$indent"/>
321
        <xsl:call-template name="verbatim-wraptext">
322
          <xsl:with-param name="indent">
323
            <xsl:value-of select="$indent"/>
324
          </xsl:with-param>
325
          <xsl:with-param name="text">
326
            <xsl:value-of select="normalize-space(substring-after($text,'⌤'))"/>
327
            <xsl:value-of select="$finalSpace"/>
328
          </xsl:with-param>
329
          <xsl:with-param name="count">
330
            <xsl:value-of select="$count + 1"/>
331
          </xsl:with-param>
332
        </xsl:call-template>
333
      </xsl:when>
334
      <xsl:otherwise>
335
        <xsl:if test="starts-with($text,' ')">
336
          <xsl:text> </xsl:text>
337
        </xsl:if>
338
        <xsl:if test="$count &gt; 0 and parent::*">
339
          <xsl:value-of select="$indent"/>
340
          <xsl:text> </xsl:text>
341
        </xsl:if>
342
        <xsl:call-template name="verbatim-Text">
343
          <xsl:with-param name="words">
344
            <xsl:value-of select="normalize-space($text)"/>
345
            <xsl:value-of select="$finalSpace"/>
346
          </xsl:with-param>
347
        </xsl:call-template>
348
      </xsl:otherwise>
349
    </xsl:choose>
350
  </xsl:template>
351
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
352
    <desc>
353
      <p>Process text and process ampersands</p>
354
      <p>[common] </p>
355
    </desc>
356
  </doc>
357
  <xsl:template name="verbatim-Text">
358
    <xsl:param name="words"/>
359
    <xsl:analyze-string select="$words" regex="(&amp;)(.)">
360
      <xsl:matching-substring>
361
        <xsl:choose>
362
          <xsl:when test="starts-with(regex-group(2),'#')">
363
            <xsl:text>&amp;</xsl:text>
364
          </xsl:when>
365
          <xsl:otherwise>
366
            <xsl:text>&amp;amp;</xsl:text>
367
          </xsl:otherwise>
368
        </xsl:choose>
369
        <xsl:value-of select="regex-group(2)"/>
370
      </xsl:matching-substring>
371
      <xsl:non-matching-substring>
372
        <xsl:value-of select="."/>
373
      </xsl:non-matching-substring>
374
    </xsl:analyze-string>
375
  </xsl:template>
376
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
377
    <desc>
378
      <p>Process default elements in verbatim mode</p>
379
      <p>[common] </p>
380
    </desc>
381
  </doc>
382
  <xsl:template match="*" mode="verbatim">
383
    <xsl:param name="highlight"/>
384
    <xsl:choose>
385
      <xsl:when test="parent::xhtml:Wrapper"/>
386
      <!--      <xsl:when test="child::node()[last()]/self::text()[not(.='')] and child::node()[1]/self::text()[not(.='')]"/>-->
387
      <xsl:when test="not(parent::*)  or parent::teix:egXML">
388
        <xsl:choose>
389
          <xsl:when test="preceding-sibling::node()[1][self::text()]      and following-sibling::node()[1][self::text()]"/>
390
          <xsl:when test="preceding-sibling::*">
391
            <xsl:call-template name="verbatim-lineBreak">
392
              <xsl:with-param name="id">-1</xsl:with-param>
393
            </xsl:call-template>
394
          </xsl:when>
395
          <xsl:otherwise>
396
            <xsl:call-template name="verbatim-newLine"/>
397
            <!-- <xsl:call-template name="makeIndent"/>-->
398
          </xsl:otherwise>
399
        </xsl:choose>
400
      </xsl:when>
401
      <xsl:when test="not(preceding-sibling::node())">
402
        <xsl:call-template name="verbatim-lineBreak">
403
          <xsl:with-param name="id">-2</xsl:with-param>
404
        </xsl:call-template>
405
        <xsl:call-template name="verbatim-makeIndent"/>
406
      </xsl:when>
407
      <xsl:when test="preceding-sibling::node()[1]/self::*">
408
        <xsl:call-template name="verbatim-lineBreak">
409
          <xsl:with-param name="id">1</xsl:with-param>
410
        </xsl:call-template>
411
        <xsl:call-template name="verbatim-makeIndent"/>
412
      </xsl:when>
413
      <xsl:when test="preceding-sibling::node()[1]/self::text()"> </xsl:when>
414
      <xsl:otherwise>
415
        <xsl:call-template name="verbatim-lineBreak">
416
          <xsl:with-param name="id">9</xsl:with-param>
417
        </xsl:call-template>
418
        <xsl:call-template name="verbatim-makeIndent"/>
419
      </xsl:otherwise>
420
    </xsl:choose>
421
    <xsl:value-of disable-output-escaping="yes" select="$startElement"/>
422
    <xsl:text>&lt;</xsl:text>
423
    <xsl:call-template name="verbatim-makeElementName">
424
      <xsl:with-param name="start">true</xsl:with-param>
425
      <xsl:with-param name="highlight">
426
        <xsl:value-of select="$highlight"/>
427
      </xsl:with-param>
428
    </xsl:call-template>
429
    <xsl:apply-templates select="@*" mode="verbatim"/>
430
    <xsl:if test="$showNamespaceDecls='true' or parent::teix:egXML[@rend='full']">
431
      <xsl:choose>
432
        <xsl:when test="not(parent::*)">
433
          <xsl:call-template name="nsList"/>
434
        </xsl:when>
435
        <xsl:when test="parent::teix:egXML and not(preceding-sibling::*)">
436
          <xsl:call-template name="nsList"/>
437
        </xsl:when>
438
      </xsl:choose>
439
    </xsl:if>
440
    <xsl:choose>
441
      <xsl:when test="child::node()">
442
        <xsl:text>&gt;</xsl:text>
443
        <xsl:value-of disable-output-escaping="yes" select="$endElement"/>
444
        <xsl:apply-templates mode="verbatim">
445
          <xsl:with-param name="highlight">
446
            <xsl:value-of select="$highlight"/>
447
          </xsl:with-param>
448
        </xsl:apply-templates>
449
        <xsl:choose>
450
          <xsl:when test="child::node()[last()]/self::text() and child::node()[1]/self::text()"/>
451
          <xsl:when test="not(parent::*)  or parent::teix:egXML">
452
            <xsl:call-template name="verbatim-lineBreak">
453
              <xsl:with-param name="id">23</xsl:with-param>
454
            </xsl:call-template>
455
          </xsl:when>
456
          <xsl:when test="child::node()[last()]/self::text()[normalize-space(.)='']">
457
            <xsl:call-template name="verbatim-lineBreak">
458
              <xsl:with-param name="id">3</xsl:with-param>
459
            </xsl:call-template>
460
            <xsl:call-template name="verbatim-makeIndent"/>
461
          </xsl:when>
462
          <xsl:when test="child::node()[last()]/self::comment()">
463
            <xsl:call-template name="verbatim-lineBreak">
464
              <xsl:with-param name="id">4</xsl:with-param>
465
            </xsl:call-template>
466
            <xsl:call-template name="verbatim-makeIndent"/>
467
          </xsl:when>
468
          <xsl:when test="child::node()[last()]/self::*">
469
            <xsl:call-template name="verbatim-lineBreak">
470
              <xsl:with-param name="id">5</xsl:with-param>
471
            </xsl:call-template>
472
            <xsl:call-template name="verbatim-makeIndent"/>
473
          </xsl:when>
474
        </xsl:choose>
475
        <xsl:value-of disable-output-escaping="yes" select="$startElement"/>
476
        <xsl:text>&lt;/</xsl:text>
477
        <xsl:call-template name="verbatim-makeElementName">
478
          <xsl:with-param name="start">false</xsl:with-param>
479
          <xsl:with-param name="highlight">
480
            <xsl:value-of select="$highlight"/>
481
          </xsl:with-param>
482
        </xsl:call-template>
483
        <xsl:text>&gt;</xsl:text>
484
        <xsl:value-of disable-output-escaping="yes" select="$endElement"/>
485
      </xsl:when>
486
      <xsl:otherwise>
487
        <xsl:text>/&gt;</xsl:text>
488
        <xsl:value-of disable-output-escaping="yes" select="$endElement"/>
489
      </xsl:otherwise>
490
    </xsl:choose>
491
  </xsl:template>
492
  <xsl:template name="verbatim-createElement">
493
    <xsl:param name="name"/>
494
    <xsl:param name="special"/>
495
    <xsl:choose>
496
      <xsl:when test="$special='true'">
497
        <xsl:value-of disable-output-escaping="yes" select="$highlightStartElementName"/>
498
        <xsl:value-of select="$name"/>
499
        <xsl:value-of disable-output-escaping="yes" select="$highlightEndElementName"/>
500
      </xsl:when>
501
      <xsl:otherwise>
502
        <xsl:value-of select="$name"/>
503
      </xsl:otherwise>
504
    </xsl:choose>
505
  </xsl:template>
506
  <xsl:template name="verbatim-createAttribute">
507
    <xsl:param name="name"/>
508
    <xsl:value-of select="$name"/>
509
  </xsl:template>
510
  <xsl:template name="verbatim-makeElementName">
511
    <xsl:param name="start"/>
512
    <xsl:param name="highlight"/>
513
    <!-- get namespace prefix -->
514
    <xsl:variable name="ns-prefix">
515
      <xsl:call-template name="verbatim-getNamespacePrefix"/>
516
    </xsl:variable>
517
    <xsl:variable name="highlightMe">
518
      <xsl:choose>
519
        <xsl:when test="$highlight=local-name()">true</xsl:when>
520
        <xsl:otherwise>false</xsl:otherwise>
521
      </xsl:choose>
522
    </xsl:variable>
523
    <xsl:choose>
524
      <xsl:when test="namespace-uri()='http://www.tei-c.org/ns/Examples'">
525
        <xsl:call-template name="verbatim-createElement">
526
          <xsl:with-param name="name" select="local-name(.)"/>
527
          <xsl:with-param name="special">
528
            <xsl:value-of select="$highlightMe"/>
529
          </xsl:with-param>
530
        </xsl:call-template>
531
      </xsl:when>
532
      <xsl:when test="contains($omitNSDecls,namespace-uri())">
533
        <xsl:call-template name="verbatim-createElement">
534
          <xsl:with-param name="name" select="local-name(.)"/>
535
          <xsl:with-param name="special">
536
            <xsl:value-of select="$highlightMe"/>
537
          </xsl:with-param>
538
        </xsl:call-template>
539
      </xsl:when>
540
      <xsl:when test="$useNSPrefixes='true' and string-length($ns-prefix) &gt; 0">
541
        <xsl:call-template name="verbatim-createElement">
542
          <xsl:with-param name="name" select="concat($ns-prefix,':',local-name(.))"/>
543
          <xsl:with-param name="special">
544
            <xsl:value-of select="$highlightMe"/>
545
          </xsl:with-param>
546
        </xsl:call-template>
547
      </xsl:when>
548
      <xsl:when test="not(namespace-uri()='')">
549
        <xsl:call-template name="verbatim-createElement">
550
          <xsl:with-param name="name" select="local-name(.)"/>
551
          <xsl:with-param name="special">
552
            <xsl:value-of select="$highlightMe"/>
553
          </xsl:with-param>
554
        </xsl:call-template>
555
        <xsl:if test="$start='true' and not(namespace-uri()=namespace-uri(..))">
556
          <xsl:text> xmlns="</xsl:text>
557
          <xsl:value-of select="namespace-uri()"/>
558
          <xsl:text>"</xsl:text>
559
          <!-- 
560
	       <xsl:call-template name="verbatim-lineBreak">
561
	       <xsl:with-param name="id">5</xsl:with-param>
562
	       </xsl:call-template>
563
	       <xsl:call-template name="verbatim-makeIndent"/>
564
	  -->
565
        </xsl:if>
566
      </xsl:when>
567
      <xsl:otherwise>
568
        <xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
569
        <xsl:call-template name="verbatim-createElement">
570
          <xsl:with-param name="name" select="local-name(.)"/>
571
          <xsl:with-param name="special">
572
            <xsl:value-of select="$highlightMe"/>
573
          </xsl:with-param>
574
        </xsl:call-template>
575
        <xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
576
      </xsl:otherwise>
577
    </xsl:choose>
578
  </xsl:template>
579
  <xsl:template name="verbatim-makeIndent">
580
    <xsl:variable name="depth" select="count(ancestor::*[not(namespace-uri()='http://www.tei-c.org/ns/1.0')])"/>
581
    <xsl:call-template name="verbatim-makeSpace">
582
      <xsl:with-param name="d">
583
        <xsl:value-of select="$depth"/>
584
      </xsl:with-param>
585
    </xsl:call-template>
586
  </xsl:template>
587
  <xsl:template name="verbatim-makeSpace">
588
    <xsl:param name="d"/>
589
    <xsl:if test="number($d)&gt;1">
590
      <xsl:value-of select="$spaceCharacter"/>
591
      <xsl:call-template name="verbatim-makeSpace">
592
        <xsl:with-param name="d">
593
          <xsl:value-of select="$d -1"/>
594
        </xsl:with-param>
595
      </xsl:call-template>
596
    </xsl:if>
597
  </xsl:template>
598
  <xsl:template match="@*" mode="verbatim">
599
    <xsl:variable name="L">
600
      <xsl:for-each select="../@*">
601
        <xsl:value-of select="."/>
602
      </xsl:for-each>
603
    </xsl:variable>
604
    <xsl:if test="count(../@*)&gt;$attsOnSameLine or      string-length($L)&gt;$attLength or     ancestor::tei:cell[not(@rend='wovenodd-col2')] or     namespace-uri()='http://www.w3.org/2005/11/its' or     string-length(.)+string-length(name(.)) &gt;     $attLength">
605
      <xsl:call-template name="verbatim-lineBreak">
606
        <xsl:with-param name="id">5</xsl:with-param>
607
      </xsl:call-template>
608
      <xsl:call-template name="verbatim-makeIndent"/>
609
    </xsl:if>
610
    <xsl:value-of select="$spaceCharacter"/>
611
    <xsl:variable name="ns-prefix">
612
      <xsl:call-template name="verbatim-getNamespacePrefix"/>
613
    </xsl:variable>
614
    <xsl:variable name="name">
615
      <xsl:choose>
616
        <xsl:when test="string-length($ns-prefix) &gt; 0">
617
          <xsl:value-of select="$ns-prefix"/>
618
          <xsl:text>:</xsl:text>
619
          <xsl:value-of select="local-name(.)"/>
620
        </xsl:when>
621
        <xsl:otherwise>
622
          <xsl:value-of select="local-name(.)"/>
623
        </xsl:otherwise>
624
      </xsl:choose>
625
    </xsl:variable>
626
    <xsl:call-template name="verbatim-createAttribute">
627
      <xsl:with-param name="name" select="$name"/>
628
    </xsl:call-template>
629
    <xsl:text>="</xsl:text>
630
    <xsl:value-of disable-output-escaping="yes" select="$startAttributeValue"/>
631
    <xsl:apply-templates select="." mode="attributetext"/>
632
    <xsl:value-of disable-output-escaping="yes" select="$endAttributeValue"/>
633
    <xsl:text>"</xsl:text>
634
  </xsl:template>
635
  <xsl:template match="@*" mode="attributetext">
636
    <xsl:choose>
637
      <xsl:when test="string-length(.)&gt;$attLength and contains(.,' ')">
638
        <xsl:call-template name="verbatim-reformatText">
639
          <xsl:with-param name="sofar">0</xsl:with-param>
640
          <xsl:with-param name="indent">
641
            <xsl:text> </xsl:text>
642
          </xsl:with-param>
643
          <xsl:with-param name="text">
644
            <xsl:value-of select="normalize-space(.)"/>
645
          </xsl:with-param>
646
        </xsl:call-template>
647
      </xsl:when>
648
      <xsl:otherwise>
649
        <xsl:value-of select="."/>
650
      </xsl:otherwise>
651
    </xsl:choose>
652
  </xsl:template>
653
  <xsl:template match="text()|comment()|processing-instruction()" mode="ns"/>
654
  <xsl:template match="*" mode="ns">
655
    <xsl:for-each select="namespace::*">
656
      <xsl:variable name="ns" select="."/>
657
      <xsl:choose>
658
        <xsl:when test=".='http://relaxng.org/ns/structure/1.0'"/>
659
        <xsl:when test=".='http://www.w3.org/2001/XInclude'"/>
660
        <xsl:when test=".='http://www.tei-c.org/ns/Examples'"/>
661
        <xsl:when test=".='http://www.ascc.net/xml/schematron'"/>
662
        <xsl:when test=".='http://relaxng.org/ns/compatibility/annotations/1.0'"/>
663
        <xsl:when test="name(.)=''"/>
664
        <xsl:when test=".='http://www.w3.org/XML/1998/namespace'"/>
665
        <xsl:otherwise>
666
          <ns name="{name(.)}" value="{.}"/>
667
        </xsl:otherwise>
668
      </xsl:choose>
669
    </xsl:for-each>
670
    <xsl:apply-templates mode="ns"/>
671
  </xsl:template>
672
  <xsl:template name="nsList">
673
    <xsl:variable name="ns">
674
      <all>
675
        <names>
676
          <xsl:apply-templates select="." mode="ns"/>
677
        </names>
678
        <text>
679
          <xsl:copy-of select="."/>
680
        </text>
681
      </all>
682
    </xsl:variable>
683
    <xsl:for-each select="$ns/all/names">
684
      <xsl:for-each-group select="ns" group-by="@name">
685
        <xsl:if test="key('NSUsed',@value)">
686
          <xsl:call-template name="verbatim-lineBreak">
687
            <xsl:with-param name="id">22</xsl:with-param>
688
          </xsl:call-template>
689
          <xsl:text>&#160;&#160;&#160;</xsl:text>
690
          <xsl:text>xmlns:</xsl:text>
691
          <xsl:value-of select="@name"/>
692
          <xsl:text>="</xsl:text>
693
          <xsl:value-of select="@value"/>
694
          <xsl:text>"</xsl:text>
695
        </xsl:if>
696
      </xsl:for-each-group>
697
    </xsl:for-each>
698
  </xsl:template>
699
  <xsl:function name="tei:getPrefix" as="xs:string*">
700
    <xsl:param name="ns"/>
701
    <xsl:param name="here"/>
702
    <xsl:for-each select="in-scope-prefixes($here)">
703
      <xsl:choose>
704
        <xsl:when test=".=''"/>
705
        <xsl:when test="$ns=namespace-uri-for-prefix(.,$here)">
706
          <xsl:value-of select="."/>
707
        </xsl:when>
708
      </xsl:choose>
709
    </xsl:for-each>
710
  </xsl:function>
711
</xsl:stylesheet>