Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / odt / teitoodt.xsl @ 187

History | View | Annotate | Download (62.6 kB)

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet
3
    version="2.0"
4
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
5
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
6
    xmlns:teidocx="http://www.tei-c.org/ns/teidocx/1.0"
7
    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
8
    xmlns:dc="http://purl.org/dc/elements/1.1/"
9
    xmlns:dom="http://www.w3.org/2001/xml-events"
10
    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
11
    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
12
    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
13
    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
14
    xmlns:math="http://www.w3.org/1998/Math/MathML"
15
    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
16
    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
17
    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
18
    xmlns:m="http://www.w3.org/1998/Math/MathML"
19
    xmlns:atom="http://www.w3.org/2005/Atom"  
20
    xmlns:estr="http://exslt.org/strings"
21
    xmlns:xlink="http://www.w3.org/1999/xlink"
22
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
23
    xmlns:dbk="http://docbook.org/ns/docbook"
24
    xmlns:rng="http://relaxng.org/ns/structure/1.0"
25
    xmlns:ooo="http://openoffice.org/2004/office"
26
    xmlns:oooc="http://openoffice.org/2004/calc"
27
    xmlns:ooow="http://openoffice.org/2004/writer"
28
    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
29
    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
30
    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
31
    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
32
    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
33
    xmlns:xforms="http://www.w3.org/2002/xforms"
34
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
35
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
36
    xmlns:tei="http://www.tei-c.org/ns/1.0"
37
    xmlns:teix="http://www.tei-c.org/ns/Examples"
38
    office:version="1.0"
39
    >
40

    
41
  <xsl:import href="../common2/core.xsl"/>
42
  <xsl:param name="useFixedDate">false</xsl:param>
43

    
44
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
45
      <desc>
46
         <p> TEI stylesheet for making OpenOffice files from TEI XML.
47
	 Originally derived from the OpenOffice /Docbook
48
	 conversion, but largely rewritten </p>
49
         <p>This software is dual-licensed:
50

    
51
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
52
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
53

    
54
2. http://www.opensource.org/licenses/BSD-2-Clause
55
		
56
All rights reserved.
57

    
58
Redistribution and use in source and binary forms, with or without
59
modification, are permitted provided that the following conditions are
60
met:
61

    
62
* Redistributions of source code must retain the above copyright
63
notice, this list of conditions and the following disclaimer.
64

    
65
* Redistributions in binary form must reproduce the above copyright
66
notice, this list of conditions and the following disclaimer in the
67
documentation and/or other materials provided with the distribution.
68

    
69
This software is provided by the copyright holders and contributors
70
"as is" and any express or implied warranties, including, but not
71
limited to, the implied warranties of merchantability and fitness for
72
a particular purpose are disclaimed. In no event shall the copyright
73
holder or contributors be liable for any direct, indirect, incidental,
74
special, exemplary, or consequential damages (including, but not
75
limited to, procurement of substitute goods or services; loss of use,
76
data, or profits; or business interruption) however caused and on any
77
theory of liability, whether in contract, strict liability, or tort
78
(including negligence or otherwise) arising in any way out of the use
79
of this software, even if advised of the possibility of such damage.
80
</p>
81
         <p>Author: See AUTHORS</p>
82
         <p>Id: $Id: teitoodt.xsl 10180 2012-03-25 14:48:46Z rahtz $</p>
83
         <p>Copyright: 2008, TEI Consortium</p>
84
      </desc>
85
   </doc>
86
  
87
  <xsl:strip-space elements="teix:* rng:* xsl:* xhtml:* atom:* m:*"/>
88
    <xsl:key name="W" match="image" use="@url"/>
89
    <xsl:key name="H" match="image" use="@url"/>
90

    
91

    
92
  <xsl:output method="xml" omit-xml-declaration="no"/>
93

    
94
  <xsl:decimal-format name="staff" digit="D"/>
95
  <xsl:variable name="doc_type">TEI</xsl:variable>
96
  <xsl:param name="useHeaderFrontMatter">false</xsl:param>
97
  <xsl:param name="postQuote">’</xsl:param>
98
  <xsl:param name="preQuote">‘</xsl:param>
99
  <xsl:param name="outputDir">.</xsl:param>
100
  <xsl:param name="freestanding">false</xsl:param>
101
  <xsl:key name='IDS' match="tei:*[@xml:id]" use="@xml:id"/>
102
  <xsl:key name='GRAPHICS' match="tei:graphic" use="1"/>
103
  <xsl:key name="Page" match="style:page-layout-properties" use="1"/>
104

    
105
  <xsl:template match="/">
106
    <xsl:choose>
107
      <xsl:when test="$freestanding='true'">
108
	<xsl:result-document href="{concat($outputDir,'/meta.xml')}">
109
	  <xsl:call-template name="META"/>
110
	</xsl:result-document>
111
	<office:document-content>
112
	  <xsl:if test="$freestanding='true'">
113
	  <xsl:for-each select="document(concat($outputDir,'/content.xml'))/office:document-content">
114
	    <xsl:copy-of select="office:scripts"/>
115
	    <xsl:copy-of select="office:font-face-decls"/>
116
	    <xsl:copy-of select="office:automatic-styles"/>
117
	  </xsl:for-each>
118
	  </xsl:if>
119
	  <office:body>
120
	    <office:text>
121
	      <xsl:apply-templates/>
122
	    </office:text>
123
	  </office:body>
124
	</office:document-content>
125
      </xsl:when>
126
      <xsl:otherwise>
127
	<office:document>
128
	  <xsl:call-template name="META"/>
129
	  <office:body>
130
	    <office:text>
131
	      <xsl:apply-templates/>
132
	    </office:text>
133
	  </office:body>
134
	</office:document>
135
      </xsl:otherwise>
136
    </xsl:choose>
137
    <xsl:result-document href="{concat($outputDir,'/META-INF/manifest.xml')}">
138
      <manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
139
	<manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.text" manifest:version="1.2" manifest:full-path="/"/>
140
	<manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/statusbar/"/>
141
	<manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/accelerator/current.xml"/>
142
	<manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/accelerator/"/>
143
	<manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/floater/"/>
144
	<manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/popupmenu/"/>
145
	<manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/progressbar/"/>
146
	<manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/menubar/"/>
147
	<manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/toolbar/"/>
148
	<manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/images/Bitmaps/"/>
149
	<manifest:file-entry manifest:media-type="" manifest:full-path="Configurations2/images/"/>
150
	<manifest:file-entry manifest:media-type="application/vnd.sun.xml.ui.configuration" manifest:full-path="Configurations2/"/>
151
	<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/>
152
	<manifest:file-entry manifest:media-type="application/rdf+xml" manifest:full-path="manifest.rdf"/>
153
	<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="styles.xml"/>
154
	<manifest:file-entry manifest:media-type="text/xml" manifest:full-path="meta.xml"/>
155
	<manifest:file-entry manifest:media-type="" manifest:full-path="Thumbnails/thumbnail.png"/>
156
	<manifest:file-entry manifest:media-type="" manifest:full-path="Thumbnails/"/>
157
	<manifest:file-entry manifest:media-type="text/xml"
158
			     manifest:full-path="settings.xml"/>
159
	<xsl:if test="count(key('GRAPHICS',1))&gt;0">
160
	<manifest:file-entry manifest:media-type="" manifest:full-path="Pictures/"/>
161
	<xsl:for-each select="key('GRAPHICS',1)">
162
	  <xsl:variable name="imagetype"
163
			select="tokenize(@url,'\.')[last()]"/>
164
	  <manifest:file-entry>
165
	    <xsl:attribute name="manifest:full-path">
166
	      <xsl:text>Pictures/resource</xsl:text>
167
	      <xsl:number level="any"/>
168
	      <xsl:text>.</xsl:text>
169
	      <xsl:value-of select="$imagetype"/>
170
	    </xsl:attribute>
171
	    <xsl:attribute name="manifest:media-type">
172
	      <xsl:text>image/</xsl:text>
173
	      <xsl:choose>
174
		<xsl:when test="$imagetype='png'">png</xsl:when>
175
		<xsl:when test="$imagetype='gif'">gif</xsl:when>
176
		<xsl:when test="$imagetype='jpg'">jpeg</xsl:when>
177
		<xsl:when test="$imagetype='jpeg'">jpg</xsl:when>
178
		<xsl:when test="$imagetype='tiff'">tiff</xsl:when>
179
		<xsl:when test="$imagetype='tif'">tiff</xsl:when>
180
		<xsl:otherwise>jpeg</xsl:otherwise>
181
	      </xsl:choose>
182
	    </xsl:attribute>
183
	  </manifest:file-entry>
184
	</xsl:for-each>
185
	</xsl:if>
186
      </manifest:manifest>
187
    </xsl:result-document>
188

    
189
  </xsl:template>
190

    
191
  <xsl:template name="META">
192
    <xsl:for-each select="*">
193
    <office:meta>
194
      <meta:generator>TEI to OpenOffice XSLT</meta:generator>
195
      <dc:title>
196
	<xsl:call-template name="generateTitle"/>
197
      </dc:title>
198
      <dc:description/>
199
      <dc:subject/>
200
      <meta:creation-date>
201
	<xsl:call-template name="generateDate"/>
202
      </meta:creation-date>
203
      <dc:date>
204
	<xsl:call-template name="generateRevDate"/>
205
      </dc:date>
206
      <dc:language>
207
	<xsl:choose>
208
	  <xsl:when test="/tei:TEI/@xml:lang">
209
	    <xsl:value-of select="/tei:TEI/@xml:lang"/>
210
	  </xsl:when>
211
	  <xsl:otherwise>en</xsl:otherwise>
212
	</xsl:choose>
213
      </dc:language>
214
      <meta:editing-cycles>1</meta:editing-cycles>
215
      <meta:editing-duration>PT00H00M00S</meta:editing-duration>
216
      <meta:user-defined meta:name="Info 1"/>
217
      <meta:user-defined meta:name="Info 2"/>
218
      <meta:user-defined meta:name="Info 3"/>
219
      <meta:user-defined meta:name="Info 4"/>
220
      <meta:document-statistic meta:table-count="1" meta:image-count="0" meta:object-count="0" meta:page-count="1" meta:paragraph-count="42" meta:word-count="144" meta:character-count="820"/>
221
    </office:meta>
222
    </xsl:for-each>
223
  </xsl:template>
224

    
225
  <!-- base structure -->
