forked from oeuvres/odette
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathodt2tei.xsl
More file actions
1746 lines (1672 loc) · 71 KB
/
odt2tei.xsl
File metadata and controls
1746 lines (1672 loc) · 71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<!--
<h1>(Open Document Text) odt > TEI (<a href="./odt_tei.xsl">odt_tei.xsl</a>)</h1>
<p>Vous qui entrez, laissez toute espérance ! (de comprendre)</p>
LGPL http://www.gnu.org/licenses/lgpl.html
© 2005 ajlsm.com (Cybertheses)
© 2007 Frederic.Glorieux@fictif.org
© 2010 Frederic.Glorieux@fictif.org et École nationale des chartes
© 2012 Frederic.Glorieux@fictif.org
© 2013 Frederic.Glorieux@fictif.org et LABEX OBVIL
<p>
Cette transformation prend en entrée du XML OpenDocument (ex : OpenOffice.org),
et produit un TEI générique. L'insistance a porté sur la robustesse du filtre,
afin de réduire les reprises du stylage dans le traitements de textes (ex : styles utilisateur corrompus).
L'outil a été développé pour plusieurs éditions savantes (textes manuscrits, dictionnaires)
sur des fichiers tels qu'envoyés à l'imprimeur (sans modèles de documents, avec peu de stylage).
Il vise à terme la récupération de textes issus de numérisation avec mise en forme.
Le résultat XML est optimisé pour des normalisations ultérieures (regroupements, hiérarchies, de niveau caractères et paragraphes).
Cette transformation peut être branchée directement comme filtre d'export
OpenOffice, mais cet usage n'est pas le plus conseillé. Le processus est parfois
long, et peut échouer sans explication, notamment sur des fichiers importants. On tirera mieux parti de
la sortie en la traitant avec d'autres filtres (expressions régulières, XSLT).
</p>
<p lang="en-FR">
This transformation takes as input the OpenDocument XML (eg OpenOffice.org)
and produces a generic TEI. The emphasis is on the robustness of the filter,
to reduce rework the styling in the word processing (eg, user styles corrupted).
The tool was developped for different scholarly publications (manuscripts, dictionaries)
on files sent to the printing house (without templates, with few styling).
It aims to recover texts from scanning with formatting.
The XML output is optimized for subsequent normalization (grouping, hierarchy, on character and paragraph level).
This transformation can be plugged directly as an export filter in
OpenOffice, but this usage is not the most advisable. The process is sometimes
long, and may fail without explanation, especially on important files.
Best usage of output could be as an input for other filters (regular expressions, XSLT).
</p>
-->
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.tei-c.org/ns/1.0"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
xmlns:math="http://www.w3.org/1998/Math/MathML"
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
xmlns:ooo="http://openoffice.org/2004/office"
xmlns:ooow="http://openoffice.org/2004/writer"
xmlns:oooc="http://openoffice.org/2004/calc"
xmlns:dom="http://www.w3.org/2001/xml-events"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
xmlns:rpt="http://openoffice.org/2005/report"
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
xmlns:rdfa="http://docs.oasis-open.org/opendocument/meta/rdfa#"
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"
xmlns:odt2tei="odt:tei"
exclude-result-prefixes="tei odt2tei
office style text table draw fo xlink dc meta number svg chart dr3d math form script ooo ooow oooc dom xforms xsd xsi config rpt of rdfa field"
xmlns:exslt="http://exslt.org/common"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:php="http://php.net/xsl"
extension-element-prefixes="date exslt php"
>
<!-- office style text table draw fo xlink dc meta number svg chart dr3d math form script ooo ooow oooc dom xforms xsd xsi -->
<!-- Nécessaire pour libxml, assure encodage -->
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<!-- clé sur les styles -->
<xsl:key name="style" match="style:style|text:list-style" use="@style:name"/>
<xsl:key name="style-auto" match="office:automatic-styles/style:style|office:automatic-styles/text:list-style" use="@style:name"/>
<xsl:key name="list-style" match="text:list-style" use="@style:name"/>
<xsl:key name="p-style" match="odt2tei:style[@level='p']" use="@name"/>
<xsl:key name="c-style" match="odt2tei:style[@level='c']" use="@name"/>
<!-- Link to a style sheet with style name mapping with elements -->
<xsl:variable name="sheet" select="document('styles.xml', document(''))"/>
<!-- the filename processed, set by the caller -->
<xsl:param name="filename"/>
<xsl:param name="mediadir"/>
<xsl:variable name="dc">,author,bibl,created,creation,contributor,copyeditor,creator,date,edition,editor,idno,issued,keyword,licence,license,publie,publisher,secretairederedaction,source,subject,sujet,title,translator,</xsl:variable>
<xsl:variable name="lf"><xsl:text>
</xsl:text></xsl:variable>
<xsl:variable name="tab" select="'	'"/>
<xsl:variable name="ABC">ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÈÉÊËÌÍÎÏÐÑÒÓÔÕÖŒÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöùúûüýÿþ,; ?()/\ ._-</xsl:variable>
<xsl:variable name="abc">abcdefghijklmnopqrstuvwxyzaaaaaaeeeeeiiiidnoooooœuuuuybbaaaaaaaceeeeiiiionooooouuuuyyb</xsl:variable>
<xsl:variable name="lang">
<xsl:choose>
<xsl:when test="//style:style[@style:name='Standard']">
<xsl:value-of select="//style:style[@style:name='Standard']/style:text-properties/@fo:language"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="//@fo:language"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Shall we infer title from content ? -->
<xsl:variable name="h" select="//text:h[1]"/>
<!--
Be more precise than root, may catch the root of a nodeset() function
<xsl:template match="/"/>
-->
<xsl:template match="office:document">
<xsl:apply-templates select="office:document-content"/>
</xsl:template>
<!-- break here -->
<xsl:template match="office:scripts | office:font-face-decls | text:sequence-decls | office:forms | office:automatic-styles | office:settings | office:styles | office:master-styles "/>
<xsl:template match="office:document-content">
<xsl:if test="function-available('date:date-time')">
<xsl:comment>
<xsl:text>odt2tei: </xsl:text>
<xsl:value-of select="date:date-time()"/>
</xsl:comment>
</xsl:if>
<TEI xml:lang="{$lang}">
<!-- Pas une bonne idée, trop de renommage
<xsl:attribute name="xml:id">
<xsl:value-of select="$filename"/>
</xsl:attribute>
-->
<teiHeader/>
<xsl:apply-templates select="*"/>
</TEI>
</xsl:template>
<!-- Structure -->
<xsl:template match="office:meta">
<teiHeader>
<xsl:apply-templates select="*"/>
</teiHeader>
</xsl:template>
<!-- Conteneur -->
<xsl:template match="office:body">
<text>
<xsl:apply-templates select="*"/>
</text>
</xsl:template>
<!-- go throw, sections can break the tree of titles -->
<xsl:template match="text:section">
<xsl:variable name="cols" select="key('style', @text:style-name)/style:columns/@fo:column-count"/>
<xsl:comment>
<xsl:text>section=</xsl:text>
<xsl:value-of select="@text:name"/>
<xsl:if test="$cols and number($cols) > 1"> cols=<xsl:value-of select="$cols"/></xsl:if>
</xsl:comment>
<xsl:apply-templates/>
<xsl:comment>/section=<xsl:value-of select="@text:name"/></xsl:comment>
</xsl:template>
<!-- A counting template to produce inlines -->
<xsl:template name="divClose">
<xsl:param name="n"/>
<xsl:choose>
<xsl:when test="$n > 0">
<xsl:processing-instruction name="div">/</xsl:processing-instruction>
<xsl:call-template name="divClose">
<xsl:with-param name="n" select="$n - 1"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="divOpen">
<xsl:param name="n"/>
<xsl:choose>
<xsl:when test="$n > 0">
<xsl:processing-instruction name="div"/>
<xsl:call-template name="divOpen">
<xsl:with-param name="n" select="$n - 1"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- do not keep list items with headings -->
<xsl:template match="text:list[descendant::text:h] | text:list-item[descendant::text:h]">
<xsl:apply-templates/>
<!--
?? table:table[descendant::text:h] | table:table-row[descendant::text:h] | table:row[descendant::text:h] | table:table-cell[descendant::text:h] | table:cell[descendant::text:h]
-->
</xsl:template>
<!-- flat headings, producing hierarchical division, empty headings should have been washed before,
heaedings in notes will break things -->
<xsl:template match="text:h">
<xsl:variable name="style" select="key('style', @text:style-name | @class | @draw:style-name | @draw:text-style-name)"/>
<xsl:variable name="styleName">
<xsl:call-template name="styleName"/>
</xsl:variable>
<xsl:variable name="class">
<xsl:call-template name="class"/>
</xsl:variable>
<xsl:variable name="level" select="@text:outline-level"/>
<!-- Generate markers for div -->
<!-- close sections previously openened -->
<xsl:choose>
<xsl:when test="ancestor::table:table"/>
<xsl:when test="ancestor::text:note"/>
<xsl:otherwise>
<xsl:variable name="prev" select="preceding::text:h[1]/@text:outline-level"/>
<xsl:if test="$prev">
<xsl:call-template name="divClose">
<xsl:with-param name="n" select="1+ $prev - $level"/>
</xsl:call-template>
</xsl:if>
<xsl:call-template name="divOpen">
<xsl:with-param name="n" select="1"/>
</xsl:call-template>
<xsl:variable name="open">
<xsl:choose>
<xsl:when test="$prev">
<xsl:value-of select="$level - $prev - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$level - 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="divOpen">
<xsl:with-param name="n" select="$open"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<!-- Always one -->
<!-- Sometimes more -->
<xsl:variable name="xml">
<!-- Add page break.
@style:master-page-name
case encountered, seems logic, but not fully tested
<xsl:if test="$style//@fo:break-before='page' or key('style',$styleName )//@fo:break-before='page' or $style//@style:master-page-name or key('style',$styleName )//@style:master-page-name"><pb/></xsl:if>
-->
<head>
<xsl:choose>
<xsl:when test="$class = ''"/>
<xsl:when test="starts-with($class, 'heading')"/>
<xsl:when test="starts-with($class, 'titre')"/>
<xsl:otherwise>
<xsl:attribute name="type">
<xsl:value-of select="$class"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="start-value" select="/office:document/office:document-styles/office:styles/text:outline-style[@style:name='Outline']/text:outline-level-style[@text:level='1']/@text:start-value"/>
<xsl:if test="$start-value">
<xsl:variable name="n">
<xsl:number count="text:h[@text:outline-level = $level]" level="any"/>
</xsl:variable>
<xsl:attribute name="n">
<xsl:value-of select="$n - 1 + $start-value"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="flow"/>
</head>
</xsl:variable>
<!-- NO BORDER AROUND HEAD -->
<xsl:copy-of select="$xml"/>
</xsl:template>
<xsl:template match="text:page-number">
<pb n="{.}"/>
</xsl:template>
<!-- if office page break are gnificative, it is here -->
<xsl:template match="text:soft-page-break"/>
<!-- End of text, do not forget to close open <div> -->
<xsl:template match="office:text">
<body>
<!-- NO !
<xsl:call-template name="divOpen">
<xsl:with-param name="n" select="1"/>
</xsl:call-template>
-->
<xsl:apply-templates select="*"/>
<xsl:variable name="last" select="(.//text:h[not(ancestor::text:note|ancestor::table:table)])[last()]"/>
<xsl:call-template name="divClose">
<xsl:with-param name="n" select="$last/@text:outline-level"/>
</xsl:call-template>
</body>
</xsl:template>
<!-- Section générée -->
<xsl:template match="text:table-of-content | text:alphabetical-index | text:user-index">
<divGen>
<xsl:attribute name="type">
<xsl:choose>
<xsl:when test="self::text:table-of-content">toc</xsl:when>
<xsl:when test="self::text:alphabetical-index">index</xsl:when>
<xsl:when test="self::text:user-index">index</xsl:when>
<xsl:otherwise>
<xsl:value-of select="local-name()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</divGen>
</xsl:template>
<!--
<p>Paragraphes, le XML est préparé pour des étapes ultérieures de regroupements
(<i>paragraphs and grouping</i>).</p>
<ul>
<li>Vue
<blockquote>
<div>Citation</div>
<div><i>Quotations</i></div>
</blockquote>
</li>
<li>odt
<pre><text:p text:style-name="Quotations">Citation</text:p>
<text:p text:style-name="P13">Quotations</text:p></pre>
</li>
<li>odt_tei.xsl
<pre><quote><p>Citation</p></quote>
<quote><p>Quotations</p></quote></pre></li>
<li><code>s/<\/([^>]+)>\t(\n+)<\1>/$2/g</code></li>
<li>
<pre><quote>
<p>Citation</p>
<p>Quotations</p>
</quote></pre>
</li>
</ul>
<p>Regroupements (grouping)</p>
<ul>
<li>Encadré (<i>border</i>) : <figure></li>
<li>Texte Préformaté (<i>Preformated Text</i>) : <eg></li>
<li>Liste de termes (<i>Definition list</i>) : list/(label+,item)+. En-tête de liste (<i>List Heading</i>) : <label> ; Contenu de liste (<i>List Content</i>) : <item></li>
<li>Citation (<i>Quotations</i>) : <quote> ; </li>
</ul>
-->
<xsl:template match="text:p">
<xsl:param name="style-name" select="@text:style-name | @class | @draw:style-name | @draw:text-style-name"/>
<!-- handle on the current style -->
<xsl:variable name="style" select="key('style', $style-name)"/>
<!-- automatic style means local styling to output -->
<xsl:variable name="style-auto" select="key('style-auto', $style-name)"/>
<!-- Get a normalized class name (no spaces, no capitals…) -->
<xsl:variable name="classtest">
<xsl:call-template name="class">
<xsl:with-param name="string">
<xsl:call-template name="styleName"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="class">
<xsl:choose>
<!-- non semantic style names -->
<xsl:when test="starts-with($classtest, 'notedebasdepage')"/>
<xsl:when test="starts-with($classtest, 'corpsdutexte')"/>
<xsl:when test="$classtest = 'textbody'"/>
<xsl:when test="$classtest = 'standard'"/>
<xsl:when test="contains($classtest, 'list')"/>
<xsl:when test="parent::table:table-cell and $classtest = 'tablecontents'"/>
<xsl:when test="$classtest ='textformatvorlage'"/>
<xsl:when test="starts-with($classtest, 'normal')"/>
<xsl:when test="$classtest = 'footnotetext'"/>
<!-- Normalize style name -->
<xsl:otherwise>
<xsl:value-of select="$classtest"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- catch rendering information for non semantic style (supposed to be local styling) -->
<xsl:variable name="align">
<xsl:variable name="left" select="translate($style/style:paragraph-properties/@fo:margin-left, 'abcdefghijklmnopqrstuvwxyz ', '')"/>
<xsl:variable name="style2" select="key('style', $style/@style:parent-style-name)"/>
<xsl:choose>
<xsl:when test="not($style-auto)"/>
<!-- margin-left:0 different from parent style -->
<xsl:when test="$left > 0.1 and $style2/style:paragraph-properties/@fo:margin-left and not(starts-with($style2/style:paragraph-properties/@fo:margin-left, '0'))">outdent</xsl:when>
<xsl:when test="$left > 0.1">margin</xsl:when>
<xsl:when test="$style/style:paragraph-properties/@fo:text-align = 'end'">right</xsl:when>
<xsl:when test="$style/style:paragraph-properties/@fo:text-align = 'center'">center</xsl:when>
<xsl:when test="contains($class, 'centr') or contains($class, 'center')">center</xsl:when>
<xsl:when test="contains($class, 'droite') or contains($class, 'right')">right</xsl:when>
<!-- ? add noise or info ? to test
<xsl:when test="$style/style:paragraph-properties/@fo:text-align = 'start'">left</xsl:when>
-->
</xsl:choose>
</xsl:variable>
<!-- first line indent -->
<xsl:variable name="indent">
<xsl:variable name="n" select="translate($style/style:paragraph-properties/@fo:text-indent, 'abcdefghijklmnopqrstuvwxyz', '')"/>
<xsl:choose>
<xsl:when test="$class = 'l'"/>
<xsl:when test="$class = 'label'"/>
<xsl:when test="$class = 'quote'"/>
<xsl:when test="not($style-auto)"/>
<xsl:when test="not($style/style:paragraph-properties/@fo:text-indent)"/>
<xsl:when test="$n < -0.1">hanging</xsl:when>
<!--
<xsl:when test="$n > 0">indent</xsl:when>
-->
<!-- Shall we verify on parent if there is a difference ? -->
<xsl:when test="$n = 0">noindent</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="font">
<xsl:choose>
<xsl:when test="not($style-auto)"/>
<xsl:when test="$style/style:text-properties/@fo:font-style='italic' or $style/style:text-properties/@style:font-style-complex='italic'">i</xsl:when>
<xsl:when test="$style/style:text-properties/@fo:font-weight='bold' or $style/style:text-properties/@style:font-weight-complex='bold'">b</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="color">
<xsl:choose>
<xsl:when test="not($style-auto)"/>
<xsl:when test="not($style/style:text-properties/@fo:color)"/>
<xsl:when test="$style/style:text-properties/@fo:color='#000000'"></xsl:when>
<xsl:otherwise>
<xsl:text>color_</xsl:text>
<xsl:value-of select="substring($style/style:text-properties/@fo:color, 2)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="bg">
<xsl:variable name="bgcol" select="$style/style:text-properties/@fo:background-color"/>
<xsl:choose>
<xsl:when test="not($style-auto)"/>
<xsl:when test="not($bgcol)"/>
<xsl:when test="substring($bgcol, 2) = 'FFFFFF'"/>
<xsl:when test="substring($bgcol, 2) = 'ffffff'"/>
<xsl:when test="$bgcol='transparent'"/>
<xsl:otherwise>
<xsl:text>bg_</xsl:text>
<xsl:value-of select="substring($bgcol, 2)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="u">
<xsl:variable name="underline" select="($style/style:text-properties/@style:text-underline-style and $style/style:text-properties/@style:text-underline-style != 'none') or ($style/style:text-properties/@style:text-underline and $style/style:text-properties/@style:text-underline != 'none')"/>
<xsl:choose>
<xsl:when test="not($style-auto)"/>
<xsl:when test="$underline">u</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="sc">
<xsl:choose>
<xsl:when test="not($style-auto)"/>
<xsl:when test="$style/style:text-properties/@fo:font-variant = 'small-caps'">sc</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="border">
<xsl:call-template name="border"/>
</xsl:variable>
<xsl:variable name="rend" select="normalize-space(concat($align,' ',$indent,' ',$font,' ',$color,' ',$bg, ' ', $u, ' ', $sc))"/>
<xsl:variable name="key" select="translate(substring-before(., ':'), $ABC, $abc)"/>
<xsl:variable name="xml">
<xsl:choose>
<xsl:when test=".='' and (text:alphabetical-index-mark | text:alphabetical-index-mark-start | text:user-index-mark)">
<index>
<xsl:apply-templates select="text:alphabetical-index-mark | text:alphabetical-index-mark-start | text:user-index-mark"/>
</index>
</xsl:when>
<!-- No style para on first page with form key:value -->
<xsl:when test="not(preceding-sibling::text:h) and contains($dc, concat(',', $key, ','))">
<index>
<term type="{$key}">
<xsl:call-template name="flow"/>
</term>
</index>
</xsl:when>
<xsl:when test="$class = 'term'">
<xsl:if test=". != ''">
<index>
<term>
<xsl:if test="contains(., ':')">
<xsl:attribute name="type">
<xsl:value-of select="$key"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="flow"/>
</term>
</index>
</xsl:if>
</xsl:when>
<!-- something to do with a possible semantic class -->
<xsl:when test="$class != ''">
<xsl:variable name="mapping" select="$sheet/*/odt2tei:style[@level='p'][@name=$class]"/>
<xsl:choose>
<xsl:when test="$mapping[@parent]">
<xsl:variable name="element" select="normalize-space($mapping/@element)"/>
<xsl:element name="{$mapping/@parent}" namespace="http://www.tei-c.org/ns/1.0">
<xsl:element name="{$element}" namespace="http://www.tei-c.org/ns/1.0">
<xsl:call-template name="lang"/>
<xsl:if test="$mapping/@type">
<xsl:attribute name="type">
<xsl:value-of select="$mapping/@type"/>
</xsl:attribute>
</xsl:if>
<xsl:variable name="rend2">
<xsl:value-of select="$mapping/@rend"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$rend"/>
</xsl:variable>
<!-- local rendering of para -->
<xsl:if test=" normalize-space($rend2) != ''">
<xsl:attribute name="rend">
<xsl:value-of select="$rend2"/>
</xsl:attribute>
</xsl:if>
<!-- numbered line -->
<xsl:if test="$element = 'l' and ($style/style:paragraph-properties/@text:number-lines='true' or $class='ln') ">
<xsl:attribute name="n"/>
</xsl:if>
<xsl:call-template name="flow"/>
</xsl:element>
</xsl:element>
</xsl:when>
<!-- A style known as an element -->
<xsl:when test="$mapping[@element and @element!='']">
<xsl:variable name="element" select="normalize-space($mapping/@element)"/>
<xsl:element name="{$element}" namespace="http://www.tei-c.org/ns/1.0">
<xsl:call-template name="lang"/>
<xsl:if test="$mapping/@type">
<xsl:attribute name="type">
<xsl:value-of select="$mapping/@type"/>
</xsl:attribute>
</xsl:if>
<xsl:variable name="rend2">
<xsl:value-of select="$mapping/@rend"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$rend"/>
</xsl:variable>
<!-- local rendering of para -->
<xsl:if test=" normalize-space($rend2) != ''">
<xsl:attribute name="rend">
<xsl:value-of select="$rend2"/>
</xsl:attribute>
</xsl:if>
<!-- numbered line -->
<xsl:if test="$element = 'l' and ($style/style:paragraph-properties/@text:number-lines='true' or $class='ln')">
<xsl:attribute name="n"/>
</xsl:if>
<xsl:if test="$element='eg'">
<xsl:value-of select="$lf"/>
</xsl:if>
<!-- if verse, tab indentation maybe relevant -->
<!-- line group where verse are defined by line breaks -->
<xsl:if test="$element = 'lg'">
<xsl:text>
</xsl:text>
<lb type="lg"/>
</xsl:if>
<xsl:call-template name="flow"/>
<xsl:if test="$element = 'lg'">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:if test="$rend!='' or $class!=''">
<xsl:attribute name="rend">
<xsl:value-of select="normalize-space(concat($class,' ',$rend))"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="lang"/>
<xsl:call-template name="flow"/>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:if test="$rend!='' or $class!=''">
<xsl:attribute name="rend">
<xsl:value-of select="normalize-space(concat($class,' ',$rend))"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="lang"/>
<xsl:call-template name="flow"/>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<!-- be careful with empty paras -->
<xsl:when test="$border != ''">
<quote rend="border">
<xsl:copy-of select="$xml"/>
</quote>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$xml"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Template for flow content, especially to deal with mixed content -->
<xsl:template name="flow">
<xsl:apply-templates/>
</xsl:template>
<!-- titre dans une liste, peut contenir plusieurs paragraphes -->
<xsl:template match="text:list-header">
<argument>
<xsl:apply-templates/>
</argument>
</xsl:template>
<!--
Listes et tables
================
-->
<!-- liste -->
<xsl:template match="text:list">
<xsl:variable name="style-name" select="@text:style-name"/>
<xsl:variable name="level" select="count(ancestor-or-self::text:list)"/>
<!-- handle on the style -->
<xsl:variable name="list-level" select="key('list-style', $style-name)/*[@text:level=$level]"/>
<!-- Get the style of the item -->
<xsl:variable name="item-class">
<xsl:for-each select="text:list-item[1]">
<xsl:call-template name="class"/>
</xsl:for-each>
<xsl:text> </xsl:text>
<xsl:for-each select="text:list-item[1]/text:p[1]">
<xsl:call-template name="class"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="list">
<xsl:choose>
<!-- listBibl -->
<xsl:when test="starts-with(normalize-space($item-class), 'Bibl') or starts-with(normalize-space($item-class), 'bibl')">
<listBibl>
<xsl:apply-templates select="*"/>
</listBibl>
</xsl:when>
<xsl:otherwise>
<list>
<xsl:choose>
<xsl:when test="local-name($list-level) = 'list-level-style-bullet'">
<xsl:attribute name="type">ul</xsl:attribute>
</xsl:when>
<xsl:when test="local-name($list-level) = 'list-level-style-number'">
<xsl:attribute name="type">ol</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:if test="name($list-level)">
<xsl:variable name="rend" select="$list-level/@text:bullet-char | $list-level/@style:num-format"/>
<xsl:if test="translate($rend, '-–—oaI1A', '') = ''">
<xsl:attribute name="rend">
<xsl:value-of select="($list-level/@text:bullet-char | $list-level/@style:num-format)"/>
</xsl:attribute>
</xsl:if>
</xsl:if>
<xsl:apply-templates select="*"/>
</list>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Attraper le premier item pour voir s'il est encadré -->
<xsl:variable name="stylename" select="*//@text:style-name | *//@class | *//@draw:style-name | *//@draw:text-style-name"></xsl:variable>
<xsl:variable name="border">
<xsl:for-each select="text:list-item[1][count(*) = 1]/*[1]">
<xsl:call-template name="border"/>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="$border != ''">
<!-- No space before a border, to help future cleaning -->
<quote rend="border">
<xsl:copy-of select="$list"/>
</quote>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$list"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="border">
<!-- nom de style, peut être passé en paramètre -->
<xsl:param name="style-name" select="@text:style-name | @class | @draw:style-name | @draw:text-style-name"/>
<!-- poignée sur le style à explorer -->
<xsl:variable name="style" select="key('style', $style-name)"/>
<!-- Automatic style ? -->
<xsl:variable name="style-auto" select="key('style-auto', $style-name)"/>
<xsl:choose>
<!-- style de bordure annulé -->
<xsl:when test="contains($style/style:paragraph-properties/@fo:border, 'none')"/>
<xsl:when test="$style/style:paragraph-properties/@fo:border">
<xsl:value-of select="$style/style:paragraph-properties/@fo:border"/>
</xsl:when>
<!-- if not style auto, stop -->
<xsl:when test="not($style-auto)"/>
<!-- if style automatic, test ancestor -->
<xsl:when test="$style/@style:parent-style-name">
<xsl:variable name="class" select="key('style', $style/@style:parent-style-name)"/>
<xsl:if test="not (contains($class/style:paragraph-properties/@fo:border, 'none'))">
<xsl:value-of select="$class/style:paragraph-properties/@fo:border"/>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- item de liste -->
<xsl:template match="text:list-item">
<xsl:variable name="class">
<xsl:variable name="value">
<xsl:call-template name="class"/>
<xsl:for-each select="*[1]">
<xsl:text> </xsl:text>
<xsl:call-template name="class"/>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="normalize-space($value)"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="starts-with($class, 'bibl') or starts-with($class, 'Bibl')">
<bibl>
<xsl:choose>
<xsl:when test="count(*) = 1">
<xsl:apply-templates select="*/node()"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</bibl>
</xsl:when>
<xsl:otherwise>
<item>
<xsl:choose>
<xsl:when test="$class='corpsdetexte'"/>
<xsl:when test="$class='listcontents'"/>
<xsl:when test="$class='List_20_Contents'"/>
<xsl:when test="$class='normal'"/>
<xsl:when test="$class='paragraphedeliste'"/>
<xsl:when test="$class='textbody'"/>
<xsl:when test="$class='standard'"/>
<xsl:when test="$class='Standard'"/>
<xsl:when test="$class='Text_20_body'"/>
<xsl:otherwise>
<xsl:attribute name="rend">
<xsl:value-of select="$class"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="count(*) = 1">
<xsl:apply-templates select="*/node()"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</item>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- table -->
<xsl:template match="table:table">
<table>
<!--
table:name="Tableau1" table:style-name="Tableau1"
-->
<xsl:apply-templates select="node()"/>
</table>
</xsl:template>
<!-- Colonnes, rien -->
<xsl:template match="table:table-column | table:table-columns"/>
<!-- Lignes -->
<xsl:template match="table:table-row | table:row">
<xsl:param name="role"/>
<row>
<xsl:if test="$role != ''">
<xsl:attribute name="role">
<xsl:value-of select="$role"/>
</xsl:attribute>
</xsl:if>
<!--
<xsl:apply-templates select="@*"/>
table:style-name="Tableau1.2"
-->
<xsl:apply-templates/>
</row>
</xsl:template>
<!-- Cellules -->
<xsl:template match="table:table-cell | table:cell">
<cell>
<xsl:apply-templates select="@*"/>
<xsl:variable name="class">
<!-- pas encore vu de style sémantique
<xsl:value-of select="@table:style-name"/>
-->
<xsl:if test="@table:protected = true()"> protected</xsl:if>
<xsl:if test="count(descendant::text:p)=1">
<xsl:variable name="style">
<xsl:call-template name="class">
<xsl:with-param name="style-name" select="descendant::text:p/@text:style-name"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="normalize-space($style)=''"/>
<xsl:when test="$style='Table_20_Contents'"/>
<xsl:when test="$style='Table_20_Heading'"> label</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
<xsl:value-of select="$style"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:variable>
<xsl:if test="normalize-space($class) != ''">
<xsl:attribute name="rend">
<xsl:value-of select="normalize-space($class)"/>
</xsl:attribute>
</xsl:if>
<xsl:choose>
<!-- cellule vide, vu : des espaces insécables (?) -->
<xsl:when test="translate(normalize-space(.), ' ', '')= ''"/>
<!-- Un seul paragraphe -->
<xsl:when test="count(descendant::text:p)=1">
<xsl:choose>
<!--
<table:table-cell table:style-name="Tableau1.B2" office:value-type="string">
<text:p text:style-name="Table_20_Contents">
<text:span text:style-name="Police_20_par_20_défaut">
<text:span text:style-name="T36">La Gelosia</text:span>
</text:span>
</text:p>
</table:table-cell>
-->
<xsl:when test="count(descendant::text()[normalize-space(.) != '']) = 1">
<xsl:apply-templates select="descendant::text()[normalize-space(.) != '']"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="descendant::text:p/node()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</cell>
</xsl:template>
<xsl:template match="@office:value-type"/>
<xsl:template match="@office:value"/>
<xsl:template match="@table:number-columns-spanned">
<xsl:if test="number(.) > 1">
<xsl:attribute name="cols">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:if>
</xsl:template>
<xsl:template match="@table:number-rows-spanned">
<xsl:if test="number(.) > 1">
<xsl:attribute name="rows">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:if>
</xsl:template>
<xsl:template match="@table:style-name | @table:protected">
<!-- TODO, voir cas réels -->
</xsl:template>
<!-- Cellule vide provenant d'une fusion -->
<xsl:template match="table:covered-table-cell"/>
<!-- thead -->
<xsl:template match="table:table-header-rows">
<xsl:apply-templates>
<xsl:with-param name="role">label</xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<!-- Cadres de texte -->
<xsl:template match="draw:frame">
<xsl:choose>
<xsl:when test="ancestor::draw:frame">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<figure>
<xsl:apply-templates/>
</figure>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="draw:text-box">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="draw:plugin">
<ptr target="{@xlink:href}"/>
</xsl:template>
<!--
<h2>Format caractère (<i>char level</i>)</h2>
-->
<!--
<p>
Interpréter les styles et les mises en forme locales en éléments TEI courts
choisis pour faciliter des regroupements ultérieurs.
</p>
<p lang="en-FR">
Interpret the styles and local formatting in TEI short names,
to facilitate subsequent groupings.
</p>
<p>Exemple de regroupement <i>grouping sample</i></p>
<ul>
<li>Vue : <u>Le <i>Quixotte</i> au <span style="font-variant: small-caps">xix</span><sup>e</sup> siècle</u></li>
<li>odt xml : <text:span text:style-name="T18">Le </text:span> <text:span text:style-name="T3">Quixotte</text:span> <text:span text:style-name="T18"> au </text:span> <text:span text:style-name="T15">xix</text:span> <text:span text:style-name="T7">e</text:span> <text:span text:style-name="T18"> siècle</text:span></li>
<li>odt_tei.xsl : <title>Le </title><title><hi>Quixotte</hi></title><title> au </title><title><num>xix</num></title><title>ᵉ</title><title> siècle</title></li>
<li>s/<\/([^>]+)>( *)<\1>/$2/</li>
<li><title>Le <hi>Quixotte</hi> au <num>xix</num>ᵉ siècle</title></li>
</ul>
<p>Ordre d'imbrication des éléments générés (<i>nesting order of elements</i>)</p>
<ul>
<li><span style="background-color:#FFFFCC">Surlignage (<i>hilite</i>)</span> : <mark_{code-couleur}> </li>
<li>Style : <{style}></li>
<li><span style="color:red">Couleur (<i>color</i>)</span> : <color_{code-couleur}></li>
<li><u>Souligné (<i>underline</i>)</u> : <title> </li>
<li><b>gras (<i>bold</i>)</b> : <b> (<i>cf.</i> <a href="http://dev.w3.org/html5/spec/Overview.html#the-b-element"><html5:b></a> : <i> keywords</i>)</li>
<li><span style="letter-spacing:0.2ex">Lettres espacées (<i>letter spacing</i>)</span> : <phr> (expressions)</li>
<li><i>Italique (<i>italic</i>)</i> : <hi></li>
<li><span style="font-variant: small-caps">Petites capitales (<i>Small-Caps</i>)</span> : <name>, <num> (chiffres, notamment romains)</li>
<li><sup>Exposant <i>superscript</i></sup> et <sub>indice <i>subscript</i></sub> : unicode, <hi rend="sup">, <hi rend="sub"></li>
</ul>
-->
<xsl:template match="text:span">
<xsl:variable name="style-name" select="@text:style-name | @class | @draw:style-name | @draw:text-style-name"/>
<!-- poignée sur le style à explorer -->
<xsl:variable name="style" select="key('style', $style-name)"/>
<!-- nom de style automatique -->
<xsl:variable name="style-auto" select="key('style-auto', $style-name)"/>
<!-- Get a good semantic style name -->
<xsl:variable name="classtest">
<xsl:call-template name="class">
<xsl:with-param name="string">
<xsl:call-template name="styleName"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="class">
<xsl:choose>
<!-- non semantic style names -->
<xsl:when test="$classtest = 'footnotesymbol'"/>
<xsl:when test="starts-with($classtest, 'ww') or starts-with($classtest, 'normal') "/>
<xsl:when test="starts-with ($classtest, 'notedebasdepage')"/>
<xsl:when test="starts-with ($classtest, 'corpsdutexte')"/>
<xsl:when test="$classtest = 'mwheadline'"/>
<xsl:when test="$classtest = 'caracteresdenotedebasdepage'"/>
<xsl:when test="starts-with($classtest, 'policepardefaut')"/>
<xsl:when test="$classtest = 'footnotereference'"/>
<xsl:when test="$classtest = 'corpsdetextecar'"/>
<xsl:when test="$classtest = 'titre1car'"/>
<xsl:when test="$classtest = 'titre2car'"/>
<xsl:when test="$classtest = 'titre3car'"/>
<xsl:when test="$classtest = 'titre4car'"/>
<!-- Normalize style name -->
<xsl:otherwise>
<xsl:value-of select="$classtest"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="text-position" select="$style/style:text-properties/@style:text-position"/>