Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / docx / to / teitodocx.xsl @ 187

History | View | Annotate | Download (87.9 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:cals="http://www.oasis-open.org/specs/tm9901" xmlns:contypes="http://schemas.openxmlformats.org/package/2006/content-types" xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:iso="http://www.iso.org/ns/1.0" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:tbx="http://www.lisa.org/TBX-Specification.33.0.html" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:teidocx="http://www.tei-c.org/ns/teidocx/1.0" xmlns:teix="http://www.tei-c.org/ns/Examples" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" exclude-result-prefixes="cp ve o r m v wp w10 w wne mml tbx iso its tei a xs pic fn xsi dc dcterms dcmitype contypes teidocx teix html cals">
3
  <xsl:import href="placeholders.xsl"/>
4
  <xsl:import href="../../common2/functions.xsl"/>
5
  <xsl:import href="../utils/functions.xsl"/>
6
  <xsl:import href="../utils/variables.xsl"/>
7
  <xsl:import href="../utils/identity/identity.xsl"/>
8
  <xsl:import href="../utils/verbatim/tei-docx-verbatim.xsl"/>
9
  <xsl:import href="../utils/maths/mml2omml.xsl"/>
10
  <xsl:import href="../../common2/core.xsl"/>
11
  <xsl:import href="../../common2/msdescription.xsl"/>
12
  <!-- Deals with dynamic text creation such as toc -->
13
  <xsl:include href="dynamic/dynamic.xsl"/>
14
  <!-- Templates transforming graphic elements -->
15
  <xsl:include href="graphics/graphics.xsl"/>
16
  <!-- Templates transforming elements from drama -->
17
  <xsl:include href="drama/drama.xsl"/>
18
  <!-- Templates transforming lists -->
19
  <xsl:include href="lists/lists.xsl"/>
20
  <!-- Templates transforming math elements -->
21
  <xsl:include href="maths/maths.xsl"/>
22
  <!-- Templates transforming ODD-related elements -->
23
  <xsl:include href="odds/tagdocs.xsl"/>
24
  <!-- Templates transforming tei milestones into sectPr -->
25
  <xsl:include href="wordsections/wordsections.xsl"/>
26
  <!-- Load stylesheets helping with the creation of special files -->
27
  <xsl:include href="docxfiles/application.xsl"/>
28
  <xsl:include href="docxfiles/content-types.xsl"/>
29
  <xsl:include href="docxfiles/endnotes.xsl"/>
30
  <xsl:include href="docxfiles/footers.xsl"/>
31
  <xsl:include href="docxfiles/comments.xsl"/>
32
  <xsl:include href="docxfiles/footnotes.xsl"/>
33
  <xsl:include href="docxfiles/headers.xsl"/>
34
  <xsl:include href="docxfiles/numbering-definition.xsl"/>
35
  <xsl:include href="docxfiles/relationships.xsl"/>
36
  <xsl:include href="docxfiles/settings.xsl"/>
37
  <xsl:param name="createanttask">false</xsl:param>
38
  <xsl:param name="useHeaderFrontMatter">false</xsl:param>
39
  <xsl:param name="useFixedDate">false</xsl:param>
40
  <!--
41
        A4 is 210mm x 297mm; leaving 1in margin (25mm),
42
        gives 160 x 247 approx useable area. For figures,
43
	Microsoft use English metrical units (emu), in which
44
        1mm = 3600 units. So page size is 57600 * 889200
45
        Divide by 100 to avoid overflow in calculations.
46

    
47
        For other measurements in Word, see useful discussion at
48
	http://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/
49
    -->
50
  <xsl:param name="pageWidth">576</xsl:param>
51
  <xsl:param name="pageHeight">890</xsl:param>
52
  <xsl:param name="tableWidthPercentage"></xsl:param>
53
  <xsl:param name="defaultHeaderFooterFile">templates/default.xml</xsl:param>
54
  <xsl:param name="postQuote">’</xsl:param>
55
  <xsl:param name="preQuote">‘</xsl:param>
56
  <xsl:param name="bulletOne"></xsl:param>
57
  <xsl:param name="bulletTwo">•</xsl:param>
58
  <xsl:param name="bulletThree">*</xsl:param>
59
  <xsl:param name="bulletFour">+</xsl:param>
60
  <xsl:param name="bulletFive">•</xsl:param>
61
  <xsl:param name="bulletSix">•</xsl:param>
62
  <xsl:param name="bulletSeven">•</xsl:param>
63
  <xsl:param name="bulletEight">•</xsl:param>
64
  <xsl:param name="word-directory">..</xsl:param>
65
  <xsl:param name="inputDir">.</xsl:param>
66
  <xsl:param name="debug">false</xsl:param>
67
  <xsl:param name="styleDoc">
68
    <xsl:value-of select="concat($wordDirectory, '/word/styles.xml')"/>
69
  </xsl:param>
70
  <xsl:param name="docDoc">
71
    <xsl:value-of select="concat($wordDirectory, '/word/document.xml')"/>
72
  </xsl:param>
73
  <xsl:param name="shadowGraphics">false</xsl:param>
74
  <xsl:param name="alignFigures">center</xsl:param>
75
  <xsl:param name="renderAddDel">true</xsl:param>
76
  <xsl:param name="addColour">red</xsl:param>
77
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
78
    <desc>
79
      <p> TEI stylesheet for making Word docx files from TEI XML </p>
80
      <p><h1 xmlns="">Stylesheet documentation</h1><h2 xmlns="">template modes</h2><h3 xmlns="">get-style</h3><h1 xmlns="">License</h1>This software is dual-licensed:
81

    
82
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
83
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
84

    
85
2. http://www.opensource.org/licenses/BSD-2-Clause
86
		
87
All rights reserved.
88

    
89
Redistribution and use in source and binary forms, with or without
90
modification, are permitted provided that the following conditions are
91
met:
92

    
93
* Redistributions of source code must retain the above copyright
94
notice, this list of conditions and the following disclaimer.
95

    
96
* Redistributions in binary form must reproduce the above copyright
97
notice, this list of conditions and the following disclaimer in the
98
documentation and/or other materials provided with the distribution.
99

    
100
This software is provided by the copyright holders and contributors
101
"as is" and any express or implied warranties, including, but not
102
limited to, the implied warranties of merchantability and fitness for
103
a particular purpose are disclaimed. In no event shall the copyright
104
holder or contributors be liable for any direct, indirect, incidental,
105
special, exemplary, or consequential damages (including, but not
106
limited to, procurement of substitute goods or services; loss of use,
107
data, or profits; or business interruption) however caused and on any
108
theory of liability, whether in contract, strict liability, or tort
109
(including negligence or otherwise) arising in any way out of the use
110
of this software, even if advised of the possibility of such damage.
111
</p>
112
      <p>Author: See AUTHORS</p>
113
      <p>Id: $Id: teitodocx.xsl 9998 2012-01-02 18:27:15Z rahtz $</p>
114
      <p>Copyright: 2008, TEI Consortium</p>
115
    </desc>
116
  </doc>
117
  <xsl:strip-space elements="*"/>
118
  <xsl:preserve-space elements="tei:text"/>
119
  <xsl:output method="xml" version="1.0" encoding="UTF-8"/>
120
  <xsl:param name="isofreestanding">true</xsl:param>
121
  <xsl:key name="FOOTERS" match="tei:fw[@type='footer']" use="@xml:id"/>
122
  <xsl:key name="HEADERS" match="tei:fw[@type='header']" use="@xml:id"/>
123
  <xsl:key name="ALLFOOTERS" match="tei:fw[@type='footer']" use="1"/>
124
  <xsl:key name="ALLHEADERS" match="tei:fw[@type='header']" use="1"/>
125
  <xsl:key name="ENDNOTES" match="tei:note[@place='end']" use="1"/>
126
  <xsl:key name="FOOTNOTES" match="tei:note[@place='foot' or @place='bottom' ]" use="1"/>
127
  <xsl:key name="OL" match="tei:list[@type='ordered']" use="1"/>
128
  <xsl:key name="BLIP" match="a:blip" use="1"/>
129
  <xsl:key name="Styles" match="w:style/w:name" use="@w:val"/>
130
  <xsl:variable name="align">right</xsl:variable>
131
  <xsl:variable name="wordDirectory">
132
    <xsl:value-of select="translate($word-directory,'\\','/')"/>
133
  </xsl:variable>
134
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
135
    <desc>
136
        Generic template from msDescription for high-level section
137
    </desc>
138
  </doc>
139
  <xsl:template name="msSection">
140
    <xsl:param name="level"/>
141
    <xsl:param name="implicitBlock"/>
142
    <xsl:param name="heading"/>
143
    <w:p>
144
      <w:pPr>
145
        <w:pStyle w:val="tei{local-name()}"/>
146
      </w:pPr>
147
      <w:r>
148
        <w:t>
149
          <xsl:value-of select="$heading"/>
150
        </w:t>
151
      </w:r>
152
    </w:p>
153
    <xsl:call-template name="block-element"/>
154
  </xsl:template>
155
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
156
    <desc>
157
        Generic template from msDescription for inline objects
158
    </desc>
159
  </doc>
160
  <xsl:template name="msInline">
161
    <xsl:param name="before"/>
162
    <xsl:param name="after"/>
163
    <xsl:param name="style"/>
164
    <w:r>
165
      <w:rPr>
166
        <w:rStyle w:val="tei{local-name()}"/>
167
        <xsl:choose>
168
          <xsl:when test="$style='italic'">
169
            <w:i/>
170
          </xsl:when>
171
          <xsl:when test="$style='bold'">
172
            <w:b/>
173
          </xsl:when>
174
        </xsl:choose>
175
        <xsl:if test="$renderAddDel='true' and ancestor-or-self::tei:del">
176
          <w:strike/>
177
        </xsl:if>
178
      </w:rPr>
179
      <w:t>
180
        <xsl:value-of select="$before"/>
181
        <xsl:value-of select="."/>
182
        <xsl:value-of select="$after"/>
183
      </w:t>
184
    </w:r>
185
  </xsl:template>
186
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
187
    <desc>
188
        Generic template from msDescription for mid-level block
189
    </desc>
190
  </doc>
191
  <xsl:template name="msBlock">
192
    <xsl:param name="style"/>
193
    <xsl:call-template name="block-element">
194
      <xsl:with-param name="style">
195
        <xsl:value-of select="$style"/>
196
      </xsl:with-param>
197
    </xsl:call-template>
198
  </xsl:template>
199
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
200
    <desc>
201
        Generic template from msDescription for labelled object
202
    </desc>
203
  </doc>
204
  <xsl:template name="msLabelled">
205
    <xsl:param name="before"/>
206
    <w:r>
207
      <w:rPr>
208
        <w:i/>
209
      </w:rPr>
210
      <w:t>
211
        <xsl:attribute name="xml:space">preserve</xsl:attribute>
212
        <xsl:value-of select="$before"/>
213
        <xsl:text>: </xsl:text>
214
      </w:t>
215
    </w:r>
216
    <w:r>
217
      <w:rPr>
218
        <w:rStyle w:val="tei{local-name()}"/>
219
      </w:rPr>
220
      <w:t>
221
        <xsl:value-of select="."/>
222
      </w:t>
223
    </w:r>
224
  </xsl:template>
225
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
226
    <desc>
227
        Generic template from msDescription for literal text
228
    </desc>
229
  </doc>
230
  <xsl:template name="msLiteral">
231
    <xsl:param name="text"/>
232
    <w:r>
233
      <w:rPr/>
234
      <w:t>
235
        <xsl:attribute name="xml:space">preserve</xsl:attribute>
236
        <xsl:value-of select="$text"/>
237
      </w:t>
238
    </w:r>
239
  </xsl:template>
240
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
241
    <desc>
242
        The starting point in the conversion to docx.
243
    </desc>
244
  </doc>
245
  <xsl:template match="/tei:TEI">
246
    <xsl:call-template name="write-docxfiles"/>
247
    <xsl:call-template name="create-document-dot-xml"/>
248
  </xsl:template>
249
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
250
    <desc>
251
        Calls templates that are responsible for creating all necessary files besides the
252
            main document.xml
253
    </desc>
254
  </doc>
255
  <xsl:template name="write-docxfiles">
256
    <!-- header and footers -->
257
    <xsl:call-template name="write-docxfile-header-files"/>
258
    <!-- footer files -->
259
    <xsl:call-template name="write-docxfile-footer-files"/>
260
    <!-- numbering file -->
261
    <xsl:call-template name="write-docxfile-numbering-definition"/>
262
    <!-- footnotes file -->
263
    <xsl:call-template name="write-docxfile-footnotes-file"/>
264
    <!-- endnotes file -->
265
    <xsl:call-template name="write-docxfile-endnotes-file"/>
266
    <!-- comments file -->
267
    <xsl:call-template name="write-docxfile-comments-file"/>
268
    <!-- main relationships -->
269
    <xsl:call-template name="write-docxfile-main-relationships"/>
270
    <!-- relationships -->
271
    <xsl:call-template name="write-docxfile-relationships"/>
272
    <!-- write Content Types -->
273
    <xsl:call-template name="write-docxfile-content-types"/>
274
    <!-- settings -->
275
    <xsl:call-template name="write-docxfile-settings"/>
276
    <!-- app files -->
277
    <xsl:call-template name="write-docxfile-docprops-core"/>
278
    <xsl:call-template name="write-docxfile-docprops-app"/>
279
    <xsl:call-template name="write-docxfile-docprops-custom"/>
280
  </xsl:template>
281
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
282
    <desc>
283
        Create the contents of the main document.xml file, that contains all "real" content.
284
    </desc>
285
  </doc>
286
  <xsl:template name="create-document-dot-xml">
287
    <w:document>
288
      <w:body>
289
        <!-- Front -->
290
        <xsl:call-template name="write-document-dot-xml-frontmatter"/>
291
        <!-- Main -->
292
        <xsl:call-template name="write-document-dot-xml-maincontent"/>
293
        <!-- Back -->
294
        <xsl:call-template name="write-document-dot-xml-backmatter"/>
295
        <!-- Clearing up at the end -->
296
        <xsl:call-template name="write-document-dot-xml-postclearing"/>
297
      </w:body>
298
    </w:document>
299
  </xsl:template>
300
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
301
    <desc>
302
        Handles the front matter
303
    </desc>
304
  </doc>
305
  <xsl:template name="write-document-dot-xml-frontmatter">
306
    <!-- are there specific titlepages -->
307
    <xsl:call-template name="titlepages"/>
308
    <!-- header components -->
309
    <xsl:call-template name="headerParts"/>
310
    <!-- The front matter -->
311
    <xsl:apply-templates select="tei:text/tei:front"/>
312
  </xsl:template>
313
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
314
    <desc>
315
        Handles the main content
316
    </desc>
317
  </doc>
318
  <xsl:template name="write-document-dot-xml-maincontent">
319
    <!-- document title -->
320
    <xsl:call-template name="document-title"/>
321
    <!-- Describes the main part of the document -->
322
    <xsl:apply-templates select="tei:text/tei:body"/>
323
  </xsl:template>
324
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
325
    <desc>
326
        Handles the back matter
327
    </desc>
328
  </doc>
329
  <xsl:template name="write-document-dot-xml-backmatter">
330
    <!-- Describes the back matter of the document -->
331
    <xsl:apply-templates select="tei:text/tei:back"/>
332
  </xsl:template>
333
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
334
    <desc>
335
      <p>Inserts final word specific sections</p>
336
      <p> Inserts a final sectPr section if we need one </p>
337
    </desc>
338
  </doc>
339
  <xsl:template name="write-document-dot-xml-postclearing">
340
    <!-- write out final sectPr .. if exists -->
341
    <xsl:choose>
342
      <xsl:when test="tei:text/tei:milestone">
343
        <xsl:apply-templates select="tei:text/tei:milestone[1]">
344
          <xsl:with-param name="final-section">true</xsl:with-param>
345
        </xsl:apply-templates>
346
      </xsl:when>
347
      <xsl:otherwise>
348
        <xsl:apply-templates select="document($defaultHeaderFooterFile)/tei:TEI/tei:text/tei:milestone">
349
          <xsl:with-param name="final-section">true</xsl:with-param>
350
        </xsl:apply-templates>
351
      </xsl:otherwise>
352
    </xsl:choose>
353
  </xsl:template>
354
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
355
    <desc>
356
      <p>Template used to process block elements:</p>
357
      <ul>
358
        <li><b>style</b>: A style for all the <gi>w:p</gi>s</li>
359
        <li><b>pPr</b>: An entire <gi>pPr</gi> element to use </li>
360
        <li><b>nop</b>: a w:p has already been created and no new w:p is to be created </li>
361
        <li><b>bookmark-id</b>: if present in conjunction with bookmark-name, a bookmark is created around the current element </li>
362
        <li><b>bookmark-name</b>: see bookmark-id </li>
363
      </ul>
364
    </desc>
365
  </doc>
366
  <xsl:template name="block-element">
367
    <xsl:param name="style"/>
368
    <xsl:param name="select" select="."/>
369
    <xsl:param name="pPr"/>
370
    <xsl:param name="nop">false</xsl:param>
371
    <xsl:param name="bookmark-id"/>
372
    <xsl:param name="bookmark-name"/>
373
    <xsl:for-each select="$select">
374
      <xsl:for-each-group select="*|processing-instruction()|text()" group-adjacent="1">
375
        <xsl:call-template name="_process-blockelement">
376
          <xsl:with-param name="style" select="$style"/>
377
          <xsl:with-param name="pPr" select="$pPr"/>
378
          <xsl:with-param name="nop" select="$nop"/>
379
          <xsl:with-param name="bookmark-id" select="$bookmark-id"/>
380
          <xsl:with-param name="bookmark-name" select="$bookmark-name"/>
381
        </xsl:call-template>
382
      </xsl:for-each-group>
383
    </xsl:for-each>
384
  </xsl:template>
385
  <!-- end template block-element -->
386
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
387
    <desc>
388
      <p>
389
            This template processes block elements (or better to say the children of a block element)
390
            and should never be called directly 
391
            (call block-element instead). The function processes all children and puts
392
            all inline elements into one w:p. If it encounters a nested block element
393
            (e.g. a note inside a p) then it closes the previous w:p processes that block
394
            element and then again starts putting all following inline elements into another
395
            w:p element.
396
            
397
            @see block-element
398
        </p>
399
    </desc>
400
  </doc>
401
  <xsl:template name="_process-blockelement">
402
    <xsl:param name="style"/>
403
    <xsl:param name="pPr"/>
404
    <xsl:param name="nop"/>
405
    <xsl:param name="bookmark-id"/>
406
    <xsl:param name="bookmark-name"/>
407
    <!-- Process Child elements -->
408
    <xsl:for-each-group select="current-group()" group-starting-with="*[not(tei:is-inline(.))]">
409
      <xsl:choose>
410
        <!-- if the current item is a block element, we process that one,
411
                     and then take call this function recursively was all the other
412
                     elements -->
413
        <xsl:when test="self::*[not(tei:is-inline(.))]">
414
          <!-- process block element -->
415
          <xsl:apply-templates select=".">
416
            <xsl:with-param name="style" select="$style"/>
417
            <xsl:with-param name="pPr" select="$pPr"/>
418
            <xsl:with-param name="nop" select="$nop"/>
419
          </xsl:apply-templates>
420
          <!-- process all the other elements in the current group -->
421
          <xsl:for-each-group select="current-group() except ." group-adjacent="1">
422
            <xsl:call-template name="_process-blockelement">
423
              <xsl:with-param name="style" select="$style"/>
424
              <xsl:with-param name="pPr" select="$pPr"/>
425
              <xsl:with-param name="nop" select="$nop"/>
426
            </xsl:call-template>
427
          </xsl:for-each-group>
428
        </xsl:when>
429
        <!-- we encountered an inline element. This means that the current group only
430
                     contains inline elements -->
431
        <xsl:otherwise>
432
          <!--
433
	  <xsl:message>+@@ <xsl:value-of select="name()"/>: pPr:	  <xsl:if test="not(empty($pPr))"><xsl:copy-of
434
	  select="$pPr"/></xsl:if>; style: <xsl:if
435
	  test="not(empty($style))"><xsl:copy-of
436
	  select="$style"/></xsl:if></xsl:message>
437
-->
438
          <!-- create all text runs for each item in the current group. we will later
439
                         on decide whether we are grouping them together in a w:p or not. -->
440
          <xsl:variable name="innerRuns">
441
            <!-- add paragraph properties (if nobody else created a w:p ($nop)) -->
442
            <xsl:if test="$nop!='true'">
443
              <xsl:choose>
444
                <xsl:when test="not($style='')">
445
                  <w:pPr>
446
                    <w:pStyle>
447
                      <xsl:attribute name="w:val" select="$style"/>
448
                    </w:pStyle>
449
                  </w:pPr>
450
                </xsl:when>
451
                <xsl:when test="not(empty($pPr))">
452
                  <xsl:copy-of select="$pPr"/>
453
                </xsl:when>
454
              </xsl:choose>
455
            </xsl:if>
456
            <!-- bookmark start -->
457
            <xsl:if test="string-length($bookmark-name) &gt; 0 and string-length($bookmark-id) &gt; 0">
458
              <w:bookmarkStart w:id="{$bookmark-id}" w:name="{$bookmark-name}"/>
459
            </xsl:if>
460
            <!-- Create text runs -->
461
            <xsl:for-each select="current-group()">
462
              <xsl:apply-templates select=".">
463
                <xsl:with-param name="style" select="$style"/>
464
                <xsl:with-param name="pPr" select="$pPr"/>
465
              </xsl:apply-templates>
466
            </xsl:for-each>
467
            <!-- bookmark end-->
468
            <xsl:if test="string-length($bookmark-name) &gt; 0 and string-length($bookmark-id) &gt; 0">
469
              <w:bookmarkEnd w:id="{$bookmark-id}"/>
470
            </xsl:if>
471
          </xsl:variable>
472
          <!-- write out text runs.
473
                         if someone has already created a w:p ($nop) we may not create another one. -->
474
          <xsl:choose>
475
            <xsl:when test="$nop='true'">
476
              <xsl:copy-of select="$innerRuns"/>
477
            </xsl:when>
478
            <xsl:otherwise>
479
              <w:p>
480
                <xsl:copy-of select="$innerRuns"/>
481
              </w:p>
482
            </xsl:otherwise>
483
          </xsl:choose>
484
        </xsl:otherwise>
485
      </xsl:choose>
486
    </xsl:for-each-group>
487
    <!-- end process children -->
488
  </xsl:template>
489
  <!-- end template _process-blockelement -->
490
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
491
    <desc>
492
        Anchors
493
    </desc>
494
  </doc>
495
  <xsl:template match="tei:anchor">
496
    <xsl:variable name="N">
497
      <xsl:number level="any"/>
498
    </xsl:variable>
499
    <w:bookmarkStart w:id="{number($N) + 20000}" w:name="{@xml:id}"/>
500
    <w:bookmarkEnd w:id="{number($N) + 20000}"/>
501
  </xsl:template>
502
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
503
    <desc>
504
        Handles text sections. Adds a bookmark if they are the
505
	first text in this object. 
506
    </desc>
507
  </doc>
508
  <xsl:template match="text()">
509
    <xsl:param name="character-style"/>
510
    <xsl:choose>
511
      <xsl:when test="ancestor::tei:head"/>
512
      <xsl:when test="ancestor::tei:bibl"/>
513
      <xsl:when test="preceding-sibling::text()"/>
514
      <xsl:when test="parent::tei:head/parent::tei:*/@xml:id">
515
        <xsl:for-each select="parent::tei:head/parent::tei:*">
516
          <xsl:variable name="N">
517
            <xsl:number level="any"/>
518
          </xsl:variable>
519
          <w:bookmarkStart w:id="{number($N) + 10000}" w:name="{@xml:id}"/>
520
        </xsl:for-each>
521
      </xsl:when>
522
      <xsl:when test="../@xml:id">
523
        <xsl:for-each select="..">
524
          <xsl:variable name="N">
525
            <xsl:number level="any"/>
526
          </xsl:variable>
527
          <w:bookmarkStart w:id="{number($N) + 10000}" w:name="{@xml:id}"/>
528
        </xsl:for-each>
529
      </xsl:when>
530
    </xsl:choose>
531
    <xsl:if test="parent::tei:head/parent::tei:div[@iso:status]">
532
      <w:r>
533
        <w:t>
534
          <xsl:attribute name="xml:space">preserve</xsl:attribute>
535
          <xsl:text> (</xsl:text>
536
          <xsl:value-of select="../../@iso:status"/>
537
          <xsl:text>) </xsl:text>
538
        </w:t>
539
      </w:r>
540
    </xsl:if>
541
    <!-- if no specific style is assigned we might check for any other indication to assign 
542
	   some style ... -->
543
    <xsl:variable name="renderingProperties">
544
      <xsl:for-each select="..">
545
        <xsl:call-template name="applyRend"/>
546
      </xsl:for-each>
547
    </xsl:variable>
548
    <xsl:variable name="rProps">
549
      <xsl:if test="string-length($character-style) &gt; 0 or not(empty($renderingProperties))">
550
        <w:rPr>
551
          <xsl:if test="string-length($character-style) &gt; 0">
552
            <w:rStyle>
553
              <xsl:choose>
554
                <!-- this is a rogue - trap it and kill it -->
555
                <xsl:when test="$character-style='footnote reference'">
556
                  <xsl:attribute name="w:val" select="'FootnoteReference'"/>
557
                </xsl:when>
558
                <xsl:otherwise>
559
                  <xsl:attribute name="w:val" select="$character-style"/>
560
                </xsl:otherwise>
561
              </xsl:choose>
562
            </w:rStyle>
563
          </xsl:if>
564
          <xsl:copy-of select="$renderingProperties"/>
565
          <xsl:if test="ancestor::*[@xml:lang]">
566
            <w:lang w:val="{ancestor::*[@xml:lang][1]/@xml:lang}"/>
567
          </xsl:if>
568
        </w:rPr>
569
      </xsl:if>
570
    </xsl:variable>
571
    <xsl:choose>
572
      <xsl:when test="$renderAddDel='true'">
573
        <w:r>
574
          <xsl:copy-of select="$rProps"/>
575
          <w:t>
576
            <xsl:call-template name="Text"/>
577
          </w:t>
578
        </w:r>
579
      </xsl:when>
580
      <xsl:when test="parent::tei:del">
581
        <w:del>
582
          <xsl:variable name="N">
583
            <xsl:for-each select="..">
584
              <xsl:number level="any"/>
585
            </xsl:for-each>
586
          </xsl:variable>
587
          <xsl:attribute name="w:id" select="number($N) + 50000"/>
588
          <xsl:if test="../@when">
589
            <xsl:attribute name="w:date">
590
              <xsl:value-of select="../@when"/>
591
            </xsl:attribute>
592
          </xsl:if>
593
          <w:r>
594
            <xsl:copy-of select="$rProps"/>
595
            <w:delText>
596
              <xsl:call-template name="Text"/>
597
            </w:delText>
598
          </w:r>
599
        </w:del>
600
      </xsl:when>
601
      <xsl:when test="parent::tei:add">
602
        <w:ins>
603
          <xsl:variable name="N">
604
            <xsl:for-each select="..">
605
              <xsl:number level="any"/>
606
            </xsl:for-each>
607
          </xsl:variable>
608
          <xsl:attribute name="w:id" select="number($N) + 50000"/>
609
          <xsl:if test="../@when">
610
            <xsl:attribute name="w:date">
611
              <xsl:value-of select="../@when"/>
612
            </xsl:attribute>
613
          </xsl:if>
614
          <w:r>
615
            <xsl:copy-of select="$rProps"/>
616
            <w:t>
617
              <xsl:call-template name="Text"/>
618
            </w:t>
619
          </w:r>
620
        </w:ins>
621
      </xsl:when>
622
      <xsl:otherwise>
623
        <w:r>
624
          <xsl:copy-of select="$rProps"/>
625
          <w:t>
626
            <xsl:call-template name="Text"/>
627
          </w:t>
628
        </w:r>
629
      </xsl:otherwise>
630
    </xsl:choose>
631
    <xsl:choose>
632
      <xsl:when test="ancestor::tei:head"/>
633
      <xsl:when test="ancestor::tei:bibl"/>
634
      <xsl:when test="following-sibling::text()"/>
635
      <xsl:when test="../@xml:id">
636
        <xsl:for-each select="..">
637
          <xsl:variable name="N">
638
            <xsl:number level="any"/>
639
          </xsl:variable>
640
          <w:bookmarkEnd w:id="{number($N) + 10000}"/>
641
        </xsl:for-each>
642
      </xsl:when>
643
      <xsl:when test="parent::tei:head/parent::tei:*/@xml:id">
644
        <xsl:for-each select="parent::tei:head/parent::tei:*">
645
          <xsl:variable name="N">
646
            <xsl:number level="any"/>
647
          </xsl:variable>
648
          <w:bookmarkEnd w:id="{number($N) + 10000}"/>
649
        </xsl:for-each>
650
      </xsl:when>
651
    </xsl:choose>
652
  </xsl:template>
653
  <xsl:template name="Text">
654
    <xsl:choose>
655
      <xsl:when test="parent::w:body">
656
        <xsl:message terminate="yes">CDATA found in body! [<xsl:value-of select="."/>]</xsl:message>
657
      </xsl:when>
658
      <xsl:otherwise>
659
        <xsl:variable name="out">
660
          <xsl:choose>
661
            <xsl:when test=".=' ' or ../@xml:space='preserve'">
662
              <xsl:value-of select="."/>
663
            </xsl:when>
664
            <xsl:otherwise>
665
              <xsl:if test="starts-with(.,' ') or starts-with(.,'&#10;')">
666
                <xsl:text> </xsl:text>
667
              </xsl:if>
668
              <xsl:value-of select="normalize-space(.)"/>
669
              <xsl:choose>
670
                <xsl:when test="substring(.,string-length(.),1)=' '">
671
                  <xsl:text> </xsl:text>
672
                </xsl:when>
673
                <xsl:when test="substring(.,string-length(.),1)='&#9;'">
674
                  <xsl:text> </xsl:text>
675
                </xsl:when>
676
                <xsl:when test="substring(.,string-length(.),1)='&#10;'">
677
                  <xsl:text> </xsl:text>
678
                </xsl:when>
679
              </xsl:choose>
680
              <xsl:if test="substring(.,string-length(.),1)='&#10;'">
681
                <xsl:text> </xsl:text>
682
              </xsl:if>
683
            </xsl:otherwise>
684
          </xsl:choose>
685
        </xsl:variable>
686
        <xsl:choose>
687
          <xsl:when test="contains($out,'ߛ')">
688
            <xsl:attribute name="xml:space">preserve</xsl:attribute>
689
            <xsl:value-of select="substring-before($out,'ߛ')"/>
690
            <w:noBreakHyphen/>
691
            <xsl:attribute name="xml:space">preserve</xsl:attribute>
692
            <xsl:value-of select="substring-after($out,'ߛ')"/>
693
          </xsl:when>
694
          <xsl:otherwise>
695
            <xsl:attribute name="xml:space">preserve</xsl:attribute>
696
            <xsl:value-of select="$out"/>
697
          </xsl:otherwise>
698
        </xsl:choose>
699
      </xsl:otherwise>
700
    </xsl:choose>
701
  </xsl:template>
702
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
703
    <desc>
704
        
705
            Style definition templates: 
706
            No default Style for any block or inline element
707
        
708
    </desc>
709
  </doc>
710
  <xsl:template match="*" mode="get-style"/>
711
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
712
    <desc> 
713
        to a given style name, this template returns the correct style id
714
        looking it up in styles.xml 
715
    </desc>
716
  </doc>
717
  <xsl:template name="getStyleName">
718
    <xsl:param name="in"/>
719
    <xsl:for-each select="document($styleDoc,/)">
720
      <xsl:for-each select="key('Styles',$in)">
721
        <xsl:value-of select="parent::w:style/@w:styleId"/>
722
      </xsl:for-each>
723
    </xsl:for-each>
724
  </xsl:template>
725
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
726
    <desc>
727
        Tests whether to add rendering elements to a run.
728
        Word styles cannot not be added in applyRend. If you want to add
729
        a style go for a get-style template. The order of these
730
	elements in Word does matter, by the way. 
731
     </desc>
732
  </doc>
733
  <xsl:template name="applyRend">
734
    <!-- use a custom font -->
735
    <xsl:choose>
736
      <xsl:when test="@iso:font">
737
        <w:rFonts w:ascii="{@iso:font}" w:hAnsi="{@iso:font}"/>
738
      </xsl:when>
739
      <!-- typewriter font -->
740
      <xsl:when test="contains(@rend,'typewriter') or tei:render-typewriter(.)">
741
        <w:rFonts w:ascii="Courier" w:hAnsi="Courier"/>
742
      </xsl:when>
743
      <xsl:when test="contains(@rend, 'Special') or matches(@iso:style,'font-family')">
744
        <xsl:call-template name="getStyleFonts">
745
          <xsl:with-param name="css" select="@iso:style"/>
746
        </xsl:call-template>
747
      </xsl:when>
748
      <xsl:when test="matches(parent::*/@iso:style,'font-family')">
749
        <xsl:call-template name="getStyleFonts">
750
          <xsl:with-param name="css" select="parent::*/@iso:style"/>
751
        </xsl:call-template>
752
      </xsl:when>
753
    </xsl:choose>
754
    <!-- bold -->
755
    <xsl:choose>
756
      <xsl:when test="tei:render-bold(.)">
757
        <w:b/>
758
      </xsl:when>
759
      <xsl:when test="self::tei:hi[not(@rend)]">
760
        <w:b/>
761
      </xsl:when>
762
      <xsl:when test="self::tbx:hi[@style='bold']">
763
        <w:i/>
764
      </xsl:when>
765
      <xsl:when test="contains(@rend,'bold')">
766
        <w:b/>
767
      </xsl:when>
768
      <xsl:when test="contains(@rend,'normalweight')">
769
        <w:b w:val="0"/>
770
      </xsl:when>
771
    </xsl:choose>
772
    <!-- italic -->
773
    <xsl:choose>
774
      <xsl:when test="tei:render-italic(.)">
775
        <w:i/>
776
      </xsl:when>
777
      <xsl:when test="self::tei:emph">
778
        <w:i/>
779
      </xsl:when>
780
      <xsl:when test="self::tbx:hi[@style='italics']">
781
        <w:i/>
782
      </xsl:when>
783
      <xsl:when test="self::tbx:hi[@style='it']">
784
        <w:i/>
785
      </xsl:when>
786
    </xsl:choose>
787
    <!-- small caps -->
788
    <xsl:if test="tei:render-smallcaps(.)">
789
      <w:smallCaps/>
790
    </xsl:if>
791
    <!-- all caps -->
792
    <xsl:if test="contains(@rend,'capsall')">
793
      <w:caps/>
794
    </xsl:if>
795
    <!-- strikethrough -->
796
    <xsl:choose>
797
      <xsl:when test="$renderAddDel='true' and ancestor-or-self::tei:del">
798
        <w:strike/>
799
      </xsl:when>
800
      <xsl:when test="contains(@rend,'strikethrough')">
801
        <w:strike/>
802
      </xsl:when>
803
      <xsl:when test="contains(@rend,'strikedoublethrough')">
804
        <w:dstrike/>
805
      </xsl:when>
806
    </xsl:choose>
807
    <!-- colour -->
808
    <xsl:choose>
809
      <xsl:when test="$renderAddDel='true' and ancestor-or-self::tei:add">
810
        <w:color w:val="{$addColour}"/>
811
      </xsl:when>
812
      <xsl:when test="contains(@rend,'color(')">
813
        <w:color w:val="{substring-before(substring-after(@rend,'color('),')')}"/>
814
      </xsl:when>
815
    </xsl:choose>
816
    <!-- background color -->
817
    <xsl:if test="contains(@rend,'background(')">
818
      <w:highlight w:val="{substring-before(substring-after(@rend,'background('),')')}"/>
819
    </xsl:if>
820
    <!-- underline -->
821
    <xsl:choose>
822
      <xsl:when test="contains(@rend,'underline') ">
823
        <w:u w:val="single"/>
824
      </xsl:when>
825
      <xsl:when test="contains(@rend,'underwavyline') ">
826
        <w:u w:val="wave"/>
827
      </xsl:when>
828
      <xsl:when test="contains(@rend,'underdoubleline')">
829
        <w:u w:val="double"/>
830
      </xsl:when>
831
    </xsl:choose>
832
    <!-- sub- and superscript -->
833
    <xsl:choose>
834
      <xsl:when test="contains(@iso:style,'position')">
835
        <w:position>
836
          <xsl:attribute name="w:val">
837
            <xsl:value-of select="normalize-space(substring-before((substring-after(@iso:style,'position:')),';'))"/>
838
          </xsl:attribute>
839
        </w:position>
840
      </xsl:when>
841
      <xsl:when test="self::tbx:hi[@style='subscript']">
842
        <w:vertAlign w:val="subscript"/>
843
      </xsl:when>
844
      <xsl:when test="contains(@rend,'subscript')">
845
        <w:vertAlign w:val="subscript"/>
846
      </xsl:when>
847
      <xsl:when test="contains(@rend,'sub')">
848
        <w:vertAlign w:val="subscript"/>
849
      </xsl:when>
850
    </xsl:choose>
851
    <xsl:choose>
852
      <xsl:when test="self::tbx:hi[@style='superscript']">
853
        <w:vertAlign w:val="superscript"/>
854
      </xsl:when>
855
      <xsl:when test="contains(@rend,'superscript')">
856
        <w:vertAlign w:val="superscript"/>
857
      </xsl:when>
858
      <xsl:when test="contains(@rend,'sup')">
859
        <w:vertAlign w:val="sup"/>
860
      </xsl:when>
861
    </xsl:choose>
862
    <!-- text direction -->
863
    <xsl:if test="@its:dir!=''">
864
      <!-- only handling RTL at the moment -->
865
      <xsl:if test="matches(@its:dir,'rtl')">
866
        <w:rtl/>
867
      </xsl:if>
868
    </xsl:if>
869
  </xsl:template>
870
  <!-- 
871
        Footnotes
872
    -->
873
  <xsl:template name="create-footnote">
874
    <xsl:variable name="num">
875
      <xsl:number count="tei:note[@place='foot' or @place='bottom' ]" level="any"/>
876
    </xsl:variable>
877
    <xsl:variable name="id" select="number($num)+1"/>
878
    <w:r>
879
      <w:rPr>
880
        <w:rStyle w:val="FootnoteReference"/>
881
      </w:rPr>
882
      <w:footnoteReference w:id="{$id}"/>
883
    </w:r>
884
    <w:r>
885
      <w:t xml:space="preserve"> </w:t>
886
    </w:r>
887
  </xsl:template>
888
  <xsl:template name="create-comment">
889
    <w:r>
890
      <w:rPr>
891
        <w:rStyle w:val="CommentReference"/>
892
        <w:vanish/>
893
      </w:rPr>
894
      <xsl:variable name="n">
895
        <xsl:number level="any" count="tei:note[@place='comment']"/>
896
      </xsl:variable>
897
      <w:commentReference w:id="{$n - 1}"/>
898
    </w:r>
899
  </xsl:template>
900
  <!-- 
901
        Endnotes
902
    -->
903
  <xsl:template name="create-endnote">
904
    <xsl:variable name="num">
905
      <xsl:number count="tei:note[@place='end']" level="any"/>
906
    </xsl:variable>
907
    <xsl:variable name="id" select="$num+1"/>
908
    <w:r>
909
      <w:rPr>
910
        <w:rStyle w:val="EndnoteReference"/>
911
        <w:noProof/>
912
      </w:rPr>
913
      <w:endnoteReference w:id="{$id}"/>
914
    </w:r>
915
    <w:r>
916
      <w:t xml:space="preserve"> </w:t>
917
    </w:r>
918
  </xsl:template>
919
  <!--
920
        Headers and Sections  
921
    -->
922
  <xsl:template match="tei:head[parent::tei:div or parent::tei:div1 or parent::tei:div2 or parent::tei:div3 or parent::tei:div4 or parent::tei:div5 or parent::tei:div6 or parent::tei:div7]">
923
    <xsl:param name="pPr"/>
924
    <!-- find out what level we are at -->
925
    <xsl:variable name="level">
926
      <xsl:value-of select="count(ancestor-or-self::tei:div| ancestor-or-self::tei:div1| ancestor-or-self::tei:div2| ancestor-or-self::tei:div3| ancestor-or-self::tei:div4| ancestor-or-self::tei:div5| ancestor-or-self::tei:div6| ancestor-or-self::tei:div7)"/>
927
    </xsl:variable>
928
    <xsl:variable name="number">
929
      <xsl:number level="any"/>
930
    </xsl:variable>
931
    <xsl:variable name="getstyle" select="tei:get-headingstyle(.,$level)"/>
932
    <xsl:call-template name="block-element">
933
      <!-- we want a bookmark for referencing this section -->
934
      <xsl:with-param name="bookmark-id">
935
        <xsl:value-of select="1000+$number"/>
936
      </xsl:with-param>
937
      <xsl:with-param name="bookmark-name">
938
        <xsl:choose>
939
          <xsl:when test="parent::tei:div/@xml:id">
940
            <xsl:value-of select="parent::tei:div/@xml:id"/>
941
          </xsl:when>
942
          <xsl:otherwise>
943
            <xsl:text>_SECTION_</xsl:text>
944
            <xsl:value-of select="1000+$number"/>
945
          </xsl:otherwise>
946
        </xsl:choose>
947
      </xsl:with-param>
948
      <!-- find the correct header style -->
949
      <xsl:with-param name="style">
950
        <xsl:choose>
951
          <xsl:when test="not($pPr  instance of xs:string)">
952
            <xsl:value-of select="$pPr/w:pPr/w:pStyle/@w:val"/>
953
          </xsl:when>
954
          <xsl:when test="string-length($getstyle) &gt; 0">
955
            <xsl:call-template name="getStyleName">
956
              <xsl:with-param name="in" select="$getstyle"/>
957
            </xsl:call-template>
958
          </xsl:when>
959
          <xsl:when test="parent::tei:div/parent::tei:back">
960
            <xsl:text>ANNEX</xsl:text>
961
          </xsl:when>
962
          <xsl:when test="ancestor::tei:back">
963
            <xsl:value-of select="concat('a',$level)"/>
964
          </xsl:when>
965
          <xsl:otherwise>
966
            <xsl:call-template name="getStyleName">
967
              <xsl:with-param name="in">
968
                <xsl:text>heading </xsl:text>
969
                <xsl:value-of select="$level"/>
970
              </xsl:with-param>
971
            </xsl:call-template>
972
          </xsl:otherwise>
973
        </xsl:choose>
974
      </xsl:with-param>
975
    </xsl:call-template>
976
  </xsl:template>
977
  <!-- quoted text; if it surrounds egXML, just pass on -->
978
  <xsl:template match="tei:q|tei:said|tei:soCalled">
979
    <xsl:choose>
980
      <xsl:when test="*[not(tei:is-inline(.))] or parent::tei:cit|parent::tei:div">
981
        <xsl:call-template name="block-element"/>
982
      </xsl:when>
983
      <xsl:when test="tei:l">
984
        <xsl:apply-templates/>
985
      </xsl:when>
986
      <xsl:otherwise>
987
        <w:r>
988
          <w:t>
989
            <xsl:value-of select="$preQuote"/>
990
          </w:t>
991
        </w:r>
992
        <xsl:apply-templates/>
993
        <w:r>
994
          <w:t>
995
            <xsl:value-of select="$postQuote"/>
996
          </w:t>
997
        </w:r>
998
      </xsl:otherwise>
999
    </xsl:choose>
1000
  </xsl:template>
1001
  <!-- 
1002
        GI
1003
    -->
1004
  <xsl:template match="tei:hi[@rend='specList-elementSpec']">
1005
    <xsl:apply-templates/>
1006
  </xsl:template>
1007
  <xsl:template match="tei:gi">
1008
    <w:r>
1009
      <w:t>&lt;</w:t>
1010
    </w:r>
1011
    <xsl:apply-templates/>
1012
    <w:r>
1013
      <w:t>&gt;</w:t>
1014
    </w:r>
1015
  </xsl:template>
1016
  <xsl:template match="tei:caesura">
1017
    <w:r>
1018
      <w:t>   </w:t>
1019
    </w:r>
1020
  </xsl:template>
1021
  <!-- 
1022
        Handle examples
1023
    -->
1024
  <xsl:template match="teix:egXML|tei:p[@rend='eg']">
1025
    <xsl:param name="simple">false</xsl:param>
1026
    <xsl:param name="highlight"/>
1027
    <xsl:call-template name="block-element">
1028
      <xsl:with-param name="select">
1029
        <tei:p rend="Special" iso:style="font-family:DejaVu Sans Mono; font-size:18; text-align:left;">
1030
          <xsl:call-template name="create-egXML-section"/>
1031
        </tei:p>
1032
      </xsl:with-param>
1033
    </xsl:call-template>
1034
  </xsl:template>
1035
  <xsl:template match="tei:eg">
1036
    <xsl:variable name="content">
1037
      <xsl:apply-templates select="*|processing-instruction()|comment()|text()" mode="egcopy"/>
1038
    </xsl:variable>
1039
    <xsl:for-each select="$content">
1040
      <xsl:call-template name="block-element">
1041
        <xsl:with-param name="style">Special</xsl:with-param>
1042
        <xsl:with-param name="select">
1043
          <tei:p rend="Special" iso:style="font-family:DejaVu Sans Mono; font-size:18;text-align:left;">
1044
            <xsl:copy-of select="*|processing-instruction()|comment()|text()"/>
1045
          </tei:p>
1046
        </xsl:with-param>
1047
      </xsl:call-template>
1048
    </xsl:for-each>
1049
  </xsl:template>
1050
  <xsl:template match="text()" mode="egcopy">
1051
    <xsl:for-each select="tokenize(.,'\n')">
1052
      <xsl:choose>
1053
        <xsl:when test="position()=last()">
1054
          <xsl:value-of select="."/>
1055
        </xsl:when>
1056
        <xsl:when test=".='' and position()=1">
1057
          <xsl:value-of select="."/>
1058
        </xsl:when>
1059
        <xsl:otherwise>
1060
          <xsl:value-of select="."/>
1061
          <tei:lb/>
1062
        </xsl:otherwise>
1063
      </xsl:choose>
1064
    </xsl:for-each>
1065
  </xsl:template>
1066
  <xsl:template match="@*|comment()|processing-instruction()" mode="egcopy">
1067
    <xsl:copy-of select="."/>
1068
  </xsl:template>
1069
  <xsl:template match="*" mode="egcopy">
1070
    <xsl:copy>
1071
      <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="egcopy"/>
1072
    </xsl:copy>
1073
  </xsl:template>
1074
  <!-- 
1075
        Handle TEI tables 
1076
    -->
1077
  <xsl:template match="tei:table">
1078
    <xsl:call-template name="table-body"/>
1079
    <xsl:call-template name="table-header"/>
1080
  </xsl:template>
1081
  <xsl:template name="table-body">
1082
    <w:tbl>
1083
      <xsl:choose>
1084
        <xsl:when test="w:tblPr">
1085
          <xsl:copy-of select="w:tblPr"/>
1086
        </xsl:when>
1087
        <xsl:when test="@rend='attDef'">
1088
          <w:tblPr>
1089
            <w:tblW w:w="0" w:type="auto"/>
1090
            <w:jc w:val="left"/>
1091
            <w:tblBorders>
1092
              <w:top w:val="nil" w:space="0" w:color="auto"/>
1093
              <w:left w:val="nil" w:space="0" w:color="auto"/>
1094
              <w:bottom w:val="nil" w:space="0" w:color="auto"/>
1095
              <w:right w:val="nil" w:space="0" w:color="auto"/>
1096
              <w:insideH w:val="nil" w:space="0" w:color="auto"/>
1097
              <w:insideV w:val="nil" w:space="0" w:color="auto"/>
1098
            </w:tblBorders>
1099
          </w:tblPr>
1100
        </xsl:when>
1101
        <xsl:when test="@rend='attList'">
1102
          <w:tblPr>
1103
            <w:tblW w:w="0" w:type="auto"/>
1104
            <w:jc w:val="left"/>
1105
            <w:tblBorders>
1106
              <w:top w:val="nil" w:space="0" w:color="auto"/>
1107
              <w:left w:val="nil" w:space="0" w:color="auto"/>
1108
              <w:bottom w:val="nil" w:space="0" w:color="auto"/>
1109
              <w:right w:val="nil" w:space="0" w:color="auto"/>
1110
              <w:insideH w:val="nil" w:space="0" w:color="auto"/>
1111
              <w:insideV w:val="nil" w:space="0" w:color="auto"/>
1112
            </w:tblBorders>
1113
          </w:tblPr>
1114
        </xsl:when>
1115
        <xsl:when test="@rend='norules'">
1116
          <w:tblPr>
1117
            <w:tblW w:w="0" w:type="auto"/>
1118
            <w:jc w:val="left"/>
1119
            <w:tblBorders>
1120
              <w:top w:val="nil" w:space="0" w:color="auto"/>
1121
              <w:left w:val="nil" w:space="0" w:color="auto"/>
1122
              <w:bottom w:val="nil" w:space="0" w:color="auto"/>
1123
              <w:right w:val="nil" w:space="0" w:color="auto"/>
1124
              <w:insideH w:val="nil" w:space="0" w:color="auto"/>
1125
              <w:insideV w:val="nil" w:space="0" w:color="auto"/>
1126
            </w:tblBorders>
1127
          </w:tblPr>
1128
        </xsl:when>
1129
        <xsl:when test="@rend='wovenodd'">
1130
          <w:tblPr>
1131
            <w:tblW w:w="0" w:type="auto"/>
1132
            <w:jc w:val="left"/>
1133
            <w:tblBorders>
1134
              <w:top w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1135
              <w:left w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1136
              <w:bottom w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1137
              <w:right w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1138
              <w:insideH w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1139
              <w:insideV w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1140
            </w:tblBorders>
1141
          </w:tblPr>
1142
        </xsl:when>
1143
        <xsl:otherwise>
1144
          <w:tblPr>
1145
            <w:tblW w:w="0" w:type="auto"/>
1146
            <w:jc w:val="center"/>
1147
            <w:tblBorders>
1148
              <w:top w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1149
              <w:left w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1150
              <w:bottom w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1151
              <w:right w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1152
              <w:insideH w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1153
              <w:insideV w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1154
            </w:tblBorders>
1155
          </w:tblPr>
1156
        </xsl:otherwise>
1157
      </xsl:choose>
1158
      <xsl:choose>
1159
        <xsl:when test="html:colgroup">
1160
          <w:tblGrid>
1161
            <xsl:for-each select="html:colgroup/html:col">
1162
              <w:gridCol w:w="{tei:convert-dim-pt20(@width)}"/>
1163
            </xsl:for-each>
1164
          </w:tblGrid>
1165
        </xsl:when>
1166
        <!-- if it is defined in word's namespace -->
1167
        <xsl:when test="w:tblGrid">
1168
          <xsl:copy-of select="w:tblGrid"/>
1169
        </xsl:when>
1170
        <xsl:otherwise>
1171
	  <xsl:variable name="maxcols" select="max(.//tei:row/count(tei:cell))"/>
1172
          <w:tblGrid>
1173
            <xsl:for-each select="1 to $maxcols">
1174
              <w:gridCol w:type="pct" w:w="{round((100 div $maxcols) *  50)}"/>
1175
            </xsl:for-each>
1176
          </w:tblGrid>
1177
        </xsl:otherwise>
1178
      </xsl:choose>
1179
      <xsl:apply-templates select="tei:row"/>
1180
    </w:tbl>
1181
    <w:p/>
1182
  </xsl:template>
1183
  <xsl:template name="table-header">
1184
    <xsl:if test="tei:head">
1185
      <xsl:variable name="number">
1186
        <xsl:number level="any"/>
1187
      </xsl:variable>
1188
      <xsl:for-each select="tei:head[1]">
1189
        <xsl:choose>
1190
          <xsl:when test="../@xml:id">
1191
            <xsl:call-template name="block-element">
1192
              <xsl:with-param name="style">Tabletitle</xsl:with-param>
1193
              <!-- we want a bookmark for referencing this table -->
1194
              <xsl:with-param name="bookmark-id">
1195
                <xsl:value-of select="1000+$number"/>
1196
              </xsl:with-param>
1197
              <xsl:with-param name="bookmark-name">
1198
                <xsl:value-of select="../@xml:id"/>
1199
              </xsl:with-param>
1200
            </xsl:call-template>
1201
          </xsl:when>
1202
          <xsl:otherwise>
1203
            <xsl:call-template name="block-element">
1204
              <xsl:with-param name="style">Tabletitle</xsl:with-param>
1205
            </xsl:call-template>
1206
          </xsl:otherwise>
1207
        </xsl:choose>
1208
      </xsl:for-each>
1209
    </xsl:if>
1210
  </xsl:template>
1211
  <xsl:template match="tei:row">
1212
    <w:tr>
1213
      <xsl:choose>
1214
        <xsl:when test="w:trPr">
1215
          <xsl:copy-of select="w:trPr"/>
1216
        </xsl:when>
1217
        <xsl:otherwise> </xsl:otherwise>
1218
      </xsl:choose>
1219
      <w:tblPrEx>
1220
        <w:tblLayout w:type="autofit"/>
1221
      </w:tblPrEx>
1222
      <xsl:apply-templates select="tei:cell"/>
1223
    </w:tr>
1224
  </xsl:template>
1225
  <xsl:template match="tei:cell">
1226
    <w:tc>
1227
      <xsl:choose>
1228
        <xsl:when test="w:tcPr">
1229
          <xsl:copy-of select="w:tcPr"/>
1230
        </xsl:when>
1231
        <xsl:otherwise>
1232
          <w:tcPr>
1233
            <!--w:tcW w:w="1915" w:type="dxa"/-->
1234
            <xsl:if test="@cols">
1235
              <w:gridSpan w:val="{@cols}"/>
1236
            </xsl:if>
1237
          </w:tcPr>
1238
        </xsl:otherwise>
1239
      </xsl:choose>
1240
      <xsl:choose>
1241
        <xsl:when test="tei:note">
1242
          <xsl:apply-templates/>
1243
        </xsl:when>
1244
        <xsl:otherwise>
1245
          <xsl:call-template name="block-element">
1246
            <xsl:with-param name="pPr">
1247
              <w:pPr>
1248
                <xsl:choose>
1249
                  <xsl:when test="@rend">
1250
                    <xsl:variable name="sName">
1251
                      <xsl:call-template name="getStyleName">
1252
                        <xsl:with-param name="in" select="@rend"/>
1253
                      </xsl:call-template>
1254
                    </xsl:variable>
1255
                    <xsl:choose>
1256
                      <xsl:when test="$sName=''">
1257
                        <w:pStyle w:val="{$TableText}"/>
1258
                      </xsl:when>
1259
                      <xsl:otherwise>
1260
                        <w:pStyle w:val="{$sName}"/>
1261
                      </xsl:otherwise>
1262
                    </xsl:choose>
1263
                  </xsl:when>
1264
                  <xsl:otherwise>
1265
                    <w:pStyle w:val="{$TableText}"/>
1266
                  </xsl:otherwise>
1267
                </xsl:choose>
1268
                <xsl:choose>
1269
                  <xsl:when test="@teidocx:align">
1270
                    <w:jc w:val="{@teidocx:align}"/>
1271
                  </xsl:when>
1272
                  <xsl:when test="parent::tei:row[@role='label']          or @role='label'">
1273
                    <w:jc w:val="left"/>
1274
                  </xsl:when>
1275
                  <xsl:when test="starts-with(.,'[0-9]')">
1276
                    <w:jc w:val="right"/>
1277
                  </xsl:when>
1278
                  <xsl:otherwise>
1279
                    <w:jc w:val="left"/>
1280
                  </xsl:otherwise>
1281
                </xsl:choose>
1282
              </w:pPr>
1283
            </xsl:with-param>
1284
          </xsl:call-template>
1285
        </xsl:otherwise>
1286
      </xsl:choose>
1287
      <!-- If we have no children, put an empty p here -->
1288
      <xsl:if test="not(descendant::text())">
1289
        <w:p>
1290
          <w:pPr>
1291
            <w:pStyle w:val="Tabletext9"/>
1292
          </w:pPr>
1293
          <w:r>
1294
            <w:t/>
1295
          </w:r>
1296
        </w:p>
1297
      </xsl:if>
1298
    </w:tc>
1299
  </xsl:template>
1300
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
1301
    <desc>Turn iso:style attribute back into Word styles for
1302
        table, or work out some defaults based on @rowsep and
1303
        @colsep</desc>
1304
  </doc>
1305
  <xsl:template name="calculateTableBorders">
1306
    <xsl:param name="htmlStyles"/>
1307
    <xsl:choose>
1308
      <xsl:when test="$htmlStyles!=''">
1309
        <xsl:for-each select="tokenize($htmlStyles,';')">
1310
          <xsl:variable name="val">
1311
            <xsl:value-of select="normalize-space(substring-after(.,':'))"/>
1312
          </xsl:variable>
1313
          <xsl:if test="matches(.,'border-top')">
1314
            <xsl:choose>
1315
              <xsl:when test="$val=0">
1316
                <w:top w:val="nil"/>
1317
              </xsl:when>
1318
              <xsl:otherwise>
1319
                <w:top w:val="single" w:sz="{$val}" w:space="0" w:color="auto"/>
1320
              </xsl:otherwise>
1321
            </xsl:choose>
1322
          </xsl:if>
1323
          <xsl:if test="matches(.,'border-left')">
1324
            <xsl:choose>
1325
              <xsl:when test="$val=0">
1326
                <w:left w:val="nil"/>
1327
              </xsl:when>
1328
              <xsl:otherwise>
1329
                <w:left w:val="single" w:sz="{$val}" w:space="0" w:color="auto"/>
1330
              </xsl:otherwise>
1331
            </xsl:choose>
1332
          </xsl:if>
1333
          <xsl:if test="matches(.,'border-bottom')">
1334
            <xsl:choose>
1335
              <xsl:when test="$val=0">
1336
                <w:bottom w:val="nil"/>
1337
              </xsl:when>
1338
              <xsl:otherwise>
1339
                <w:bottom w:val="single" w:sz="{$val}" w:space="0" w:color="auto"/>
1340
              </xsl:otherwise>
1341
            </xsl:choose>
1342
          </xsl:if>
1343
          <xsl:if test="matches(.,'border-right')">
1344
            <xsl:choose>
1345
              <xsl:when test="$val=0">
1346
                <w:right w:val="nil"/>
1347
              </xsl:when>
1348
              <xsl:otherwise>
1349
                <w:right w:val="single" w:sz="{$val}" w:space="0" w:color="auto"/>
1350
              </xsl:otherwise>
1351
            </xsl:choose>
1352
          </xsl:if>
1353
        </xsl:for-each>
1354
      </xsl:when>
1355
      <xsl:otherwise>
1356
        <xsl:if test="@rowsep='1' or (not(@rowsep ='0') and ancestor::cals:tgroup/@rowsep='1')">
1357
          <w:top w:val="single" w:sz="1"/>
1358
        </xsl:if>
1359
        <xsl:if test="@colsep='1' or (not(@colsep ='0') and ancestor::cals:tgroup/@colsep='1')">
1360
          <w:left w:val="single" w:sz="1"/>
1361
        </xsl:if>
1362
        <xsl:if test="@rowsep='1' or (not(@rowsep ='0') and ancestor::cals:tgroup/@rowsep='1')">
1363
          <w:bottom w:val="single" w:sz="1"/>
1364
        </xsl:if>
1365
        <xsl:if test="@colsep='1' or (not(@colsep ='0') and ancestor::cals:tgroup/@colsep='1')">
1366
          <w:right w:val="single" w:sz="1"/>
1367
        </xsl:if>
1368
      </xsl:otherwise>
1369
    </xsl:choose>
1370
  </xsl:template>
1371
  <!-- Handle CALS tables -->
1372
  <xsl:template match="cals:table">
1373
    <xsl:call-template name="tableheading-from-cals"/>
1374
    <w:tbl>
1375
      <w:tblPr>
1376
        <w:tblW>
1377
	  <xsl:choose>
1378
	    <xsl:when test="not($tableWidthPercentage='')">
1379
	      <xsl:attribute name="w:w">
1380
		<xsl:value-of  select="round(number($tableWidthPercentage)* 50)"/>
1381
	      </xsl:attribute>
1382
	      <xsl:attribute name="w:type">pct</xsl:attribute>
1383
	    </xsl:when>
1384
	    <xsl:otherwise>
1385
	      <xsl:attribute name="w:w">0</xsl:attribute>
1386
	      <xsl:attribute name="w:type">auto</xsl:attribute>
1387
	    </xsl:otherwise>
1388
	  </xsl:choose>
1389
	</w:tblW>
1390
        <w:jc w:val="center"/>
1391
        <w:tblBorders>
1392
          <xsl:variable name="tblBorders">
1393
            <xsl:call-template name="calculateTableBorders">
1394
              <xsl:with-param name="htmlStyles">
1395
                <xsl:value-of select="@iso:style"/>
1396
              </xsl:with-param>
1397
            </xsl:call-template>
1398
          </xsl:variable>
1399
          <xsl:choose>
1400
            <!-- only @frame turns borders on/off. If a
1401
		   border is 'on' *and* there is a corresponding 
1402
		   border in $tblBorders (ie created from
1403
		   info in iso:style) then the size from $tblBorders
1404
		   overrides the default size -->
1405
            <xsl:when test="@frame='none'">
1406
              <w:top w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1407
              <w:left w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1408
              <w:bottom w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1409
              <w:right w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1410
            </xsl:when>
1411
            <xsl:when test="@frame='top'">
1412
              <xsl:choose>
1413
                <xsl:when test="$tblBorders/w:top">
1414
                  <xsl:copy-of select="$tblBorders/w:top"/>
1415
                </xsl:when>
1416
                <xsl:otherwise>
1417
                  <w:top w:val="none" w:sz="6" w:space="0" w:color="auto"/>
1418
                </xsl:otherwise>
1419
              </xsl:choose>
1420
              <w:left w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1421
              <w:bottom w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1422
              <w:right w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1423
            </xsl:when>
1424
            <xsl:when test="@frame='bottom'">
1425
              <w:top w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1426
              <w:left w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1427
              <xsl:choose>
1428
                <xsl:when test="$tblBorders/w:bottom">
1429
                  <xsl:copy-of select="$tblBorders/w:bottom"/>
1430
                </xsl:when>
1431
                <xsl:otherwise>
1432
                  <w:bottom w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1433
                </xsl:otherwise>
1434
              </xsl:choose>
1435
              <w:right w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1436
            </xsl:when>
1437
            <xsl:when test="@frame='topbot'">
1438
              <xsl:choose>
1439
                <xsl:when test="$tblBorders/w:top">
1440
                  <xsl:copy-of select="$tblBorders/w:top"/>
1441
                </xsl:when>
1442
                <xsl:otherwise>
1443
                  <w:top w:val="none" w:sz="6" w:space="0" w:color="auto"/>
1444
                </xsl:otherwise>
1445
              </xsl:choose>
1446
              <w:left w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1447
              <xsl:choose>
1448
                <xsl:when test="$tblBorders/w:bottom">
1449
                  <xsl:copy-of select="$tblBorders/w:bottom"/>
1450
                </xsl:when>
1451
                <xsl:otherwise>
1452
                  <w:bottom w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1453
                </xsl:otherwise>
1454
              </xsl:choose>
1455
              <w:right w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1456
            </xsl:when>
1457
            <xsl:when test="@frame='sides'">
1458
              <w:top w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1459
              <xsl:choose>
1460
                <xsl:when test="$tblBorders/w:left">
1461
                  <xsl:copy-of select="$tblBorders/w:left"/>
1462
                </xsl:when>
1463
                <xsl:otherwise>
1464
                  <w:left w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1465
                </xsl:otherwise>
1466
              </xsl:choose>
1467
              <w:bottom w:val="none" w:sz="0" w:space="0" w:color="auto"/>
1468
              <xsl:choose>
1469
                <xsl:when test="$tblBorders/w:right">
1470
                  <xsl:copy-of select="$tblBorders/w:right"/>
1471
                </xsl:when>
1472
                <xsl:otherwise>
1473
                  <w:right w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1474
                </xsl:otherwise>
1475
              </xsl:choose>
1476
            </xsl:when>
1477
            <xsl:when test="@frame='all'">
1478
              <xsl:choose>
1479
                <xsl:when test="$tblBorders/w:top">
1480
                  <xsl:copy-of select="$tblBorders/w:top"/>
1481
                </xsl:when>
1482
                <xsl:otherwise>
1483
                  <w:top w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1484
                </xsl:otherwise>
1485
              </xsl:choose>
1486
              <xsl:choose>
1487
                <xsl:when test="$tblBorders/w:left">
1488
                  <xsl:copy-of select="$tblBorders/w:left"/>
1489
                </xsl:when>
1490
                <xsl:otherwise>
1491
                  <w:left w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1492
                </xsl:otherwise>
1493
              </xsl:choose>
1494
              <xsl:choose>
1495
                <xsl:when test="$tblBorders/w:bottom">
1496
                  <xsl:copy-of select="$tblBorders/w:bottom"/>
1497
                </xsl:when>
1498
                <xsl:otherwise>
1499
                  <w:bottom w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1500
                </xsl:otherwise>
1501
              </xsl:choose>
1502
              <xsl:choose>
1503
                <xsl:when test="$tblBorders/w:right">
1504
                  <xsl:copy-of select="$tblBorders/w:right"/>
1505
                </xsl:when>
1506
                <xsl:otherwise>
1507
                  <w:right w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1508
                </xsl:otherwise>
1509
              </xsl:choose>
1510
            </xsl:when>
1511
          </xsl:choose>
1512
          <xsl:choose>
1513
            <xsl:when test="@rowsep=1">
1514
              <w:insideH w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1515
            </xsl:when>
1516
            <xsl:otherwise>
1517
              <w:insideH w:val="none" w:sz="6" w:space="0" w:color="auto"/>
1518
            </xsl:otherwise>
1519
          </xsl:choose>
1520
          <xsl:choose>
1521
            <xsl:when test="@colsep=1">
1522
              <w:insideV w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1523
            </xsl:when>
1524
            <xsl:otherwise>
1525
              <w:insideV w:val="none" w:sz="6" w:space="0" w:color="auto"/>
1526
            </xsl:otherwise>
1527
          </xsl:choose>
1528
        </w:tblBorders>
1529
        <w:tblLayout w:type="fixed"/>
1530
      </w:tblPr>
1531
      <xsl:variable name="maxcols" select="max(.//cals:row/count(cals:entry))"/>
1532
      <xsl:choose>
1533
        <xsl:when test="cals:tgroup/cals:colspec">
1534
          <w:tblGrid>
1535
	    <xsl:variable name="totunits" select="sum(cals:tgroup/cals:colspec[ends-with(@colwidth,'*')]/number(substring-before(@colwidth,'*')))"/>
1536
            <xsl:for-each select="cals:tgroup/cals:colspec">
1537
              <w:gridCol>
1538
		  <xsl:choose>
1539
		    <!-- cell widths are specified in 50th of a percent -->
1540
		    <xsl:when test="ends-with(@colwidth,'*')">
1541
		      <xsl:attribute name="w:type">pct</xsl:attribute>
1542
		      <xsl:attribute name="w:w">
1543
			<xsl:value-of  select="round((number(substring-before(@colwidth,'*')) * 5000) div $totunits)"/>
1544
		      </xsl:attribute>
1545
		    </xsl:when>
1546
		    <xsl:otherwise>
1547
		      <xsl:attribute name="w:w">
1548
			<xsl:value-of select="tei:convert-dim-pt20(@colwidth)"/>
1549
		      </xsl:attribute>
1550
		    </xsl:otherwise>
1551
		  </xsl:choose>
1552
	      </w:gridCol>
1553
	    </xsl:for-each>
1554
          </w:tblGrid>
1555
        </xsl:when>
1556
        <xsl:otherwise>
1557
          <w:tblGrid>
1558
            <xsl:for-each select="1 to $maxcols">
1559
              <w:gridCol w:type="pct" w:w="{round((100 div $maxcols) *  50)}"/>
1560
            </xsl:for-each>
1561
          </w:tblGrid>
1562
        </xsl:otherwise>
1563
      </xsl:choose>
1564
      <xsl:apply-templates select="cals:tgroup"/>
1565
    </w:tbl>
1566
    <w:p/>
1567
  </xsl:template>
1568
  <xsl:template name="tableheading-from-cals">
1569
    <xsl:if test="cals:title">
1570
      <xsl:for-each select="cals:title[1]">
1571
        <w:p>
1572
          <w:pPr>
1573
            <w:pStyle>
1574
              <xsl:attribute name="w:val">Tabletitle</xsl:attribute>
1575
            </w:pStyle>
1576
          </w:pPr>
1577
          <xsl:if test="not(normalize-space(.)='')">
1578
            <w:r>
1579
              <w:t xml:space="preserve">— </w:t>
1580
            </w:r>
1581
          </xsl:if>
1582
          <xsl:apply-templates/>
1583
        </w:p>
1584
      </xsl:for-each>
1585
      <xsl:for-each select="preceding-sibling::tei:p[@rend='Table units']">
1586
        <w:p>
1587
          <w:pPr>
1588
            <w:pStyle>
1589
              <xsl:attribute name="w:val">Tableunits</xsl:attribute>
1590
            </w:pStyle>
1591
          </w:pPr>
1592
          <xsl:apply-templates/>
1593
        </w:p>
1594
      </xsl:for-each>
1595
    </xsl:if>
1596
  </xsl:template>
1597
  <xsl:template match="cals:tgroup">
1598
    <xsl:variable name="TABLE">
1599
      <xsl:copy>
1600
        <xsl:attribute name="iso:style">
1601
          <xsl:copy-of select="ancestor::cals:table/@iso:style"/>
1602
        </xsl:attribute>
1603
        <xsl:copy-of select="@*"/>
1604
        <xsl:copy-of select="cals:colspec"/>
1605
        <xsl:for-each select="cals:tbody|cals:thead">
1606
          <xsl:copy>
1607
            <xsl:for-each select="cals:row">
1608
              <xsl:copy>
1609
                <xsl:copy-of select="@*"/>
1610
                <xsl:for-each select="cals:entry">
1611
                  <xsl:copy>
1612
                    <xsl:copy-of select="@*"/>
1613
                    <xsl:apply-templates mode="contents" select="."/>
1614
                  </xsl:copy>
1615
                  <xsl:variable name="rows" select="@rowsep"/>
1616
                  <xsl:variable name="cols" select="@colsep"/>
1617
                  <xsl:choose>
1618
                    <xsl:when test="@namest and ancestor::cals:tgroup/cals:colspec[@colname=current()/@namest]">
1619
                      <xsl:variable name="start">
1620
                        <xsl:for-each select="ancestor::cals:tgroup/cals:colspec[@colname=current()/@namest]">
1621
                          <xsl:choose>
1622
                            <xsl:when test="@colnum">
1623
                              <xsl:value-of select="@colnum"/>
1624
                            </xsl:when>
1625
                            <xsl:otherwise>
1626
                              <xsl:number/>
1627
                            </xsl:otherwise>
1628
                          </xsl:choose>
1629
                        </xsl:for-each>
1630
                      </xsl:variable>
1631
                      <xsl:variable name="end">
1632
                        <xsl:for-each select="ancestor::cals:tgroup/cals:colspec[@colname=current()/@nameend]">
1633
                          <xsl:choose>
1634
                            <xsl:when test="@colnum">
1635
                              <xsl:value-of select="@colnum"/>
1636
                            </xsl:when>
1637
                            <xsl:otherwise>
1638
                              <xsl:number/>
1639
                            </xsl:otherwise>
1640
                          </xsl:choose>
1641
                        </xsl:for-each>
1642
                      </xsl:variable>
1643
                      <xsl:for-each select="ancestor::cals:tgroup/cals:colspec[position()&gt;$start and position()&lt;=$end]">
1644
                        <cals:entry DUMMY="true" colname="{@colname}" colsep="{$cols}" rowsep="{$rows}"/>
1645
                      </xsl:for-each>
1646
                    </xsl:when>
1647
                    <xsl:when test="@namest">
1648
                      <xsl:message terminate="yes">ERROR Column <xsl:value-of select="@namest"/> 
1649
				    <xsl:text> referenced with @namest attribute </xsl:text>
1650
				    <xsl:text>is not named in the list of  &lt;colspec&gt; elements for this table</xsl:text>
1651
				  </xsl:message>
1652
                    </xsl:when>
1653
                  </xsl:choose>
1654
                </xsl:for-each>
1655
              </xsl:copy>
1656
            </xsl:for-each>
1657
          </xsl:copy>
1658
        </xsl:for-each>
1659
      </xsl:copy>
1660
    </xsl:variable>
1661
    <!--
1662
	<xsl:variable name="count">
1663
	  <xsl:number level="any"/>
1664
	</xsl:variable>
1665
	  <xsl:result-document indent="yes" href="/tmp/T{$count}.xml">
1666
	    <xsl:copy-of select="$TABLE"/>
1667
	  </xsl:result-document>
1668
-->
1669
    <xsl:for-each select="$TABLE/cals:tgroup">
1670
      <xsl:apply-templates/>
1671
    </xsl:for-each>
1672
  </xsl:template>
1673
  <xsl:template match="cals:row">
1674
    <xsl:variable name="borders">
1675
      <xsl:if test="@colsep='1' or (not(@colsep ='0') and ancestor::cals:tgroup/@colsep='1')">
1676
        <w:left w:val="single" w:sz="1"/>
1677
      </xsl:if>
1678
    </xsl:variable>
1679
    <xsl:variable name="ROWPOS">
1680
      <xsl:number/>
1681
    </xsl:variable>
1682
    <xsl:variable name="TEMPLATE">
1683
      <xsl:for-each select="ancestor::cals:tgroup/cals:colspec">
1684
        <CELL name="{@colname}" num="{@colnum}" rowpos="{$ROWPOS}"/>
1685
      </xsl:for-each>
1686
    </xsl:variable>
1687
    <xsl:variable name="lastColnum">
1688
      <xsl:value-of select="ancestor::cals:tgroup/cals:colspec[last()]/@colnum"/>
1689
    </xsl:variable>
1690
    <xsl:variable name="lastColname">
1691
      <xsl:value-of select="ancestor::cals:tgroup/cals:colspec[last()]/@colname"/>
1692
    </xsl:variable>
1693
    <xsl:variable name="ME" select="."/>
1694
    <xsl:variable name="topEdge">
1695
      <xsl:choose>
1696
        <xsl:when test="parent::cals:tbody">
1697
          <xsl:if test="not(parent::cals:tbody/preceding-sibling::cals:thead/cals:row)">true</xsl:if>
1698
        </xsl:when>
1699
        <xsl:otherwise>
1700
          <xsl:if test="not(preceding-sibling::cals:row)">true</xsl:if>
1701
        </xsl:otherwise>
1702
      </xsl:choose>
1703
    </xsl:variable>
1704
    <xsl:variable name="bottomEdge">
1705
      <xsl:choose>
1706
        <xsl:when test="parent::cals:thead">
1707
          <xsl:if test="not(parent::cals:thead/following-sibling::cals:tbody/cals:row)">true</xsl:if>
1708
        </xsl:when>
1709
        <xsl:otherwise>
1710
          <xsl:if test="not(following-sibling::cals:row)">true</xsl:if>
1711
        </xsl:otherwise>
1712
      </xsl:choose>
1713
    </xsl:variable>
1714
    <w:tr>
1715
      <w:tblPrEx>
1716
        <w:tblLayout w:type="autofit"/>
1717
      </w:tblPrEx>
1718
      <xsl:for-each select="$TEMPLATE/CELL">
1719
        <xsl:variable name="N" select="@name"/>
1720
        <xsl:variable name="leftEdge">
1721
          <xsl:choose>
1722
            <xsl:when test="$N='c1' or $N='1'">true</xsl:when>
1723
            <xsl:when test="not(preceding-sibling::CELL)">true</xsl:when>
1724
          </xsl:choose>
1725
        </xsl:variable>
1726
        <xsl:variable name="rightEdge">
1727
          <xsl:choose>
1728
            <xsl:when test="not(following-sibling::CELL)">true</xsl:when>
1729
          </xsl:choose>
1730
        </xsl:variable>
1731
        <xsl:choose>
1732
          <xsl:when test="$ME/cals:entry[@colname=$N and @DUMMY='true']"/>
1733
          <xsl:when test="$ME/cals:entry[@colname=$N]">
1734
            <xsl:apply-templates select="$ME/cals:entry[@colname=$N]">
1735
              <xsl:with-param name="topEdge" select="$topEdge"/>
1736
              <xsl:with-param name="bottomEdge" select="$bottomEdge"/>
1737
              <xsl:with-param name="leftEdge" select="$leftEdge"/>
1738
              <xsl:with-param name="rightEdge" select="$rightEdge"/>
1739
            </xsl:apply-templates>
1740
          </xsl:when>
1741
          <xsl:otherwise>
1742
            <w:tc>
1743
              <w:tcPr>
1744
                <w:vMerge/>
1745
                <xsl:if test="$borders/w:left">
1746
                  <w:tcBorders>
1747
                    <xsl:copy-of select="$borders/w:left"/>
1748
                  </w:tcBorders>
1749
                </xsl:if>
1750
              </w:tcPr>
1751
              <w:p>    </w:p>
1752
            </w:tc>
1753
          </xsl:otherwise>
1754
        </xsl:choose>
1755
      </xsl:for-each>
1756
    </w:tr>
1757
  </xsl:template>
1758
  <xsl:template match="cals:entry">
1759
    <xsl:param name="topEdge"/>
1760
    <xsl:param name="bottomEdge"/>
1761
    <xsl:param name="leftEdge"/>
1762
    <xsl:param name="rightEdge"/>
1763
    <xsl:variable name="cellBorders">
1764
      <xsl:call-template name="calculateTableBorders">
1765
        <xsl:with-param name="htmlStyles">
1766
          <xsl:value-of select="@iso:style"/>
1767
        </xsl:with-param>
1768
      </xsl:call-template>
1769
    </xsl:variable>
1770
    <xsl:variable name="tableBorders">
1771
      <xsl:call-template name="calculateTableBorders">
1772
        <xsl:with-param name="htmlStyles">
1773
          <xsl:value-of select="ancestor::cals:tgroup/@iso:style"/>
1774
        </xsl:with-param>
1775
      </xsl:call-template>
1776
    </xsl:variable>
1777
    <xsl:variable name="colname" select="@colname"/>
1778
    <w:tc>
1779
      <w:tcPr>
1780
        <xsl:if test="@namest">
1781
          <xsl:variable name="start">
1782
            <xsl:for-each select="ancestor::cals:tgroup/cals:colspec[@colname=current()/@namest]">
1783
              <xsl:choose>
1784
                <xsl:when test="@colnum">
1785
                  <xsl:value-of select="@colnum"/>
1786
                </xsl:when>
1787
                <xsl:otherwise>
1788
                  <xsl:number/>
1789
                </xsl:otherwise>
1790
              </xsl:choose>
1791
            </xsl:for-each>
1792
          </xsl:variable>
1793
          <xsl:variable name="end">
1794
            <xsl:for-each select="ancestor::cals:tgroup/cals:colspec[@colname=current()/@nameend]">
1795
              <xsl:choose>
1796
                <xsl:when test="@colnum">
1797
                  <xsl:value-of select="@colnum"/>
1798
                </xsl:when>
1799
                <xsl:otherwise>
1800
                  <xsl:number/>
1801
                </xsl:otherwise>
1802
              </xsl:choose>
1803
            </xsl:for-each>
1804
          </xsl:variable>
1805
          <w:gridSpan w:val="{number($end)-number($start)+1}"/>
1806
        </xsl:if>
1807
        <xsl:if test="@morerows">
1808
          <w:vMerge w:val="restart"/>
1809
        </xsl:if>
1810
        <!--
1811
	    <xsl:message><xsl:value-of select="$colname"/>
1812
	    (<xsl:value-of select="."/>):    <xsl:value-of
1813
	    select="@rowsep"/> and <xsl:value-of
1814
	    select="parent::cals:row/preceding-sibling::cals:row[1]/cals:entry[@colname=$colname]/@rowsep"/></xsl:message>
1815
	    -->
1816
        <xsl:variable name="borders">
1817
          <!-- top border -->
1818
          <xsl:choose>
1819
            <xsl:when test="parent::cals:row/preceding-sibling::cals:row[1]/cals:entry[@colname=$colname]/@rowsep=0">
1820
              <w:top w:val="nil"/>
1821
            </xsl:when>
1822
            <xsl:when test="$topEdge='true'">
1823
              <!-- HERE -->
1824
              <xsl:if test="$tableBorders/w:top[@w:sz]">
1825
                <w:top w:val="single" w:sz="{$tableBorders/w:top/@w:sz}" w:space="0" w:color="auto"/>
1826
              </xsl:if>
1827
            </xsl:when>
1828
            <xsl:when test="@rowsep=0">
1829
              <w:top w:val="nil"/>
1830
            </xsl:when>
1831
            <xsl:when test="$cellBorders/w:top">
1832
              <xsl:copy-of select="$cellBorders/w:top"/>
1833
            </xsl:when>
1834
          </xsl:choose>
1835
          <!-- left border -->
1836
          <xsl:choose>
1837
            <xsl:when test="$leftEdge='true'">
1838
              <xsl:if test="$tableBorders/w:left[@w:sz]">
1839
                <w:left w:val="single" w:sz="{$tableBorders/w:left/@w:sz}" w:space="0" w:color="auto"/>
1840
              </xsl:if>
1841
            </xsl:when>
1842
            <xsl:when test="$cellBorders/w:left">
1843
              <xsl:copy-of select="$cellBorders/w:left"/>
1844
            </xsl:when>
1845
          </xsl:choose>
1846
          <!-- bottom border -->
1847
          <xsl:choose>
1848
            <xsl:when test="$bottomEdge='true'">
1849
              <xsl:if test="$tableBorders/w:bottom[@w:sz]">
1850
                <w:bottom w:val="single" w:sz="{$tableBorders/w:bottom/@w:sz}" w:space="0" w:color="auto"/>
1851
              </xsl:if>
1852
            </xsl:when>
1853
            <xsl:when test="@rowsep=0 or parent::cals:row/@rowsep=0">
1854
              <w:bottom w:val="nil"/>
1855
            </xsl:when>
1856
            <xsl:when test="@rowsep=1 or parent::cals:row/@rowsep=1">
1857
              <xsl:choose>
1858
                <xsl:when test="$cellBorders/w:bottom">
1859
                  <xsl:copy-of select="$cellBorders/w:bottom"/>
1860
                </xsl:when>
1861
                <xsl:otherwise>
1862
                  <w:bottom w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1863
                </xsl:otherwise>
1864
              </xsl:choose>
1865
            </xsl:when>
1866
          </xsl:choose>
1867
          <!-- right border -->
1868
          <xsl:choose>
1869
            <xsl:when test="following-sibling::cals:entry[1]/@colsep=0">
1870
              <w:right w:val="nil"/>
1871
            </xsl:when>
1872
            <xsl:when test="$rightEdge='true'">
1873
              <xsl:if test="$tableBorders/w:right[@w:sz]">
1874
                <w:right w:val="single" w:sz="{$tableBorders/w:right/@w:sz}" w:space="0" w:color="auto"/>
1875
              </xsl:if>
1876
            </xsl:when>
1877
            <xsl:when test="@colsep=0">
1878
              <w:right w:val="nil"/>
1879
            </xsl:when>
1880
            <xsl:when test="@colsep=1">
1881
              <xsl:choose>
1882
                <xsl:when test="$cellBorders/w:right">
1883
                  <xsl:copy-of select="$cellBorders/w:right"/>
1884
                </xsl:when>
1885
                <xsl:otherwise>
1886
                  <w:right w:val="single" w:sz="6" w:space="0" w:color="auto"/>
1887
                </xsl:otherwise>
1888
              </xsl:choose>
1889
            </xsl:when>
1890
          </xsl:choose>
1891
        </xsl:variable>
1892
        <xsl:if test="$borders/*">
1893
          <w:tcBorders>
1894
            <xsl:copy-of select="$borders/w:top"/>
1895
            <xsl:copy-of select="$borders/w:left"/>
1896
            <xsl:copy-of select="$borders/w:bottom"/>
1897
            <xsl:copy-of select="$borders/w:right"/>
1898
          </w:tcBorders>
1899
        </xsl:if>
1900
        <xsl:if test="@rotate='1'">
1901
          <w:textDirection w:val="btLr"/>
1902
        </xsl:if>
1903
        <xsl:if test="@valign">
1904
          <w:vAlign>
1905
            <xsl:attribute name="w:val">
1906
              <xsl:attribute name="valign">
1907
                <xsl:choose>
1908
                  <xsl:when test="@valign='middle'">center</xsl:when>
1909
                  <xsl:otherwise>
1910
                    <xsl:value-of select="@valign"/>
1911
                  </xsl:otherwise>
1912
                </xsl:choose>
1913
              </xsl:attribute>
1914
            </xsl:attribute>
1915
          </w:vAlign>
1916
        </xsl:if>
1917
      </w:tcPr>
1918
      <xsl:copy-of select="*"/>
1919
    </w:tc>
1920
  </xsl:template>
1921
  <xsl:template match="cals:entry" mode="contents">
1922
    <xsl:call-template name="block-element">
1923
      <xsl:with-param name="pPr">
1924
        <w:pPr>
1925
          <xsl:choose>
1926
            <xsl:when test="@rend">
1927
              <xsl:variable name="sName">
1928
                <xsl:call-template name="getStyleName">
1929
                  <xsl:with-param name="in" select="@rend"/>
1930
                </xsl:call-template>
1931
              </xsl:variable>
1932
              <xsl:choose>
1933
                <xsl:when test="$sName=''">
1934
                  <w:pStyle w:val="{$TableText}"/>
1935
                </xsl:when>
1936
                <xsl:otherwise>
1937
                  <w:pStyle w:val="{$sName}"/>
1938
                </xsl:otherwise>
1939
              </xsl:choose>
1940
            </xsl:when>
1941
            <xsl:otherwise>
1942
              <w:pStyle w:val="{$TableText}"/>
1943
            </xsl:otherwise>
1944
          </xsl:choose>
1945
          <xsl:choose>
1946
            <xsl:when test="@align">
1947
              <w:jc w:val="{@align}"/>
1948
            </xsl:when>
1949
            <xsl:when test="parent::tei:row[@role='label']    or @role='label'">
1950
              <w:jc w:val="left"/>
1951
            </xsl:when>
1952
            <xsl:when test="starts-with(.,'[0-9]')">
1953
              <w:jc w:val="right"/>
1954
            </xsl:when>
1955
            <xsl:otherwise>
1956
              <w:jc w:val="left"/>
1957
            </xsl:otherwise>
1958
          </xsl:choose>
1959
        </w:pPr>
1960
      </xsl:with-param>
1961
      <xsl:with-param name="nop">
1962
        <xsl:choose>
1963
          <xsl:when test="not(text()) and tei:note[(not(@place))]">true</xsl:when>
1964
          <!--NEN: next when commented to make footnotes in table possible-->
1965
          <!--<xsl:when test="not(text()) and tei:note[@place='foot']">true</xsl:when>-->
1966
	    <xsl:otherwise>false</xsl:otherwise>
1967
        </xsl:choose>
1968
      </xsl:with-param>
1969
    </xsl:call-template>
1970
    <!-- If we have no children, put an empty p here -->
1971
    <xsl:choose>
1972
      <xsl:when test="*"/>
1973
      <xsl:when test="text()"/>
1974
      <xsl:otherwise>
1975
        <w:p>
1976
          <w:pPr>
1977
            <w:pStyle w:val="Tabletext9"/>
1978
          </w:pPr>
1979
          <w:r>
1980
            <w:t/>
1981
          </w:r>
1982
        </w:p>
1983
      </xsl:otherwise>
1984
    </xsl:choose>
1985
  </xsl:template>
1986
  <!-- 
1987
	 Inline Templates:
1988
    -->
1989
  <xsl:template match="tei:g[@ref='x:tab']">
1990
    <w:r>
1991
      <w:tab/>
1992
    </w:r>
1993
  </xsl:template>
1994
  <xsl:template match="tei:c[@rend='ptab']">
1995
    <w:r>
1996
      <w:ptab w:relativeTo="margin" w:alignment="{@type}" w:leader="none"/>
1997
    </w:r>
1998
  </xsl:template>
1999
  <xsl:template match="tei:lb">
2000
    <w:r>
2001
      <w:br/>
2002
    </w:r>
2003
  </xsl:template>
2004
  <!-- hyperlink -->
2005
  <xsl:template match="tei:ptr">
2006
    <xsl:call-template name="linkMe">
2007
      <xsl:with-param name="anchor">
2008
        <xsl:choose>
2009
          <xsl:when test="@type='cit'">[</xsl:when>
2010
          <xsl:when test="@type='figure'">Figure </xsl:when>
2011
          <xsl:when test="@type='table'">Table </xsl:when>
2012
        </xsl:choose>
2013
        <xsl:choose>
2014
          <xsl:when test="starts-with(@target,'#')  and id(substring(@target,2))">
2015
            <xsl:variable name="target" select="substring(@target,2)"/>
2016
            <xsl:apply-templates select="id($target)" mode="xref"/>
2017
          </xsl:when>
2018
          <xsl:otherwise>
2019
            <xsl:value-of select="@target"/>
2020
          </xsl:otherwise>
2021
        </xsl:choose>
2022
        <xsl:choose>
2023
          <xsl:when test="@type='cit'">]</xsl:when>
2024
        </xsl:choose>
2025
      </xsl:with-param>
2026
    </xsl:call-template>
2027
  </xsl:template>
2028
  <xsl:template match="tei:ref[@target]">
2029
    <xsl:choose>
2030
      <xsl:when test="starts-with(@target,'#') and id(substring(@target,2))">
2031
        <xsl:call-template name="linkMe">
2032
          <xsl:with-param name="anchor">
2033
            <xsl:apply-templates/>
2034
          </xsl:with-param>
2035
        </xsl:call-template>
2036
      </xsl:when>
2037
      <xsl:otherwise>
2038
        <xsl:apply-templates/>
2039
      </xsl:otherwise>
2040
    </xsl:choose>
2041
  </xsl:template>
2042
  <xsl:template name="linkMeUsingHyperlink">
2043
    <xsl:param name="anchor"/>
2044
    <xsl:choose>
2045
      <xsl:when test="starts-with(@target,'#')">
2046
        <w:r>
2047
          <w:fldChar w:fldCharType="begin"/>
2048
        </w:r>
2049
        <w:r>
2050
          <w:instrText>HYPERLINK "<xsl:value-of select="@target"/>" \h</w:instrText>
2051
        </w:r>
2052
        <w:r>
2053
          <w:fldChar w:fldCharType="separate"/>
2054
        </w:r>
2055
        <w:r w:rsidR="00765EBE">
2056
          <w:rPr>
2057
            <w:rStyle w:val="Hyperlink"/>
2058
            <w:u w:val="none"/>
2059
            <xsl:if test="ancestor::tei:cell">
2060
              <w:sz w:val="18"/>
2061
            </xsl:if>
2062
          </w:rPr>
2063
          <w:t>
2064
            <xsl:copy-of select="$anchor"/>
2065
          </w:t>
2066
        </w:r>
2067
        <w:r>
2068
          <w:fldChar w:fldCharType="end"/>
2069
        </w:r>
2070
      </xsl:when>
2071
      <xsl:otherwise>
2072
        <xsl:variable name="rid">
2073
          <xsl:text>rId</xsl:text>
2074
          <xsl:variable name="n">
2075
            <xsl:number level="any"/>
2076
          </xsl:variable>
2077
          <xsl:value-of select="$n + 3000"/>
2078
        </xsl:variable>
2079
        <w:hyperlink r:id="{$rid}">
2080
          <w:r>
2081
            <w:rPr>
2082
              <w:rStyle w:val="Hyperlink"/>
2083
            </w:rPr>
2084
            <w:t>
2085
              <xsl:copy-of select="$anchor"/>
2086
            </w:t>
2087
          </w:r>
2088
        </w:hyperlink>
2089
      </xsl:otherwise>
2090
    </xsl:choose>
2091
  </xsl:template>
2092
  <xsl:template name="linkMe">
2093
    <xsl:param name="anchor"/>
2094
    <!-- create the field codes for the complex field -->
2095
    <!-- based on information in tei:ref/@tei:rend -->
2096
    <xsl:variable name="instrText">
2097
      <xsl:choose>
2098
        <xsl:when test="starts-with(@target,'#')">
2099
          <xsl:variable name="target" select="substring(@target,2)"/>
2100
          <xsl:variable name="rend" select="@rend"/>
2101
          <xsl:choose>
2102
            <xsl:when test="contains($rend,'noteref')">
2103
              <xsl:text>NOTEREF </xsl:text>
2104
            </xsl:when>
2105
            <xsl:otherwise>
2106
              <xsl:text>REF </xsl:text>
2107
            </xsl:otherwise>
2108
          </xsl:choose>
2109
          <xsl:value-of select="$target"/>
2110
          <xsl:for-each select="id($target)">
2111
            <xsl:choose>
2112
              <xsl:when test="contains($rend,'instr_')">
2113
                <xsl:if test="contains($rend,'instr_f')">
2114
                  <xsl:text> \f</xsl:text>
2115
                </xsl:if>
2116
                <xsl:if test="contains($rend,'instr_r')">
2117
                  <xsl:text> \r</xsl:text>
2118
                </xsl:if>
2119
                <xsl:if test="contains($rend,'instr_n')">
2120
                  <xsl:text> \n</xsl:text>
2121
                </xsl:if>
2122
              </xsl:when>
2123
              <xsl:when test="@type='refdoc'"/>
2124
              <xsl:otherwise>
2125
                <xsl:text> \n</xsl:text>
2126
              </xsl:otherwise>
2127
            </xsl:choose>
2128
          </xsl:for-each>
2129
          <xsl:text> \h</xsl:text>
2130
          <xsl:if test="contains(@rend,'mergeformat')">
2131
            <xsl:text> \* MERGEFORMAT</xsl:text>
2132
          </xsl:if>
2133
        </xsl:when>
2134
        <xsl:otherwise>
2135
          <xsl:text>HYPERLINK "</xsl:text>
2136
          <xsl:value-of select="@target"/>
2137
          <xsl:text>" \h</xsl:text>
2138
        </xsl:otherwise>
2139
      </xsl:choose>
2140
    </xsl:variable>
2141
    <w:r>
2142
      <w:fldChar w:fldCharType="begin"/>
2143
    </w:r>
2144
    <w:r>
2145
      <w:instrText>
2146
        <xsl:value-of select="$instrText"/>
2147
      </w:instrText>
2148
    </w:r>
2149
    <w:r>
2150
      <w:fldChar w:fldCharType="separate"/>
2151
    </w:r>
2152
    <w:r>
2153
      <xsl:variable name="rPr">
2154
        <xsl:apply-templates>
2155
          <xsl:with-param name="character-style" select="@iso:class"/>
2156
        </xsl:apply-templates>
2157
      </xsl:variable>
2158
      <w:rPr>
2159
        <xsl:if test="$rPr/w:r/w:rPr/w:rStyle/@w:val">
2160
          <w:rStyle w:val="{$rPr/w:r/w:rPr/w:rStyle/@w:val}"/>
2161
        </xsl:if>
2162
        <xsl:copy-of select="$anchor/w:r/w:rPr/*[not(self::w:rStyle)]"/>
2163
        <!-- oucs0037: why are we overriding special font styles??
2164
	       Comment this out for now! -->
2165
        <!--	  <xsl:if test="ancestor::tei:p[@rend='Special']">
2166
	    <w:rFonts w:ascii="Courier New" w:hAnsi="Courier New"/>
2167
	  </xsl:if> -->
2168
        <xsl:if test="$rPr/w:r/w:rPr/w:rStyle/@w:val='Hyperlink'">
2169
          <w:u w:val="none"/>
2170
        </xsl:if>
2171
      </w:rPr>
2172
      <xsl:choose>
2173
        <xsl:when test="$anchor/w:r">
2174
          <xsl:copy-of select="$anchor/w:r/w:t"/>
2175
        </xsl:when>
2176
        <xsl:otherwise>
2177
          <w:t>
2178
            <xsl:copy-of select="$anchor"/>
2179
          </w:t>
2180
        </xsl:otherwise>
2181
      </xsl:choose>
2182
    </w:r>
2183
    <w:r>
2184
      <w:fldChar w:fldCharType="end"/>
2185
    </w:r>
2186
  </xsl:template>
2187
  <xsl:template match="tei:bibl|tei:biblStruct" mode="xref">
2188
    <xsl:number/>
2189
  </xsl:template>
2190
  <xsl:template match="tei:note|tei:figure|tei:table|tei:item" mode="xref">
2191
    <xsl:number/>
2192
  </xsl:template>
2193
  <xsl:template match="tei:div" mode="xref">
2194
    <xsl:choose>
2195
      <xsl:when test="ancestor::tei:front">
2196
        <xsl:number count="tei:div" from="tei:front" format="i" level="multiple"/>
2197
      </xsl:when>
2198
      <xsl:when test="ancestor::tei:body">
2199
        <xsl:number count="tei:div" from="tei:body" format="1" level="multiple"/>
2200
      </xsl:when>
2201
      <xsl:when test="ancestor::tei:back">
2202
	   Annex <xsl:number count="tei:div" from="tei:back" format="A.1.1" level="multiple"/>
2203
         </xsl:when>
2204
    </xsl:choose>
2205
  </xsl:template>
2206
  <!-- 
2207
       §< Handle elements from different namespaces, such as wordML, wordMathML, MathML ...
2208
        -->
2209
  <xsl:template match="w:drawing">
2210
    <w:r>
2211
      <xsl:apply-templates select="." mode="iden"/>
2212
    </w:r>
2213
  </xsl:template>
2214
  <xsl:template match="iso:wordObject">
2215
    <xsl:apply-templates/>
2216
  </xsl:template>
2217
  <xsl:template match="w:*">
2218
    <xsl:if test="ancestor::w:tbl">
2219
      <xsl:copy>
2220
        <xsl:copy-of select="@*"/>
2221
        <xsl:apply-templates/>
2222
      </xsl:copy>
2223
    </xsl:if>
2224
  </xsl:template>
2225
  <xsl:template match="tei:titlePage">
2226
    <xsl:apply-templates/>
2227
  </xsl:template>
2228
  <xsl:template match="tei:docTitle/tei:titlePart[@type='main']">
2229
    <xsl:call-template name="block-element">
2230
      <xsl:with-param name="style">Title</xsl:with-param>
2231
    </xsl:call-template>
2232
  </xsl:template>
2233
  <xsl:template match="tei:docTitle/tei:titlePart[not(@type)]">
2234
    <xsl:call-template name="block-element">
2235
      <xsl:with-param name="style">Title</xsl:with-param>
2236
    </xsl:call-template>
2237
  </xsl:template>
2238
  <xsl:template match="tei:titlePage/tei:titlePart">
2239
    <xsl:call-template name="block-element">
2240
      <xsl:with-param name="style">Title</xsl:with-param>
2241
    </xsl:call-template>
2242
  </xsl:template>
2243
  <xsl:template match="tei:docTitle/tei:titlePart[@type='sub']">
2244
    <xsl:call-template name="block-element">
2245
      <xsl:with-param name="style">Subtitle</xsl:with-param>
2246
    </xsl:call-template>
2247
  </xsl:template>
2248
  <xsl:template match="tei:docTitle/tei:titlePart[2]" priority="99">
2249
    <xsl:call-template name="block-element">
2250
      <xsl:with-param name="style">Subtitle</xsl:with-param>
2251
    </xsl:call-template>
2252
  </xsl:template>
2253
  <xsl:template match="tei:titlePage/tei:docAuthor" priority="99">
2254
    <xsl:call-template name="block-element">
2255
      <xsl:with-param name="style">Author</xsl:with-param>
2256
    </xsl:call-template>
2257
  </xsl:template>
2258
  <xsl:template match="tei:titlePage/tei:byline" priority="99">
2259
    <xsl:call-template name="block-element">
2260
      <xsl:with-param name="style">Author</xsl:with-param>
2261
    </xsl:call-template>
2262
  </xsl:template>
2263
  <xsl:template match="tei:titlePage/tei:docDate" priority="99">
2264
    <xsl:call-template name="block-element">
2265
      <xsl:with-param name="style">Docdate</xsl:with-param>
2266
    </xsl:call-template>
2267
  </xsl:template>
2268
  <!-- place holders, used by ISO profile -->
2269
  <xsl:template name="getStyleFonts">
2270
    <xsl:param name="css"/>
2271
  </xsl:template>
2272
  <!-- no handling of index terms -->
2273
  <xsl:template match="tei:index"/>
2274
  <xsl:template name="applyRendition"/>
2275
  <xsl:template name="emphasize">
2276
    <xsl:param name="class"/>
2277
    <xsl:param name="content"/>
2278
    <w:r>
2279
      <xsl:choose>
2280
        <xsl:when test="$class='titlem'">
2281
          <w:rPr>
2282
            <w:i/>
2283
          </w:rPr>
2284
        </xsl:when>
2285
        <xsl:when test="$class='titlej'">
2286
          <w:rPr>
2287
            <w:i/>
2288
          </w:rPr>
2289
        </xsl:when>
2290
      </xsl:choose>
2291
      <w:t>
2292
        <xsl:attribute name="xml:space">preserve</xsl:attribute>
2293
        <xsl:choose>
2294
          <xsl:when test="$class='titles'">
2295
            <xsl:text>, </xsl:text>
2296
          </xsl:when>
2297
          <xsl:when test="$class='titleu'">
2298
            <xsl:text>‘</xsl:text>
2299
          </xsl:when>
2300
          <xsl:when test="$class='titlea'">
2301
            <xsl:text>‘</xsl:text>
2302
          </xsl:when>
2303
        </xsl:choose>
2304
        <xsl:value-of select="$content"/>
2305
        <xsl:choose>
2306
          <xsl:when test="$class='titleu'">
2307
            <xsl:text>’</xsl:text>
2308
          </xsl:when>
2309
          <xsl:when test="$class='titlea'">
2310
            <xsl:text>’</xsl:text>
2311
          </xsl:when>
2312
        </xsl:choose>
2313
      </w:t>
2314
    </w:r>
2315
  </xsl:template>
2316
  <!-- List Bibl -->
2317
  <xsl:template match="tei:listBibl">
2318
    <xsl:for-each select="tei:bibl|tei:biblStruct">
2319
      <xsl:choose>
2320
        <xsl:when test="@xml:id">
2321
          <xsl:variable name="number">
2322
            <xsl:number level="any"/>
2323
          </xsl:variable>
2324
          <xsl:call-template name="block-element">
2325
            <xsl:with-param name="style">Bibliography</xsl:with-param>
2326
            <xsl:with-param name="bookmark-id">
2327
              <xsl:value-of select="9000+$number"/>
2328
            </xsl:with-param>
2329
            <xsl:with-param name="bookmark-name">
2330
              <xsl:value-of select="@xml:id"/>
2331
            </xsl:with-param>
2332
          </xsl:call-template>
2333
        </xsl:when>
2334
        <xsl:otherwise>
2335
          <xsl:call-template name="block-element">
2336
            <xsl:with-param name="style">Bibliography</xsl:with-param>
2337
          </xsl:call-template>
2338
        </xsl:otherwise>
2339
      </xsl:choose>
2340
    </xsl:for-each>
2341
  </xsl:template>
2342
  <xsl:template name="tei:makeText">
2343
    <xsl:param name="letters"/>
2344
    <w:r>
2345
      <w:t>
2346
        <xsl:attribute name="xml:space">preserve</xsl:attribute>
2347
        <xsl:value-of select="$letters"/>
2348
      </w:t>
2349
    </w:r>
2350
  </xsl:template>
2351
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
2352
    <desc>
2353
	Page break
2354
      </desc>
2355
  </doc>
2356
  <xsl:template match="tei:pb">
2357
    <w:r>
2358
      <w:br w:type="page"/>
2359
    </w:r>
2360
  </xsl:template>
2361
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
2362
    <desc>
2363
        A signature block
2364
    </desc>
2365
  </doc>
2366
  <xsl:template match="tei:signed">
2367
    <xsl:call-template name="block-element">
2368
      <xsl:with-param name="style">teisigned</xsl:with-param>
2369
    </xsl:call-template>
2370
  </xsl:template>
2371
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
2372
    <desc>
2373
	If you meet an inline element with a link inside it, pass by
2374
	on the other side
2375
      </desc>
2376
  </doc>
2377
  <xsl:template match="tei:title[tei:ref]|tei:hi[tei:ref]" priority="-1">
2378
    <xsl:apply-templates/>
2379
  </xsl:template>
2380
  <xsl:template name="makeSpan">
2381
    <xsl:apply-templates/>
2382
  </xsl:template>
2383
  <xsl:template name="makeExternalLink">
2384
    <xsl:param name="ptr" as="xs:boolean" select="false()"/>
2385
    <xsl:param name="dest"/>
2386
    <xsl:value-of select="$dest"/>
2387
  </xsl:template>
2388
</xsl:stylesheet>