226
  <xsl:template match="tei:TEI">
227
    <xsl:apply-templates select="tei:text"/>
228
  </xsl:template>
229

    
230
  <xsl:template match="tei:body|tei:front|tei:back">
231
	<xsl:apply-templates/>
232
  </xsl:template>
233

    
234

    
235
  <xsl:template match="tei:head">
236
    <xsl:choose>
237
      <xsl:when test="parent::tei:figure"/>
238
      <xsl:when test="parent::tei:list"/>
239
      <xsl:when test="parent::tei:div"/>
240
      <xsl:when test="parent::tei:div1"/>
241
      <xsl:when test="parent::tei:div2"/>
242
      <xsl:when test="parent::tei:div3"/>
243
      <xsl:when test="parent::tei:div4"/>
244
      <xsl:when test="parent::tei:div5"/>
245
      <xsl:when test="parent::tei:div6"/>
246
      <xsl:when test="parent::tei:table"/>
247

    
248
      <xsl:otherwise>
249
	<xsl:choose>
250
	  <xsl:when test="parent::tei:appendix">
251
	    <text:p text:style-name="Appendix">
252
	      <xsl:apply-templates/>	   
253
	    </text:p>	
254
	  </xsl:when>
255
	  <xsl:when test="parent::tei:body">
256
	    <text:h text:outline-level="1">
257
	      <xsl:apply-templates/>
258
	    </text:h>
259
	  </xsl:when>
260
	  <xsl:otherwise>
261
	    <text:p>
262
	      <xsl:apply-templates/>	   
263
	    </text:p>
264
	  </xsl:otherwise>
265
	</xsl:choose>
266

    
267
      </xsl:otherwise>
268
    </xsl:choose>
269
  </xsl:template>
270

    
271

    
272

    
273
  <xsl:template match="tei:div">
274
    <xsl:variable name="depth">
275
      <xsl:value-of select="count(ancestor::tei:div)"/>
276
    </xsl:variable>
277
    <text:h>
278
      <xsl:attribute name="text:outline-level">
279
	<xsl:value-of select="$depth + 1"/>
280
      </xsl:attribute>
281
      <xsl:call-template name="test.id"/>
282
      <xsl:apply-templates select="tei:head" mode="show"/>
283
    </text:h>
284
    <xsl:apply-templates/>
285
  </xsl:template>
286

    
287
  <xsl:template match="tei:div1|tei:div2|tei:div3|tei:div4|tei:div5|tei:div6">
288
    <xsl:variable name="depth">
289
      <xsl:value-of select="substring-after(name(.),'div')"/>
290
    </xsl:variable>
291
    <text:h>
292
      <xsl:attribute name="text:outline-level">
293
	<xsl:value-of select="$depth + 1"/>
294
      </xsl:attribute>
295
      <xsl:call-template name="test.id"/>
296
      <xsl:apply-templates select="tei:head" mode="show"/>
297
    </text:h>
298
    <xsl:apply-templates/>
299
  </xsl:template>
300

    
301

    
302

    
303
<!-- paragraphs -->
304
  <xsl:template match="tei:pb">
305
    <text:soft-page-break/>
306
  </xsl:template>
307

    
308
  <xsl:template match="tei:p">
309
    <xsl:variable name="style">
310
      <xsl:choose>
311
	<xsl:when test="ancestor::tei:note[@place='foot']">
312
	    <xsl:text>Footnote</xsl:text>
313
	</xsl:when>
314
	<xsl:otherwise>
315
	  <xsl:text>Text_20_body</xsl:text>
316
	</xsl:otherwise>
317
      </xsl:choose>
318
    </xsl:variable>
319
    <xsl:choose>
320
<!--      
321
     <xsl:when test="tei:pb">
322
	<xsl:for-each-group select="node()" group-adjacent="boolean(self::tei:pb)">
323
	  <xsl:choose>
324
	    <xsl:when test="current-grouping-key()">
325
		<text:p text:style-name="P1"/>
326
	    </xsl:when>
327
	    <xsl:otherwise>
328
	    <text:p text:style-name="{$style}">
329
	      <xsl:call-template name="test.id"/>
330
	      <xsl:apply-templates select="current-group()"/>
331
	    </text:p>
332
	  </xsl:otherwise>  
333
        </xsl:choose>
334
	</xsl:for-each-group>
335
      </xsl:when>
336
-->
337
      <xsl:when test="tei:list">
338
	<xsl:for-each-group select="node()" group-adjacent="boolean(self::tei:list)">
339
	  <xsl:choose>
340
	    <xsl:when test="current-grouping-key()">
341
	      <xsl:apply-templates select="current-group()"/>
342
	    </xsl:when>
343
	    <xsl:otherwise>
344
	    <text:p text:style-name="{$style}">
345
	      <xsl:call-template name="test.id"/>
346
	      <xsl:apply-templates select="current-group()"/>
347
	    </text:p>
348
	  </xsl:otherwise>  
349
        </xsl:choose>
350
	</xsl:for-each-group>
351
      </xsl:when>
352
      <xsl:otherwise>
353
	<text:p text:style-name="{$style}">
354
	  <xsl:call-template name="test.id"/>
355
	  <xsl:apply-templates/>
356
	</text:p>
357
      </xsl:otherwise>  
358
    </xsl:choose>
359
  </xsl:template>
360

    
361

    
362

    
363
<!-- figures -->
364
  <xsl:template match="tei:figure">
365
    <xsl:call-template name="startHook"/>
366
    <text:p text:style-name="Standard">
367
      <xsl:call-template name="test.id"/>
368
      <xsl:apply-templates select="tei:graphic"/>
369
    </text:p>
370
    <xsl:if test="tei:head">
371
      <text:p text:style-name="Caption">
372
	<text:span text:style-name="Figurenum">
373
	  <xsl:text>Figure </xsl:text>
374
	  <text:sequence 
375
	      text:ref-name="refFigure0" 
376
	      text:name="Figure"
377
	      text:formula="Figure+1"
378
	      style:num-format="1">
379
	  <xsl:number level="any"/>
380
	  <xsl:text>.</xsl:text>
381
	  </text:sequence>
382
	</text:span>
383
	<xsl:text> </xsl:text>
384
	<xsl:apply-templates select="tei:head" mode="show"/>
385
      </text:p>
386
    </xsl:if>
387
    <xsl:call-template name="endHook"/>
388

    
389
  </xsl:template>
390

    
391
  <xsl:template match="tei:graphic">
392
    <xsl:variable name="id">
393
      <xsl:choose>
394
	<xsl:when test="@xml:id">
395
	  <xsl:value-of select="@xml:id"/>
396
	</xsl:when>
397
	<xsl:otherwise>
398
	  <xsl:text>Figure</xsl:text><xsl:number level="any"/>
399
	</xsl:otherwise>
400
      </xsl:choose>
401
    </xsl:variable>
402

    
403
	<xsl:variable name="filename">
404
	  <xsl:text>Pictures/resource</xsl:text>
405
	  <xsl:number level="any"/>
406
	  <xsl:text>.</xsl:text>
407
	  <xsl:value-of select="tokenize(@url,'\.')[last()]"/>
408
	</xsl:variable>
409
	<xsl:variable name="origheight">
410
	  <xsl:choose>
411
	    <xsl:when test="@teidocx:height">
412
	      <xsl:value-of select="@teidocx:height"/>
413
	    </xsl:when>
414
	    <xsl:when test="doc-available(concat($outputDir,'/image-size-info.xml'))">
415
		<xsl:for-each select="document(concat($outputDir,'/image-size-info.xml'))">
416
		  <xsl:value-of select="(number(key('H',$filename)/height) div 72) * 9144"/>
417
		</xsl:for-each>
418
	    </xsl:when>
419
	    <xsl:otherwise>0</xsl:otherwise>
420
	  </xsl:choose>
421
	</xsl:variable>
422

    
423
	<xsl:variable name="origwidth">
424
	  <xsl:choose>
425
	    <xsl:when test="@teidocx:width">
426
	      <xsl:value-of select="@teidocx:width"/>
427
	    </xsl:when>
428
	    <xsl:when test="doc-available(concat($outputDir,'/image-size-info.xml'))">
429
		<xsl:for-each select="document(concat($outputDir,'/image-size-info.xml'))">
430
		  <xsl:value-of select="(number(key('W',$filename)/width) div 72) * 9144"/>
431
		</xsl:for-each>
432
	    </xsl:when>
433
	    <xsl:otherwise>0</xsl:otherwise>
434
	  </xsl:choose>
435
	</xsl:variable>
436

    
437
    <xsl:choose>
438
      <xsl:when test="$filename and  ( ($origwidth and $origheight) or (@width and @height))">
439
	
440
	<!-- work out page width / height and subtract 1inch on all sides -->
441
	<xsl:variable name="pageWidth">
442
	  <xsl:for-each
443
	      select="document(concat($outputDir,'/styles.xml'))/office:document-styles/office:automatic-styles/style:page-layout/style:page-layout-properties">
444
	    <xsl:value-of
445
		select="number(tei:convert-dim-pt(@fo:page-width) - 144)"/>
446
	  </xsl:for-each>
447
	</xsl:variable>
448
	<xsl:variable name="pageHeight">
449
	  <xsl:for-each
450
	      select="document(concat($outputDir,'/styles.xml'))/office:document-styles/office:automatic-styles/style:page-layout/style:page-layout-properties">
451
	    <xsl:value-of 
452
		select="number(tei:convert-dim-pt(@fo:page-height) - 144)"/>
453
	  </xsl:for-each>
454
	</xsl:variable>
455
	
456
	<xsl:variable name="Width">
457
	  <xsl:choose>
458
	    <xsl:when test="contains(@width,'%')">
459
	      <xsl:value-of select="(($pageWidth div 100) * number(substring-before(@width,'%'))) cast as xs:integer"/>
460
	    </xsl:when>
461
	    <xsl:when test="@width">
462
	      <xsl:value-of select="tei:convert-dim-pt(@width)"/>
463
	    </xsl:when>
464
	    <xsl:when test="@scale and $origwidth">
465
	      <xsl:value-of select="number($origwidth * number(@scale)) div 127 cast as xs:integer"/>
466
	    </xsl:when>
467
	    <xsl:when test="@height[not(contains(.,'%'))] and $origheight">
468
	      <xsl:variable name="h">
469
		<xsl:value-of select="number(tei:convert-dim-pt(@height))"/>
470
	      </xsl:variable>
471
	      <xsl:value-of select="($h * number($origwidth)) div number($origheight)"/>
472
	    </xsl:when>
473
	    <xsl:when test="$origwidth">
474
	      <xsl:value-of select="number($origwidth) div 127"/>
475
	    </xsl:when>
476
	    <xsl:otherwise>
477
	      <xsl:message terminate="yes">no way to work out image width for
478
	      <xsl:value-of select="$filename"/>
479
	      </xsl:message>
480
	    </xsl:otherwise>
481
	  </xsl:choose>
482
	</xsl:variable>
483
	
484
	<xsl:variable name="Height">
485
	  <xsl:choose>
486
	    <xsl:when test="contains(@height,'%')">
487
	      <xsl:value-of select="(($pageHeight div 100) * (number(substring-before(@height,'%')))) cast as xs:integer"/>
488
	    </xsl:when>
489
	    <xsl:when test="@height">
490
	      <xsl:value-of select="tei:convert-dim-pt(@height)"/>
491
	    </xsl:when>
492
	    <xsl:when test="@scale and $origheight">
493
	      <xsl:value-of select="($origheight *
494
				    number(@scale)) div 127 cast as xs:integer"/>
495
	    </xsl:when>
496
	    <xsl:when test="@width[not(contains(.,'%'))] and $origheight and $origwidth">
497
	      <xsl:variable name="w">
498
		<xsl:value-of select="number(tei:convert-dim-pt(@width))"/>
499
	      </xsl:variable>
500
	      <xsl:value-of select="($w * number($origheight)) div number($origwidth)"/>
501
	    </xsl:when>
502
	    <xsl:when test="$origheight">
503
	      <xsl:value-of select="number($origheight) div 127"/>
504
	    </xsl:when>
505
	    <xsl:otherwise>
506
	      <xsl:message terminate="yes">no way to work out image height for
507
	      <xsl:value-of select="$filename"/>
508
	      </xsl:message>
509
	    </xsl:otherwise>
510
	  </xsl:choose>
511
	</xsl:variable>
512
	
513
	<!-- check for sense -->
514
	<xsl:variable name="imageHeight">
515
	  <xsl:choose>
516
	    <xsl:when test="$Height &lt; 0">
517
	      <xsl:value-of select="$pageHeight"/>
518
	    </xsl:when>
519
	    <xsl:when test="number($Height) &gt; $pageHeight">
520
	      <xsl:value-of select="$pageHeight"/>
521
	    </xsl:when>
522
	    <xsl:otherwise>
523
	      <xsl:value-of select="$Height"/>
524
	    </xsl:otherwise>
525
	  </xsl:choose>
526
	</xsl:variable>
527
	<xsl:variable name="imageWidth">
528
	  <xsl:choose>
529
	    <xsl:when test="$Width &lt; 0">
530
	      <xsl:value-of select="$pageWidth"/>
531
	    </xsl:when>
532
	    <xsl:when test="number($Width) &gt; $pageWidth">
533
	      <xsl:value-of select="$pageWidth"/>
534
	    </xsl:when>
535
	    <xsl:otherwise>
536
	      <xsl:value-of select="$Width"/>
537
	    </xsl:otherwise>
538
	  </xsl:choose>
539
	</xsl:variable>
540
<!--
541
<xsl:message>
542
  <xsl:for-each select="@*">
543
    - @<xsl:value-of select="name(.)"/>: <xsl:value-of select="."/>
544
</xsl:for-each>
545
    - pageWidth: <xsl:value-of select="$pageWidth"/>
546
    - pageHeight: <xsl:value-of select="$pageHeight"/>
547
    - Width: <xsl:value-of select="$Width"/>
548
    - Height: <xsl:value-of select="$Height"/>
549
    - imageWidth: <xsl:value-of select="$imageWidth"/>
550
    - imageHeight: <xsl:value-of select="$imageHeight"/>
551
</xsl:message>
552
-->
553
	<draw:frame draw:style-name="fr1" 
554
		    draw:name="{$id}"
555
		    draw:z-index="0">
556
	  <xsl:attribute name="text:anchor-type">
557
	    <xsl:choose>
558
	      <xsl:when test="parent::tei:figure">
559
		<xsl:text>paragraph</xsl:text>
560
	      </xsl:when>
561
	      <xsl:otherwise>
562
		<xsl:text>as-char</xsl:text>
563
	      </xsl:otherwise>
564
	    </xsl:choose>
565
	  </xsl:attribute>
566
	  
567
	  <xsl:attribute name="svg:width">
568
	    <xsl:value-of select="$imageWidth"/>
569
	    <xsl:text>pt</xsl:text>
570
	  </xsl:attribute>
571
	  <xsl:attribute name="svg:height">
572
	    <xsl:value-of select="$imageHeight"/>
573
	    <xsl:text>pt</xsl:text>
574
	  </xsl:attribute>
575
	  <draw:image
576
	      xlink:href="{$filename}" 
577
	      xlink:type="simple" 
578
	      xlink:show="embed"
579
	      xlink:actuate="onLoad" 
580
	      draw:filter-name="&lt;All formats&gt;"/>
581
	</draw:frame>
582
      </xsl:when>	
583
      <xsl:otherwise>
584
	<xsl:message terminate="yes">ERROR. no image size info for  <xsl:value-of select="$filename"/>, cannot proceed</xsl:message>
585
	
586
      </xsl:otherwise>
587
    </xsl:choose>
588
    
589
  </xsl:template>
590

    
591

    
592
<!-- lists -->
593
  <xsl:template match="tei:list|tei:listBibl">
594
    <xsl:if test="tei:head">
595
      <text:p>
596
	<xsl:attribute name="text:style-name">
597
	  <xsl:choose>
598
	    <xsl:when  test="@type='ordered'">P2</xsl:when>
599
	    <xsl:otherwise>P1</xsl:otherwise>
600
	  </xsl:choose>
601
      </xsl:attribute>
602
      <xsl:apply-templates select="tei:head" mode="show"/>
603
      </text:p>
604
    </xsl:if>
605
    <text:list>
606
      <xsl:attribute name="text:style-name">
607
	<xsl:choose>
608
	    <xsl:when test="self::tei:listBibl">L2</xsl:when>
609
            <xsl:when test="not(@type)">L1</xsl:when>
610
            <xsl:when test="@type='ordered'">L2</xsl:when>
611
            <xsl:when test="@type='unordered'">L1</xsl:when>
612
	</xsl:choose>
613
      </xsl:attribute>
614
      <xsl:apply-templates/>
615
    </text:list>
616
  </xsl:template>
617

    
618

    
619

    
620
  <xsl:template match="tei:list[@type='gloss' or @rend='valList']" priority="10">
621
    <xsl:apply-templates/>
622
  </xsl:template>
623

    
624
  <xsl:template match="tei:list[@type='gloss' or @rend='valList']/tei:item">
625
    <text:p text:style-name="List_20_Contents">
626
      <xsl:apply-templates/>
627
    </text:p>
628
  </xsl:template>
629

    
630
  <xsl:template match="tei:list[@type='gloss' or @rend='valList']/tei:label">
631
    <text:p text:style-name="List_20_Heading">
632
      <xsl:apply-templates/>
633
    </text:p>
634
  </xsl:template>
635

    
636
  <xsl:template match="tei:item/tei:p">
637
    <xsl:apply-templates/>
638
  </xsl:template>
639

    
640
  <xsl:template match="tei:item">
641
    <text:list-item>
642
      <xsl:choose>
643
	<xsl:when test="tei:list">
644
	  <xsl:apply-templates/>
645
	</xsl:when>
646
	<xsl:otherwise>
647
	  <text:p>
648
	    <xsl:attribute name="text:style-name">
649
	      <xsl:choose>
650
		<xsl:when  test="parent::tei:list/@type='ordered'">P2</xsl:when>
651
		<xsl:otherwise>P1</xsl:otherwise>
652
	      </xsl:choose>
653
	    </xsl:attribute>
654
	    <xsl:apply-templates/>
655
	  </text:p>
656
	</xsl:otherwise>
657
      </xsl:choose>
658
    </text:list-item>
659
  </xsl:template>
660

    
661
<!-- inline stuff -->
662
  <xsl:template match="tei:emph">
663
    <text:span text:style-name="Emphasis">
664
      <xsl:apply-templates/>
665
    </text:span>
666
  </xsl:template>
667

    
668
  <xsl:template  match="tei:gi">
669
    <xsl:text>&lt;</xsl:text>
670
    <xsl:apply-templates/>
671
    <xsl:text>&gt;</xsl:text>
672
  </xsl:template>
673

    
674
  <xsl:template  match="tei:caesura">
675
    <xsl:text>&#160;&#160;&#160;</xsl:text>
676
  </xsl:template>
677

    
678
  <xsl:template match="tei:q">
679
    <text:span text:style-name="q">
680
      <xsl:text>&#x2018;</xsl:text>
681
      <xsl:apply-templates/>
682
      <xsl:text>&#x2019;</xsl:text>
683
    </text:span>
684
  </xsl:template>
685

    
686

    
687
  <xsl:template match="tei:note">
688
    <text:note text:note-class="footnote">
689
    <text:note-citation>
690
      <xsl:number level="any" count="tei:note[@place='foot']"/>
691
    </text:note-citation>
692
      <text:note-body>
693
	<text:p text:style-name="Footnote">
694
	  <xsl:apply-templates/>
695
	</text:p>
696
      </text:note-body>
697
    </text:note>  
698
  </xsl:template>
699

    
700
  <xsl:template match="tei:note[@place='end']">
701
    <text:note text:note-class="endnote">
702
    <text:note-citation>
703
      <xsl:number format="i" level="any" count="tei:note[@place='end']"/>
704
    </text:note-citation>
705
      <text:note-body>
706
	<text:p text:style-name="Endnote">
707
	  <xsl:apply-templates/>
708
	</text:p>
709
      </text:note-body>
710
    </text:note>
711
  </xsl:template>
712

    
713

    
714
  <xsl:template match="tei:ref">
715
    <text:a xlink:type="simple" xlink:href="{@target}">
716
      <xsl:apply-templates/>
717
    </text:a>
718
  </xsl:template>
719

    
720
  <xsl:template match="tei:ptr">
721
    <text:a xlink:type="simple" xlink:href="{@target}">
722
      <xsl:choose>
723
	<xsl:when test="starts-with(@target,'#')">
724
	  <xsl:for-each select="id(substring(@target,2))">
725
	    <xsl:apply-templates select="." mode="crossref"/>
726
	  </xsl:for-each>
727
	</xsl:when>
728
	<xsl:otherwise>
729
	  <xsl:value-of select="@target"/>
730
	</xsl:otherwise>
731
      </xsl:choose>
732
    </text:a>
733
  </xsl:template>
734

    
735
  <xsl:template match="tei:table|tei:figure|tei:item" mode="crossref">
736
    <xsl:number level="any"/>
737
  </xsl:template>
738

    
739
  <xsl:template match="tei:div" mode="crossref">
740
    <xsl:number format="1.1.1.1.1"
741
		level="multiple" 
742
		count="tei:div"/>
743
  </xsl:template>
744

    
745
  <xsl:template
746
      match="tei:div1|tei:div2|tei:div3|tei:div4|tei:div5|tei:div6" 
747
      mode="crossref">
748
    <xsl:number format="1.1.1.1.1"
749
        count="tei:div1|tei:div2|tei:div3|tei:div4|tei:div5|tei:div6"
750
        level="multiple"/>
751
  </xsl:template>
752

    
753
  <xsl:template name="test.id">
754
    <xsl:if test="@xml:id">
755
      <text:bookmark text:name="{@xml:id}"/>
756
    </xsl:if>
757
  </xsl:template>
758

    
759
  <xsl:template match="tei:unclear">
760
    <text:span text:style-name="Highlight">
761
      <xsl:apply-templates/>
762
    </text:span>
763
  </xsl:template>
764

    
765
  <xsl:template match="tei:hi">
766
    <text:span>
767
      <xsl:attribute name="text:style-name">
768
	<xsl:choose>
769
	  <xsl:when test="@rend='normalweight'">
770
	    <xsl:text>Standard</xsl:text>
771
	  </xsl:when>
772
	  <xsl:when test="@rend='code' or @rend='typewriter'">
773
	    <xsl:text>Source_20_Text</xsl:text>
774
	  </xsl:when>
775
	  <xsl:when test="@rend='sup' or @rend='superscript'">
776
	    <xsl:text>Superscript</xsl:text>
777
	  </xsl:when>
778
	  <xsl:when test="@rend='sub' or @rend='subscript'">
779
	    <xsl:text>Subscript</xsl:text>
780
	  </xsl:when>
781
	  <xsl:when test="@rend='bold'">
782
	    <xsl:text>Highlight</xsl:text>
783
	  </xsl:when>
784
	  <xsl:when test="@rend='label'">
785
	    <xsl:text>Highlight</xsl:text>
786
	  </xsl:when>
787
	  <xsl:when test="@rend='it' or @rend='i' or @rend='italic'">
788
	    <xsl:text>Emphasis</xsl:text>
789
	  </xsl:when>
790
	  <xsl:when test="@rend='underline'">
791
	    <xsl:text>Underline</xsl:text>
792
	  </xsl:when>
793
	  <xsl:when test="@rend='sc' or @rend='smallcaps'">
794
	    <xsl:text>SmallCaps</xsl:text>
795
	  </xsl:when>
796
	  <xsl:when test="@rend='sc' or @rend='capsall'">
797
	    <xsl:text>AllCaps</xsl:text>
798
	  </xsl:when>
799
	  <xsl:when test="@rend='strikethrough'">
800
	    <xsl:text>StrikeThrough</xsl:text>
801
	  </xsl:when>
802
	  <xsl:when test="@rend='strikedoublethrough'">
803
	    <xsl:text>StrikeDoubleThrough</xsl:text>
804
	  </xsl:when>
805
	  <xsl:when test="@rend='underline'">
806
	    <xsl:text>UnderLine</xsl:text>
807
	  </xsl:when>
808
	  <xsl:when test="@rend='underdoubleline'">
809
	    <xsl:text>UnderDoubleLine</xsl:text>
810
	  </xsl:when>
811
	  <xsl:otherwise>
812
	    <xsl:text>Emphasis</xsl:text>
813
	  </xsl:otherwise>
814
	</xsl:choose>
815
      </xsl:attribute>
816
      <xsl:apply-templates/>
817
    </text:span>
818
  </xsl:template>
819

    
820
  <xsl:template match="tei:term">
821
    <text:span>
822
      <xsl:attribute name="text:style-name">
823
	<xsl:text>Highlight</xsl:text>
824
      </xsl:attribute>
825
      <xsl:apply-templates/>
826
    </text:span>
827
</xsl:template>
828

    
829
  <xsl:template match="tei:index"/>
830

    
831
  <xsl:template match="tei:eg">
832
    <xsl:call-template name="startHook"/>
833
    <xsl:call-template name="Literal">
834
      <xsl:with-param name="Text">
835
	<xsl:value-of select="."/>
836
      </xsl:with-param>
837
    </xsl:call-template>
838
    <xsl:call-template name="endHook"/>
839
  </xsl:template>
840

    
841
  <xsl:template match="teix:egXML">
842
    <xsl:call-template name="startHook"/>
843
    <xsl:call-template name="Literal">
844
      <xsl:with-param name="Text">
845
	<xsl:apply-templates mode="verbatim"/>
846
      </xsl:with-param>
847
    </xsl:call-template>
848
    <xsl:call-template name="endHook"/>
849
  </xsl:template>
850

    
851
  <!-- safest to drop comments entirely, I think -->
852
  <xsl:template match="comment()"/>
853

    
854
  <xsl:template match="tei:head" mode="show">
855
    <xsl:apply-templates/>
856
  </xsl:template>
857

    
858
  <xsl:template match="tei:lb">
859
    <text:line-break/>
860
  </xsl:template>
861

    
862
  <xsl:template match="tei:biblStruct">
863
    <text:list-item>
864
      <text:p text:style-name="P2">
865
	<xsl:apply-templates/>
866
      </text:p>
867
    </text:list-item>
868
  </xsl:template>
869

    
870
  <xsl:template match="tei:bibl|tei:signed|tei:docTitle|tei:byline|tei:docImprint">
871
    <text:p text:style-name="tei_{local-name(.)}">
872
      <xsl:apply-templates/>
873
    </text:p>
874
  </xsl:template>
875

    
876
  <xsl:template match="tei:lg">
877
    <text:p text:style-name="lg">
878
      <xsl:apply-templates/>
879
    </text:p>
880
  </xsl:template>
881

    
882
  <xsl:template match="tei:l">
883
    <xsl:choose>
884
      <xsl:when test="parent::tei:q">
885
	<xsl:apply-templates/>
886
	<text:line-break/>
887
      </xsl:when>
888
      <xsl:when test="parent::tei:lg">
889
	<xsl:apply-templates/>
890
	<text:line-break/>
891
      </xsl:when>
892
      <xsl:otherwise>
893
	<text:p text:style-name="lg">
894
	  <xsl:apply-templates/>
895
	</text:p>
896
      </xsl:otherwise>
897
    </xsl:choose>
898
  </xsl:template>
899

    
900
  <xsl:template name="Literal">
901
    <xsl:param name="Text"/>
902
    <xsl:choose>
903
      <xsl:when test="contains($Text,'&#10;')">
904
	<text:p text:style-name="Preformatted_20_Text">
905
	  <xsl:value-of
906
	      select="translate(substring-before($Text,'&#10;'),' ','&#160;')"/>
907
	</text:p>
908
	<xsl:call-template name="Literal">
909
	  <xsl:with-param name="Text">
910
	    <xsl:value-of select="substring-after($Text,'&#10;')"/>
911
	  </xsl:with-param>
912
	</xsl:call-template>
913
      </xsl:when>
914
      <xsl:otherwise>
915
	<text:p text:style-name="Preformatted_20_Text">
916
	  <xsl:value-of select="translate($Text,' ','&#160;')"/>
917
	</text:p>
918
      </xsl:otherwise>
919
    </xsl:choose>
920
    <!-- text:s c="6" to ident 6 spaces -->
921
  </xsl:template>
922

    
923

    
924
  <xsl:template match="tei:sp">
925
    <xsl:apply-templates/>
926
  </xsl:template>
927

    
928
  <xsl:template match="tei:stage">
929
    <xsl:choose>
930
      <xsl:when test="parent::tei:sp">
931
	<text:p text:style-name="Stage">
932
	  <xsl:apply-templates/>
933
	</text:p>
934
      </xsl:when>
935
      <xsl:otherwise>
936
	<text:span text:style-name="Stage">
937
	  <xsl:apply-templates/>
938
	</text:span>
939
      </xsl:otherwise>
940
    </xsl:choose>
941
  </xsl:template>
942

    
943
  <xsl:template match="tei:speaker">
944
      <text:p text:style-name="Speaker">
945
	<xsl:apply-templates/>
946
      </text:p>
947
  </xsl:template>
948

    
949
  <!-- tables-->
950

    
951
  <xsl:template match="tei:table">
952
    <xsl:call-template name="startHook"/>
953
    <xsl:variable name="tablenum">
954
      <xsl:choose>
955
	<xsl:when test="@xml:id"><xsl:value-of select="@xml:id"/></xsl:when>
956
	<xsl:otherwise>table<xsl:number level="any"/></xsl:otherwise>
957
      </xsl:choose>
958
    </xsl:variable>
959
    <table:table
960
	table:name="{$tablenum}"
961
	table:style-name="Table1">
962
      <xsl:for-each select="1 to max(for $i in tei:row return count($i/tei:cell))">
963
	<table:table-column
964
	    table:style-name="Table{.}.col{.}">
965
	</table:table-column>
966
      </xsl:for-each>
967
      <xsl:apply-templates/>
968
    </table:table>
969
    <xsl:if test="tei:head">
970
      <text:p text:style-name="Caption">
971
	<xsl:apply-templates select="tei:head" mode="show"/>
972
      </text:p>
973
    </xsl:if>
974
    <xsl:call-template name="endHook"/>
975
  </xsl:template>
976

    
977

    
978
  <xsl:template match="tei:row[@role='label']">
979
    <table:table-header-rows>
980
      <table:table-row>
981
	<xsl:apply-templates/>
982
      </table:table-row>
983
    </table:table-header-rows>
984
  </xsl:template>
985

    
986

    
987
  <xsl:template match="tei:row">
988
    <table:table-row>
989
      <xsl:apply-templates/>
990
    </table:table-row>
991
  </xsl:template>
992

    
993

    
994

    
995
  <xsl:template match="tei:seg">
996
    <text:span>
997
      <xsl:apply-templates/>
998
    </text:span>
999
  </xsl:template>
1000

    
1001
  <xsl:template match="tei:seg[@rend='parent']">
1002
      <xsl:apply-templates/>
1003
  </xsl:template>
1004

    
1005
  <xsl:template match="tei:ident">
1006
    <text:span>
1007
      <xsl:apply-templates/>
1008
    </text:span>
1009
  </xsl:template>
1010

    
1011
  <xsl:template match="tei:cit[@rend='display' or not(@rend)]">
1012
    <text:p text:style-name="tei_cit">
1013
      <xsl:apply-templates/>
1014
    </text:p>
1015
  </xsl:template>
1016

    
1017
  <xsl:template match="tei:mentioned">
1018
    <text:span>
1019
      <xsl:apply-templates/>
1020
    </text:span>
1021
  </xsl:template>
1022

    
1023
  <xsl:template match="tei:code">
1024
    <text:span text:style-name="User_20_Entry">
1025
      <xsl:apply-templates/>
1026
    </text:span>
1027
  </xsl:template>
1028

    
1029
  <xsl:template match="tei:cell">
1030
    <table:table-cell>
1031
      <xsl:if test="@cols">
1032
	<xsl:attribute name="table:number-columns-spanned"
1033
		       select="@cols"/>
1034
      </xsl:if>
1035
      <xsl:if test="@rows">
1036
	<xsl:attribute name="table:number-rows-spanned"
1037
		       select="@rows"/>
1038
      </xsl:if>
1039
      <xsl:variable name="cellContents">
1040
	<xsl:apply-templates/>
1041
      </xsl:variable>
1042
      <xsl:for-each-group select="$cellContents/node()"			  
1043
			  group-adjacent="if (self::draw:frame or self::text:span or self::text() or self::text:a)
1044
					  then 1
1045
					  else 2">      
1046
      <xsl:choose>
1047
	<xsl:when test="current-grouping-key()=1">
1048
	    <text:p>
1049
	      <xsl:copy-of select="current-group()"/>
1050
	    </text:p>
1051
	  </xsl:when>
1052
	  <xsl:otherwise>
1053
	    <xsl:copy-of select="current-group()"/>
1054
	  </xsl:otherwise>
1055
	</xsl:choose>
1056
      </xsl:for-each-group>
1057
    </table:table-cell>
1058
    <xsl:if test="@cols">
1059
      <xsl:for-each select="2 to @cols">
1060
	<table:covered-table-cell/>
1061
      </xsl:for-each>
1062
    </xsl:if>
1063
  </xsl:template>
1064

    
1065
  <xsl:param name="startComment"></xsl:param>
1066
  <xsl:param name="endComment"></xsl:param>
1067
  <xsl:param name="startElement"></xsl:param>
1068
  <xsl:param name="endElement"></xsl:param>
1069
  <xsl:param name="startElementName"></xsl:param>
1070
  <xsl:param name="endElementName"></xsl:param>
1071
  <xsl:param name="startAttribute"></xsl:param>
1072
  <xsl:param name="endAttribute"></xsl:param>
1073
  <xsl:param name="startAttributeValue"></xsl:param>
1074
  <xsl:param name="endAttributeValue"></xsl:param>
1075
  <xsl:param name="startNamespace"></xsl:param>
1076
  <xsl:param name="endNamespace"></xsl:param>
1077

    
1078
  <xsl:param name="spaceCharacter">&#160;</xsl:param>
1079
  <xsl:param name="showNamespaceDecls">true</xsl:param>
1080

    
1081
  <xsl:param name="wrapLength">65</xsl:param>
1082

    
1083
  <xsl:param name="attsOnSameLine">3</xsl:param>
1084
  <xsl:key name="Namespaces" match="*[ancestor::teix:egXML]" use="namespace-uri()"/>
1085

    
1086
  <xsl:key name="Namespaces" match="*[not(ancestor::*)]" use="namespace-uri()"/>
1087

    
1088

    
1089
  <xsl:template name="newLine">&#10;</xsl:template>
1090

    
1091
  <xsl:template name="lineBreak">
1092
    <xsl:param name="id"/>
1093
    <xsl:text>&#10;</xsl:text>
1094
  </xsl:template>
1095

    
1096
  <xsl:template match="comment()" mode="verbatim">
1097
    <xsl:choose>
1098
      <xsl:when test="ancestor::Wrapper"/>
1099
      <xsl:when test="ancestor::xhtml:Wrapper"/>
1100
      <xsl:otherwise>
1101
    <xsl:call-template name="lineBreak">
1102
      <xsl:with-param name="id">21</xsl:with-param>
1103
    </xsl:call-template>
1104
    <xsl:value-of  disable-output-escaping="yes" select="$startComment"/>
1105
    <xsl:text>&lt;!--</xsl:text>
1106
    <xsl:value-of select="."/>
1107
    <xsl:text>--&gt;</xsl:text>
1108
    <xsl:value-of  disable-output-escaping="yes"
1109
		   select="$endComment"/>
1110
      </xsl:otherwise>
1111
    </xsl:choose>
1112
  </xsl:template>
1113

    
1114
  <xsl:template match="text()" mode="verbatim">
1115
    <xsl:choose>
1116
      <xsl:when test="not(preceding-sibling::node() or contains(.,'&#10;'))">
1117
	<xsl:call-template name="Text">
1118
	  <xsl:with-param name="words">
1119
	    <xsl:value-of select="."/>
1120
	  </xsl:with-param>
1121
	</xsl:call-template>
1122
<!--	
1123
        <xsl:if test="substring(.,string-length(.))=' '">
1124
	  <xsl:text> </xsl:text>
1125
	</xsl:if>
1126
-->
1127
      </xsl:when>
1128
      <xsl:when test="normalize-space(.)=''">
1129
        <xsl:for-each select="following-sibling::*[1]">
1130
          <xsl:call-template name="lineBreak">
1131
            <xsl:with-param name="id">7</xsl:with-param>
1132
          </xsl:call-template>
1133
          <xsl:call-template name="makeIndent"/>
1134
        </xsl:for-each>
1135
      </xsl:when>
1136
      <xsl:otherwise>
1137
<!--
1138
	<xsl:if test="starts-with(.,' ')">
1139
	  <xsl:text> </xsl:text>
1140
	</xsl:if>
1141
-->
1142
        <xsl:call-template name="wraptext">
1143
          <xsl:with-param name="count">0</xsl:with-param>
1144
          <xsl:with-param name="indent">
1145
            <xsl:for-each select="parent::*">
1146
              <xsl:call-template name="makeIndent"/>
1147
            </xsl:for-each>
1148
          </xsl:with-param>
1149
          <xsl:with-param name="text">
1150
	    <xsl:choose>
1151
	      <xsl:when test="starts-with(.,'&#10;') and not
1152
			      (preceding-sibling::node())">
1153
		<xsl:call-template name="Text">
1154
		  <xsl:with-param name="words">
1155
		    <xsl:value-of select="substring(.,2)"/>
1156
		  </xsl:with-param>
1157
		</xsl:call-template>
1158
		
1159
	      </xsl:when>
1160
	      <xsl:otherwise>
1161
		<xsl:call-template name="Text">
1162
		  <xsl:with-param name="words">
1163
		    <xsl:value-of select="."/>
1164
		  </xsl:with-param>
1165
		</xsl:call-template>
1166
	      </xsl:otherwise>
1167
	    </xsl:choose>
1168
          </xsl:with-param>
1169
        </xsl:call-template>
1170
	<!--
1171
	<xsl:if test="substring(.,string-length(.))=' '">
1172
	  <xsl:text> </xsl:text>
1173
	</xsl:if>
1174
	-->
1175
      </xsl:otherwise>
1176
    </xsl:choose>
1177
  </xsl:template>
1178

    
1179
  <xsl:template name="wraptext">
1180
    <xsl:param name="indent"/>
1181
    <xsl:param name="text"/>
1182
    <xsl:param name="count">0</xsl:param>
1183
    <xsl:choose>
1184
      <xsl:when test="normalize-space($text)=''"/>
1185
      <xsl:when test="contains($text,'&#10;')">
1186
	<xsl:if test="$count &gt; 0">
1187
	  <xsl:value-of select="$indent"/>
1188
	  <xsl:text> </xsl:text>
1189
	</xsl:if>
1190
	<xsl:call-template name="Text">
1191
	  <xsl:with-param name="words">
1192
	    <xsl:value-of
1193
		select="substring-before($text,'&#10;')"/>
1194
	  </xsl:with-param>
1195
	</xsl:call-template>
1196
<!--	<xsl:if test="not(substring-after($text,'&#10;')='')">-->
1197
	  <xsl:call-template name="lineBreak">
1198
	    <xsl:with-param name="id">6</xsl:with-param>
1199
	  </xsl:call-template>
1200
	  <xsl:value-of select="$indent"/>
1201
	  <xsl:call-template name="wraptext">
1202
	    <xsl:with-param name="indent">
1203
	      <xsl:value-of select="$indent"/>
1204
	    </xsl:with-param>
1205
	    <xsl:with-param name="text">
1206
	      <xsl:value-of select="substring-after($text,'&#10;')"/>
1207
	    </xsl:with-param>
1208
	    <xsl:with-param name="count">
1209
	      <xsl:value-of select="$count + 1"/>
1210
	    </xsl:with-param>
1211
	  </xsl:call-template>
1212

    
1213
      </xsl:when>
1214
      <xsl:otherwise>
1215
	<xsl:if test="$count &gt; 0 and parent::*">
1216
	  <xsl:value-of select="$indent"/>
1217
	  <xsl:text> </xsl:text>
1218
	</xsl:if>
1219
	<xsl:call-template name="Text">
1220
	  <xsl:with-param name="words">
1221
	    <xsl:value-of select="$text"/>
1222
	  </xsl:with-param>
1223
	</xsl:call-template>
1224
      </xsl:otherwise>
1225
    </xsl:choose>
1226
  </xsl:template>
1227

    
1228
  <xsl:template name="Text">
1229
    <xsl:param name="words"/>
1230
    <xsl:choose>
1231
      <xsl:when test="contains($words,'&amp;')">
1232
	<xsl:value-of
1233
	    select="substring-before($words,'&amp;')"/>
1234
	<xsl:text>&amp;amp;</xsl:text>
1235
	<xsl:call-template name="Text">
1236
	  <xsl:with-param name="words">
1237
	    <xsl:value-of select="substring-after($words,'&amp;')"/>
1238
	  </xsl:with-param>
1239
	</xsl:call-template>
1240
      </xsl:when>
1241
      <xsl:otherwise>
1242
	<xsl:value-of select="$words"/>
1243
      </xsl:otherwise>
1244
    </xsl:choose>
1245
  </xsl:template>
1246

    
1247
  <xsl:template match="*" mode="verbatim">
1248
    <xsl:choose>
1249
      <xsl:when test="parent::xhtml:Wrapper"/>
1250
<!--      <xsl:when test="child::node()[last()]/self::text()[not(.='')] and child::node()[1]/self::text()[not(.='')]"/>-->
1251
      <xsl:when test="not(parent::*)  or parent::teix:egXML">
1252
	<xsl:choose>
1253
	  <xsl:when test="preceding-sibling::node()[1][self::text()]
1254
			  and following-sibling::node()[1][self::text()]"/>
1255
	  <xsl:when test="preceding-sibling::*">
1256
	    <xsl:call-template name="lineBreak">
1257
	      <xsl:with-param name="id">-1</xsl:with-param>
1258
	    </xsl:call-template>
1259
	  </xsl:when>
1260
	  <xsl:otherwise>
1261
	    <xsl:call-template name="newLine"/>
1262
        <!-- <xsl:call-template name="makeIndent"/>-->
1263
	  </xsl:otherwise>
1264
	</xsl:choose>
1265
      </xsl:when>
1266
      <xsl:when test="not(preceding-sibling::node())">
1267
	<xsl:call-template name="lineBreak">
1268
          <xsl:with-param name="id">-2</xsl:with-param>
1269
	</xsl:call-template>
1270
        <xsl:call-template name="makeIndent"/>
1271
      </xsl:when>
1272
      <xsl:when test="preceding-sibling::node()[1]/self::*">
1273
        <xsl:call-template name="lineBreak">
1274
          <xsl:with-param name="id">1</xsl:with-param>
1275
        </xsl:call-template>
1276
        <xsl:call-template name="makeIndent"/>
1277
      </xsl:when>
1278
      <xsl:when test="preceding-sibling::node()[1]/self::text()">
1279
	</xsl:when>
1280
      <xsl:otherwise>
1281
        <xsl:call-template name="lineBreak">
1282
          <xsl:with-param name="id">9</xsl:with-param>
1283
        </xsl:call-template>
1284
        <xsl:call-template name="makeIndent"/>
1285
      </xsl:otherwise>
1286
    </xsl:choose>
1287

    
1288
    <xsl:value-of disable-output-escaping="yes" select="$startElement"/>
1289
    <xsl:text>&lt;</xsl:text>
1290
    <xsl:call-template name="makeElementName">
1291
      <xsl:with-param name="start">true</xsl:with-param>
1292
    </xsl:call-template>
1293
    <xsl:apply-templates select="@*" mode="verbatim"/>
1294
    <xsl:if test="$showNamespaceDecls='true' or parent::teix:egXML[@rend='full']">
1295
      <xsl:choose>
1296
      <xsl:when test="not(parent::*)">
1297
	<xsl:apply-templates select="." mode="ns"/>
1298
      </xsl:when>
1299
      <xsl:when test="parent::teix:egXML and not(preceding-sibling::*)">
1300
	<xsl:apply-templates select="." mode="ns"/>
1301
      </xsl:when>
1302
      </xsl:choose>
1303
    </xsl:if>
1304

    
1305
    <xsl:choose>
1306
      <xsl:when test="child::node()">
1307
        <xsl:text>&gt;</xsl:text>
1308
        <xsl:value-of disable-output-escaping="yes" select="$endElement"/>
1309
        <xsl:apply-templates mode="verbatim"/>
1310
        <xsl:choose>
1311
          <xsl:when test="child::node()[last()]/self::text() and child::node()[1]/self::text()"/>
1312

    
1313
	  <xsl:when test="not(parent::*)  or parent::teix:egXML">
1314
            <xsl:call-template name="lineBreak">
1315
              <xsl:with-param name="id">23</xsl:with-param>
1316
            </xsl:call-template>
1317
	  </xsl:when>
1318
          <xsl:when test="child::node()[last()]/self::text()[normalize-space(.)='']">
1319
            <xsl:call-template name="lineBreak">
1320
              <xsl:with-param name="id">3</xsl:with-param>
1321
            </xsl:call-template>
1322
            <xsl:call-template name="makeIndent"/>
1323
          </xsl:when>
1324
          <xsl:when test="child::node()[last()]/self::comment()">
1325
            <xsl:call-template name="lineBreak">
1326
              <xsl:with-param name="id">4</xsl:with-param>
1327
            </xsl:call-template>
1328
            <xsl:call-template name="makeIndent"/>
1329
          </xsl:when>
1330
          <xsl:when test="child::node()[last()]/self::*">
1331
            <xsl:call-template name="lineBreak">
1332
              <xsl:with-param name="id">5</xsl:with-param>
1333
            </xsl:call-template>
1334
            <xsl:call-template name="makeIndent"/>
1335
          </xsl:when>
1336
        </xsl:choose>
1337
        <xsl:value-of disable-output-escaping="yes" select="$startElement"/>
1338
        <xsl:text>&lt;/</xsl:text>
1339
	<xsl:call-template name="makeElementName">
1340
	  <xsl:with-param name="start">false</xsl:with-param>
1341
	</xsl:call-template>
1342
        <xsl:text>&gt;</xsl:text>
1343
        <xsl:value-of disable-output-escaping="yes" select="$endElement"/>
1344
      </xsl:when>
1345
      <xsl:otherwise>
1346
        <xsl:text>/&gt;</xsl:text>
1347
        <xsl:value-of disable-output-escaping="yes" select="$endElement"/>
1348
      </xsl:otherwise>
1349
    </xsl:choose>
1350
  </xsl:template>
1351

    
1352

    
1353
  <xsl:template name="makeElementName">
1354
    <xsl:param name="start"/>
1355
    <xsl:choose>
1356

    
1357
      <xsl:when
1358
	  test="namespace-uri()='http://docbook.org/ns/docbook'">
1359
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1360
	<xsl:text>dbk:</xsl:text>
1361
	<xsl:value-of disable-output-escaping="yes" select="$endNamespace"/>
1362
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1363
	<xsl:value-of select="local-name(.)"/>
1364
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1365
      </xsl:when>
1366

    
1367
      <xsl:when
1368
	  test="namespace-uri()='http://www.w3.org/2001/XMLSchema'">
1369
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1370
	<xsl:text>xsd:</xsl:text>
1371
	<xsl:value-of disable-output-escaping="yes"
1372
		      select="$endNamespace"/>
1373
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1374
	
1375
	<xsl:value-of select="local-name(.)"/>
1376
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1377
	
1378
      </xsl:when>
1379

    
1380
      <xsl:when
1381
	  test="namespace-uri()='http://www.ascc.net/xml/schematron'">
1382
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1383
	<xsl:text>sch:</xsl:text>
1384
	<xsl:value-of disable-output-escaping="yes"
1385
		      select="$endNamespace"/>
1386
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1387
	
1388
	<xsl:value-of select="local-name(.)"/>
1389
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1390
	
1391
      </xsl:when>
1392

    
1393
      <xsl:when
1394
	  test="namespace-uri()='http://www.w3.org/1998/Math/MathML'">
1395
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1396
	<xsl:text>m:</xsl:text>
1397
	<xsl:value-of disable-output-escaping="yes"
1398
		      select="$endNamespace"/>
1399
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1400
	
1401
	<xsl:value-of select="local-name(.)"/>
1402
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1403
	
1404
      </xsl:when>
1405

    
1406
      <xsl:when
1407
	  test="namespace-uri()='http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0'">
1408
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1409
	<xsl:text>nvdl:</xsl:text>
1410
	<xsl:value-of disable-output-escaping="yes"
1411
		      select="$endNamespace"/>
1412
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1413
	
1414
	<xsl:value-of select="local-name(.)"/>
1415
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1416
	
1417
      </xsl:when>
1418

    
1419
      <xsl:when
1420
	  test="namespace-uri()='http://relaxng.org/ns/compatibility/annotations/1.0'">
1421
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1422
	<xsl:text>a:</xsl:text>
1423
	<xsl:value-of disable-output-escaping="yes"
1424
		      select="$endNamespace"/>
1425
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1426
	
1427
	<xsl:value-of select="local-name(.)"/>
1428
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1429
	
1430
      </xsl:when>
1431
      <xsl:when
1432
	  test="namespace-uri()='http://www.w3.org/1999/xhtml'">
1433
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1434
	<xsl:text>xhtml:</xsl:text>
1435
	<xsl:value-of disable-output-escaping="yes"
1436
		      select="$endNamespace"/>
1437
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1438
	
1439
	<xsl:value-of select="local-name(.)"/>
1440
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1441
	
1442
      </xsl:when>
1443

    
1444
      <xsl:when
1445
	  test="namespace-uri()='http://www.w3.org/1999/xlink'">
1446
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1447
	<xsl:text>xlink:</xsl:text>
1448
	<xsl:value-of disable-output-escaping="yes"
1449
		      select="$endNamespace"/>
1450
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1451
	
1452
	<xsl:value-of select="local-name(.)"/>
1453
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1454
	
1455
      </xsl:when>
1456

    
1457
      <xsl:when
1458
	  test="namespace-uri()='http://relaxng.org/ns/structure/1.0'">
1459
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1460
	<xsl:text>rng:</xsl:text>
1461
	<xsl:value-of disable-output-escaping="yes"
1462
		      select="$endNamespace"/>
1463
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1464
	<xsl:value-of select="local-name(.)"/>
1465
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1466
	
1467
      </xsl:when>
1468

    
1469
      <xsl:when
1470
	  test="namespace-uri()='http://earth.google.com/kml/2.1'">
1471
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1472
	<xsl:text>kml:</xsl:text>
1473
	<xsl:value-of disable-output-escaping="yes"
1474
		      select="$endNamespace"/>
1475
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1476
	<xsl:value-of select="local-name(.)"/>
1477
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1478
	
1479
      </xsl:when>
1480

    
1481
      <xsl:when
1482
	  test="namespace-uri()='http://www.w3.org/2005/11/its'">
1483
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1484
	<xsl:text>its:</xsl:text>
1485
	<xsl:value-of disable-output-escaping="yes"
1486
		      select="$endNamespace"/>
1487
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1488
	<xsl:value-of select="local-name(.)"/>
1489
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1490
      </xsl:when>
1491

    
1492
      <xsl:when test="namespace-uri()='http://www.w3.org/1999/XSL/Transform'">
1493
        <xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1494
        <xsl:text>xsl:</xsl:text>
1495
        <xsl:value-of select="local-name(.)"/>
1496
        <xsl:value-of disable-output-escaping="yes" select="$endNamespace"/>
1497
      </xsl:when>
1498

    
1499
      <xsl:when
1500
	  test="namespace-uri()='http://www.tei-c.org/ns/Examples'">
1501
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1502
	<xsl:value-of select="local-name(.)"/>
1503
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1504
      </xsl:when>
1505

    
1506
      <xsl:when
1507
	  test="namespace-uri()='http://www.w3.org/2005/Atom'">
1508
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1509
	<xsl:text>atom:</xsl:text>
1510
	<xsl:value-of disable-output-escaping="yes"
1511
		      select="$endNamespace"/>
1512
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1513
	<xsl:value-of select="local-name(.)"/>
1514
	    <xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1515
      </xsl:when>
1516

    
1517
      <xsl:when
1518
	  test="namespace-uri()='http://purl.org/rss/1.0/modules/event/'">
1519
	<xsl:value-of disable-output-escaping="yes" select="$startNamespace"/>
1520
	<xsl:text>ev:</xsl:text>
1521
	<xsl:value-of disable-output-escaping="yes"
1522
		      select="$endNamespace"/>
1523
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1524
	<xsl:value-of select="local-name(.)"/>
1525
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1526
	
1527
      </xsl:when>
1528

    
1529
      <xsl:when test="not(namespace-uri()='')">
1530
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1531
	<xsl:value-of select="local-name(.)"/>
1532
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1533
	<xsl:if test="$start='true'">
1534
	  <xsl:text> xmlns="</xsl:text>
1535
	  <xsl:value-of select="namespace-uri()"/>
1536
	  <xsl:text>"</xsl:text>
1537
	</xsl:if>
1538
      </xsl:when>
1539

    
1540
      <xsl:otherwise>
1541
	<xsl:value-of disable-output-escaping="yes" select="$startElementName"/>
1542
	<xsl:value-of select="local-name(.)"/>
1543
	<xsl:value-of disable-output-escaping="yes" select="$endElementName"/>
1544
      </xsl:otherwise>
1545
    </xsl:choose>
1546
  </xsl:template>
1547

    
1548

    
1549
    <xsl:template name="makeIndent">
1550
      <xsl:variable name="depth"
1551
		    select="count(ancestor::*[not(namespace-uri()='http://www.tei-c.org/ns/1.0')])"/>
1552
      <xsl:call-template name="makeSpace">
1553
	<xsl:with-param name="d">
1554
	  <xsl:value-of select="$depth"/>
1555
	</xsl:with-param>
1556
      </xsl:call-template>
1557
  </xsl:template>
1558

    
1559
  <xsl:template name="makeSpace">
1560
    <xsl:param name="d"/>
1561
    <xsl:if test="number($d)&gt;1">
1562
      <xsl:value-of select="$spaceCharacter"/>
1563
      <xsl:call-template name="makeSpace">
1564
	<xsl:with-param name="d">
1565
	  <xsl:value-of select="$d -1"/>
1566
	</xsl:with-param>
1567
      </xsl:call-template>
1568
    </xsl:if>
1569
  </xsl:template>
1570

    
1571
<xsl:template match="@*" mode="verbatim">
1572
  <xsl:variable name="L">
1573
    <xsl:for-each select="../@*">
1574
      <xsl:value-of select="."/>
1575
    </xsl:for-each>
1576
  </xsl:variable>
1577
    <xsl:if test="count(../@*)&gt;$attsOnSameLine or string-length($L)&gt;40 or
1578
		  namespace-uri()='http://www.w3.org/2005/11/its' or
1579
		  string-length(.)+string-length(name(.)) &gt; 40">
1580
    <xsl:call-template name="lineBreak">
1581
      <xsl:with-param name="id">5</xsl:with-param>
1582
    </xsl:call-template>
1583
    <xsl:call-template name="makeIndent"/>
1584
  </xsl:if>
1585
  <xsl:value-of select="$spaceCharacter"/>
1586
  <xsl:value-of disable-output-escaping="yes" select="$startAttribute"/>
1587
  <xsl:choose>
1588
    <xsl:when test="namespace-uri()='http://www.w3.org/2005/11/its'">
1589
      <xsl:text>its:</xsl:text>
1590
    </xsl:when>
1591
    <xsl:when
1592
	test="namespace-uri()='http://www.w3.org/XML/1998/namespace'">
1593
      <xsl:text>xml:</xsl:text>
1594
    </xsl:when>
1595
    <xsl:when test="namespace-uri()='http://www.w3.org/1999/xlink'">
1596
      <xsl:text>xlink:</xsl:text>
1597
    </xsl:when>
1598
    <xsl:when
1599
	test="namespace-uri()='http://www.example.org/ns/nonTEI'">
1600
      <xsl:text>my:</xsl:text>
1601
    </xsl:when>
1602
    <xsl:when
1603
	test="namespace-uri()='http://relaxng.org/ns/compatibility/annotations/1.0'">
1604
      <xsl:text>a:</xsl:text>
1605
    </xsl:when>
1606
<!--    <xsl:otherwise>
1607
    <xsl:for-each select="namespace::*">
1608
      <xsl:if test="not(name(.)='')">
1609
	  <xsl:value-of select="name(.)"/>
1610
	  <xsl:text>:</xsl:text>
1611
      </xsl:if>
1612
    </xsl:for-each>
1613
    </xsl:otherwise>
1614
-->
1615
  </xsl:choose>
1616
  <xsl:value-of select="local-name(.)"/>
1617
  <xsl:value-of disable-output-escaping="yes" select="$endAttribute"/>
1618
  <xsl:text>="</xsl:text>
1619
  <xsl:value-of disable-output-escaping="yes" select="$startAttributeValue"/>
1620
  <xsl:apply-templates select="." mode="attributetext"/>
1621
  <xsl:value-of disable-output-escaping="yes" select="$endAttributeValue"/>
1622
  <xsl:text>"</xsl:text>
1623
</xsl:template>
1624

    
1625
<xsl:template match="@*" mode="attributetext">
1626
  <xsl:choose>
1627
    <xsl:when test="string-length(.)&gt;50">
1628
      <xsl:choose>
1629
	<xsl:when test="contains(.,'|')">
1630
	  <xsl:call-template name="breakMe">
1631
	    <xsl:with-param name="text">
1632
	      <xsl:value-of select="."/>
1633
	    </xsl:with-param>
1634
	    <xsl:with-param name="sep">
1635
	      <xsl:text>|</xsl:text>
1636
	    </xsl:with-param>
1637
	  </xsl:call-template>
1638
	</xsl:when>
1639
	<xsl:otherwise>
1640
	  <xsl:call-template name="breakMe">
1641
	    <xsl:with-param name="text">
1642
	      <xsl:value-of select="."/>
1643
	    </xsl:with-param>
1644
	    <xsl:with-param name="sep">
1645
	      <xsl:text> </xsl:text>
1646
	    </xsl:with-param>
1647
	  </xsl:call-template>
1648
	</xsl:otherwise>
1649
      </xsl:choose>
1650
    </xsl:when>
1651
    <xsl:otherwise>
1652
      <xsl:value-of select="."/>
1653
    </xsl:otherwise>
1654
  </xsl:choose>
1655
</xsl:template>
1656

    
1657
<xsl:template name="breakMe">
1658
  <xsl:param name="text"/>
1659
  <xsl:param name="sep"/>
1660
  <xsl:choose>
1661
    <xsl:when test="string-length($text)&lt;50">
1662
      <xsl:value-of select="$text"/>
1663
    </xsl:when>
1664
    <xsl:otherwise>
1665
      <xsl:value-of select="substring-before($text,$sep)"/>
1666
      <xsl:text>&#10;</xsl:text>
1667
      <xsl:value-of select="$sep"/>
1668
      <xsl:call-template name="breakMe">
1669
	<xsl:with-param name="text">
1670
	  <xsl:value-of select="substring-after($text,$sep)"/>
1671
	</xsl:with-param>
1672
	<xsl:with-param name="sep">
1673
	  <xsl:value-of select="$sep"/>
1674
	</xsl:with-param>
1675
      </xsl:call-template>
1676
    </xsl:otherwise>
1677
  </xsl:choose>
1678
</xsl:template>
1679

    
1680

    
1681
<xsl:template match="text()|comment()|processing-instruction()" mode="ns"/>
1682

    
1683
<xsl:template match="*" mode="ns">
1684
  <xsl:param name="list"/>
1685
  <xsl:variable name="used">
1686
    <xsl:for-each select="namespace::*">
1687
      <xsl:variable name="ns" select="."/>
1688
      <xsl:choose>
1689
	<xsl:when test="contains($list,$ns)"/>
1690
	<xsl:when test=".='http://relaxng.org/ns/structure/1.0'"/>
1691
	<xsl:when test=".='http://www.w3.org/2001/XInclude'"/>
1692
	<xsl:when test=".='http://www.tei-c.org/ns/Examples'"/>
1693
	<xsl:when test=".='http://relaxng.org/ns/compatibility/annotations/1.0'"/>
1694
	<xsl:when test="name(.)=''"/>
1695
	<xsl:when test=".='http://www.w3.org/XML/1998/namespace'"/>
1696
	<xsl:otherwise>
1697
	  <xsl:call-template name="lineBreak">
1698
	    <xsl:with-param name="id">22</xsl:with-param>
1699
	  </xsl:call-template>
1700
	  <xsl:text>&#160;&#160;&#160;</xsl:text>
1701
	  <xsl:text>xmlns:</xsl:text>
1702
	  <xsl:value-of select="name(.)"/>
1703
	  <xsl:text>="</xsl:text>
1704
	  <xsl:value-of select="."/>
1705
	  <xsl:text>"</xsl:text>
1706
	</xsl:otherwise>
1707
      </xsl:choose>
1708
    </xsl:for-each>
1709
    </xsl:variable>
1710
  <xsl:copy-of select="$used"/>
1711
  <xsl:apply-templates mode="ns">
1712
    <xsl:with-param name="list">
1713
      <xsl:value-of select="$list"/>
1714
      <xsl:value-of select="$used"/>
1715
    </xsl:with-param>
1716
  </xsl:apply-templates>
1717
</xsl:template>
1718

    
1719

    
1720
  <xsl:template name="italicize"/>
1721

    
1722
  <xsl:template match="tei:soCalled">
1723
    <text:span>
1724
      <xsl:value-of select="$preQuote"/>
1725
      <xsl:apply-templates/>
1726
      <xsl:value-of select="$postQuote"/>
1727
    </text:span>
1728
  </xsl:template>
1729

    
1730
  <xsl:function name="tei:convert-dim-pt" as="xs:integer">
1731
    <xsl:param name="dim"/>
1732
    <xsl:choose>
1733
      <xsl:when test="ends-with($dim,'cm')">
1734
	<xsl:value-of select="number(number(substring($dim,0,string-length($dim)-1))*28.3464567) cast as xs:integer"/>
1735
      </xsl:when>
1736
      <xsl:when test="ends-with($dim,'in')">
1737
	<xsl:value-of select="number(number(substring($dim,0,string-length($dim)-1))*72) cast as xs:integer"/>
1738
      </xsl:when>
1739
      
1740
      <xsl:when test="ends-with($dim,'mm')">
1741
	<xsl:value-of select="number(number(substring($dim,0,string-length($dim)-1))*2.83464567) cast as xs:integer"/>
1742
      </xsl:when>
1743
      <xsl:when test="ends-with($dim,'pt')">
1744
	<xsl:value-of select="number(substring($dim,0,string-length($dim)-1)) cast as xs:integer"/>
1745
      </xsl:when>
1746
      <xsl:when test="ends-with($dim,'px')">
1747
	<xsl:value-of select="number(number(substring($dim,0,string-length($dim)-1))*0.75) cast as xs:integer"/>
1748
      </xsl:when>
1749
      
1750
      <xsl:otherwise>
1751
	-1
1752
      </xsl:otherwise>
1753
    </xsl:choose>
1754
  </xsl:function>
1755

    
1756
  <xsl:template name="makeExternalLink">
1757
    <xsl:param name="ptr" as="xs:boolean" select="false()"/>
1758
    <xsl:param name="dest"/>
1759
    <xsl:param name="class">link_<xsl:value-of select="local-name(.)"/></xsl:param>
1760
    <text:a xlink:type="simple" xlink:href="{$dest}">
1761
      <xsl:choose>
1762
	<xsl:when test="$ptr">
1763
	  <xsl:value-of select="$dest"/>
1764
	</xsl:when>
1765
	<xsl:otherwise>
1766
	  <xsl:apply-templates/>
1767
	</xsl:otherwise>
1768
      </xsl:choose>
1769
    </text:a>
1770
  </xsl:template>
1771

    
1772

    
1773
  <xsl:template name="startHook">
1774
    <xsl:choose>
1775
      <xsl:when test="self::tei:list and parent::tei:item">
1776
	<xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
1777
	<xsl:text disable-output-escaping="yes">&lt;/text:list&gt;</xsl:text>
1778
      </xsl:when>
1779
      <xsl:when test="parent::tei:p">
1780
      <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
1781
      </xsl:when>
1782
    </xsl:choose>
1783
  </xsl:template>
1784

    
1785
  <xsl:template name="endHook">
1786
    <xsl:choose>
1787
      <xsl:when test="self::tei:list and parent::tei:item">
1788
	<xsl:text disable-output-escaping="yes">&lt;text:list
1789
	</xsl:text>
1790
	<xsl:choose>
1791
	  <xsl:when test="parent::tei:list[@type='ordered']">
1792
	  </xsl:when>
1793
	</xsl:choose>
1794
	<xsl:text>&gt;</xsl:text>
1795
	<xsl:text disable-output-escaping="yes">&lt;text:p  text:style-name="List Contents&gt;</xsl:text>
1796
      </xsl:when>
1797
      <xsl:when test="parent::tei:p">
1798
      <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
1799
      </xsl:when>
1800
    </xsl:choose>
1801
  </xsl:template>
1802

    
1803
  <xsl:template name="generateRevDate">
1804
      <xsl:variable name="when">
1805
         <xsl:choose>
1806
            <xsl:when test="ancestor-or-self::tei:TEI/tei:teiHeader/tei:revisionDesc/descendant::tei:date">
1807
               <xsl:value-of select="ancestor-or-self::tei:TEI/tei:teiHeader/tei:revisionDesc/descendant::tei:date[1]"/>
1808
            </xsl:when>
1809
            <xsl:when
1810
		test="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/descendant::tei:date">
1811
	      <xsl:value-of select="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/descendant::tei:date"/>
1812
	    </xsl:when>	    
1813
         </xsl:choose>
1814
      </xsl:variable>
1815
      <xsl:choose>
1816
         <xsl:when test="starts-with($when,'$Date')">
1817
        <!-- it's RCS -->
1818
        <xsl:value-of select="substring($when,16,2)"/>
1819
            <xsl:text>/</xsl:text>
1820
            <xsl:value-of select="substring($when,13,2)"/>
1821
            <xsl:text>/</xsl:text>
1822
            <xsl:value-of select="substring($when,8,4)"/>
1823
         </xsl:when>
1824
         <xsl:when test="starts-with($when,'$LastChangedDate')">
1825
        <!-- it's Subversion-->
1826
        <xsl:value-of select="substring-before(substring-after($when,'('),')')"/>
1827
         </xsl:when>
1828
         <xsl:otherwise>
1829
            <xsl:value-of select="$when"/>
1830
         </xsl:otherwise>
1831
      </xsl:choose>
1832
  </xsl:template>
1833
  <xsl:template name="generateDate">
1834
      <xsl:choose>
1835
	 <xsl:when test="$useFixedDate='true'">1970-01-01</xsl:when>
1836
         <xsl:when
1837
	     test="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/tei:editionStmt/descendant::tei:date[@when]">
1838
            <xsl:value-of select="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/tei:editionStmt/descendant::tei:date[@when][1]/@when"/>
1839
         </xsl:when>
1840
         <xsl:when test="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/tei:editionStmt/descendant::tei:date">
1841
            <xsl:value-of select="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/tei:editionStmt/descendant::tei:date[1]"/>
1842
         </xsl:when>
1843
         <xsl:when test="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:date">
1844
            <xsl:value-of select="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:date"/>
1845
         </xsl:when>
1846
         <xsl:when test="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/tei:editionStmt/tei:edition">
1847
            <xsl:apply-templates select="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/tei:editionStmt/tei:edition"/>
1848
         </xsl:when>
1849
	 <xsl:when
1850
	     test="ancestor-or-self::tei:TEI/tei:teiHeader/tei:revisionDesc/tei:change[@when
1851
		   or tei:date]">
1852
            <xsl:for-each
1853
		select="ancestor-or-self::tei:TEI/tei:teiHeader/tei:revisionDesc/tei:change[1]">
1854
	      <xsl:choose>
1855
		<xsl:when test="@when">
1856
		  <xsl:value-of select="@when"/>
1857
		</xsl:when>
1858
		<xsl:when test="tei:date/@when">
1859
		  <xsl:value-of select="tei:date/@when"/>
1860
		</xsl:when>
1861
		<xsl:when test="tei:date">
1862
		  <xsl:value-of select="tei:date"/>
1863
		</xsl:when>
1864
		<xsl:otherwise>
1865
		  <xsl:value-of select="format-dateTime(current-dateTime(),'[Y]-[M02]-[D02]')"/>
1866
		</xsl:otherwise>
1867
	      </xsl:choose>
1868
	    </xsl:for-each>
1869
	 </xsl:when>
1870
	 <xsl:otherwise>
1871
	   <xsl:value-of select="format-dateTime(current-dateTime(),'[Y]-[M02]-[D02]')"/>
1872
	 </xsl:otherwise>
1873
      </xsl:choose>
1874
  </xsl:template>
1875

    
1876
  <xsl:template name="generateTitle">
1877
    <xsl:for-each
1878
	select="ancestor-or-self::tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt">
1879
	<xsl:apply-templates select="tei:title"/>
1880
    </xsl:for-each>
1881
  </xsl:template>
1882

    
1883
  <xsl:template name="makeSpan">
1884
    <xsl:apply-templates/>
1885
  </xsl:template>
1886

    
1887
  <xsl:template name="tei:makeText">
1888
    <xsl:param name="letters"/>
1889
    <xsl:value-of select="$letters"/>
1890
  </xsl:template>
1891

    
1892

    
1893
    <xsl:template name="emphasize">
1894
      <xsl:param name="class"/>
1895
      <xsl:param name="content"/>
1896
      <text:span>
1897
	<xsl:choose>
1898
	  <xsl:when test="$class='titlem'">
1899
	    <xsl:attribute name="text:style-name">Emphasis</xsl:attribute>
1900
	  </xsl:when>
1901
	  <xsl:when test="$class='titlej'">
1902
	    <xsl:attribute name="text:style-name">Emphasis</xsl:attribute>
1903
	  </xsl:when>
1904
	</xsl:choose>
1905
	<xsl:attribute name="xml:space">preserve</xsl:attribute>
1906
	  <xsl:choose>
1907
	    <xsl:when test="$class='titles'">
1908
	      <xsl:text>, </xsl:text>
1909
	    </xsl:when>
1910
	    <xsl:when test="$class='titleu'">
1911
	      <xsl:text>‘</xsl:text>
1912
	    </xsl:when>
1913
	    <xsl:when test="$class='titlea'">
1914
	      <xsl:text>‘</xsl:text>
1915
	    </xsl:when>
1916
	  </xsl:choose>
1917
	  <xsl:value-of select="$content"/>
1918
	  <xsl:choose>
1919
	    <xsl:when test="$class='titleu'">
1920
	      <xsl:text>’</xsl:text>
1921
	    </xsl:when>
1922
	    <xsl:when test="$class='titlea'">
1923
	      <xsl:text>’</xsl:text>
1924
	    </xsl:when>
1925
	  </xsl:choose>
1926
      </text:span>
1927
    </xsl:template>
1928
 
1929
</xsl:stylesheet>