-
Notifications
You must be signed in to change notification settings - Fork 6
/
docx2indesign.xsl
2815 lines (2716 loc) · 160 KB
/
docx2indesign.xsl
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"?><!--
Microsoft Word Document -> HTML -> InDesign
(InDesign Module)
Created: September 30, 2021
Modified: April 1, 2023
Author: Roland Dreger, www.rolanddreger.net
# Notes
## InDesign Import
For InDesign import use indent="no" in <xsl:output> in this stylesheet and
deactivate option »Do Not Import Contents Of Whitespace-Only Elements«
in InDesign XML import settings.
Otherwise, there may be problems with text wrap in cells
with multiple paragraphs. (
)
## Document Resources
InDesign sometimes crashes with copy-of therefore the construct
document($document-file-name) that always exits instead of
xsl:choose and xsl:copy-of for global paramerters
--><xsl:transform xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:cusp="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:extp="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:rd="http://www.rolanddreger.net" xmlns:rel="http://schemas.openxmlformats.org/package/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="rd pkg wpc cx cx1 cx2 cx3 cx4 cx5 cx6 cx7 cx8 mc aink am3d o r rel m v wp14 wp w10 w w14 w15 w16cex w16cid w16 w16sdtdh w16se wpg wpi wne wps cp extp cusp vt dc dcterms dcmitype dcmitype a pic xsi b" version="1.0">
<!-- ++++++++++++ --><!-- + Settings + --><!-- ++++++++++++ --><!-- Document Namespace --><!-- Comments for Complex Fields, Tab, ... --><!-- Tab Character --><!-- Values: 'extended' or 'minimized'. If minimized, ignore all local overrides (without tags, only via class) except: strong, i, em, u, superscript, subscript --><!-- Heading Style Map --><xsl:param name="h1-paragraph-style-names" select="''"/><!-- e.g. '»Custom_Name_1« »Custom_Name_1.1«' --><xsl:param name="h2-paragraph-style-names" select="''"/><!-- e.g. 'Custom_Name_2' --><xsl:param name="h3-paragraph-style-names" select="''"/><xsl:param name="h4-paragraph-style-names" select="''"/><xsl:param name="h5-paragraph-style-names" select="''"/><xsl:param name="h6-paragraph-style-names" select="''"/><!-- Heading Marker --><xsl:variable name="heading-marker" select="'-Heading-'"/><!-- Heading Font Sizes --><xsl:param name="h1-font-size" select="0"/><!-- e.g. 28 or 28.5 or 0 --><xsl:param name="h2-font-size" select="0"/><xsl:param name="h3-font-size" select="0"/><xsl:param name="h4-font-size" select="0"/><xsl:param name="h5-font-size" select="0"/><xsl:param name="h6-font-size" select="0"/><!-- Case conversion --><xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ'"/><xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ'"/><!-- +++++++++ --><!-- + INPUT + --><!-- +++++++++ --><!-- Folder and File Paths --><!-- an empty string is passed if input is a Word-XML-Document. --><!-- document.xml or name of Word-XML-Document --><!-- If image folder path is defined, all images get the path according to this pattern: $image-folder-path + '/' + $image-name --><!-- docProps/core.xml --><!-- word/styles.xml --><!-- word/numbering.xml --><!-- word/footnotes.xml --><!-- word/endnotes.xml --><!-- word/comments.xml --><!-- word/_rels/document.xml.rels --><!-- word/_rels/footnotes.xml.rels --><!-- word/_rels/endnotes.xml.rels --><!-- Core Properties (Metadata) --><!-- Styles --><!-- Numbering --><!-- Document Relationships (e.g. Hyperlinks) --><!-- Footnotes --><!-- Footnote Relationships --><!-- Endnotes --><!-- Endnote Relationships --><!-- Comments --><!-- Citations --><!-- ++++++++++ --><!-- + OUTPUT + --><!-- ++++++++++ --><!-- Output tag and attribute names --><xsl:variable name="heading-tag-name" select="'h'"/><xsl:variable name="list-item-tag-name" select="'li'"/><xsl:variable name="table-column-group-tag-name" select="'colgroup'"/><xsl:variable name="table-column-tag-name" select="'col'"/><xsl:variable name="table-row-tag-name" select="'tr'"/><xsl:variable name="table-cell-column-span-attribute-name" select="'colspan'"/><xsl:variable name="table-cell-row-span-attribute-name" select="'rowspan'"/><xsl:variable name="table-header-cell-tag-name" select="'th'"/><xsl:variable name="table-header-cell-scope-attribute-name" select="'scope'"/><xsl:variable name="bold-tag-name" select="'strong'"/><xsl:variable name="italics-tag-name" select="'i'"/><xsl:variable name="emphasis-mark-tag-name" select="'em'"/><xsl:variable name="underline-tag-name" select="'u'"/><xsl:variable name="subscript-tag-name" select="'sub'"/><xsl:variable name="superscript-tag-name" select="'sup'"/><xsl:variable name="section-break-type-attribute-name" select="'data-wrap-type'"/><!-- Spaces --><!-- +++++++++++++ --><!-- + Templates + --><!-- +++++++++++++ --><!-- Head --><xsl:template name="create-head-section">
<xsl:element name="head" namespace="{$ns}">
<xsl:element name="meta" namespace="{$ns}">
<xsl:attribute name="charset">UTF-8</xsl:attribute>
</xsl:element>
<xsl:element name="meta" namespace="{$ns}">
<xsl:attribute name="name">
<xsl:value-of select="'viewport'"/>
</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="'width=device-width, initial-scale=1'"/>
</xsl:attribute>
</xsl:element>
<xsl:element name="title" namespace="{$ns}">
<xsl:value-of select="$core-props/dc:title"/>
</xsl:element>
<xsl:element name="meta" namespace="{$ns}">
<xsl:attribute name="name">
<xsl:value-of select="'author'"/>
</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="$core-props/dc:creator"/>
</xsl:attribute>
</xsl:element>
<xsl:element name="meta" namespace="{$ns}">
<xsl:attribute name="name">
<xsl:value-of select="'keywords'"/>
</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="$core-props/cp:keywords"/>
</xsl:attribute>
</xsl:element>
<xsl:element name="meta" namespace="{$ns}">
<xsl:attribute name="name">
<xsl:value-of select="'description'"/>
</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="$core-props/dc:description"/>
</xsl:attribute>
</xsl:element>
<xsl:element name="meta" namespace="{$ns}">
<xsl:attribute name="name">
<xsl:value-of select="'generator'"/>
</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="'Stylesheet'"/>
</xsl:attribute>
</xsl:element>
<xsl:element name="meta" namespace="{$ns}">
<xsl:attribute name="property">
<xsl:value-of select="'created'"/>
</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="$core-props/dcterms:created"/>
</xsl:attribute>
</xsl:element>
<xsl:element name="meta" namespace="{$ns}">
<xsl:attribute name="property">
<xsl:value-of select="'modified'"/>
</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="$core-props/dcterms:modified"/>
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template><!-- Body --><xsl:template name="create-body-section">
<xsl:element name="body" namespace="{$ns}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template><xsl:template match="pkg:package">
<xsl:apply-templates select="pkg:part[@pkg:name='/word/document.xml']/pkg:xmlData/w:document"/> <!-- for Word XML Document (single XML file) -->
</xsl:template><xsl:template match="w:document">
<xsl:apply-templates/>
</xsl:template><!-- Structure paragraphs (e.g. lists) --><xsl:template name="structure-paragraphs">
<xsl:param name="target-elements"/>
<xsl:choose>
<!-- Check: Are there any (list) elements? -->
<xsl:when test="not($target-elements/w:pPr/w:numPr)">
<xsl:apply-templates select="$target-elements"/>
</xsl:when>
<!-- Check: List elements only? -->
<xsl:when test="not($target-elements[not(w:pPr/w:numPr)])">
<xsl:call-template name="create-html-list">
<xsl:with-param name="list-elements" select="$target-elements"/>
<xsl:with-param name="prev-level" select="-1"/>
</xsl:call-template>
</xsl:when>
<!-- Check: First element is list element? -->
<xsl:when test="$target-elements[1]/w:pPr/w:numPr">
<xsl:variable name="num-of-following-elements" select="count($target-elements[not(w:pPr/w:numPr)][1]/following-sibling::*) + 1"/>
<xsl:variable name="num-of-list-elements" select="count($target-elements) - $num-of-following-elements"/>
<xsl:call-template name="create-html-list">
<xsl:with-param name="list-elements" select="$target-elements[position() <= $num-of-list-elements]"/>
<xsl:with-param name="prev-level" select="-1"/>
</xsl:call-template>
<xsl:call-template name="structure-paragraphs">
<xsl:with-param name="target-elements" select="$target-elements[position() > $num-of-list-elements]"/>
</xsl:call-template>
</xsl:when>
<!-- The first element is not a list element, but there are! -->
<xsl:otherwise>
<xsl:variable name="num-of-following-elements" select="count($target-elements[w:pPr/w:numPr][1]/following-sibling::*) + 1"/>
<xsl:variable name="num-of-non-list-elements" select="count($target-elements) - $num-of-following-elements"/>
<xsl:apply-templates select="$target-elements[position() <= $num-of-non-list-elements]"/>
<xsl:call-template name="structure-paragraphs">
<xsl:with-param name="target-elements" select="$target-elements[position() > $num-of-non-list-elements]"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- HTML list --><!--
Level (@w:ilvl = 0)
. Level (@w:ilvl = 1)
.. Level (@w:ilvl = 2)
...
--><xsl:template name="create-html-list">
<xsl:param name="list-elements"/>
<xsl:param name="prev-level"/>
<xsl:variable name="first-element" select="$list-elements[1]"/>
<xsl:variable name="cur-level" select="$first-element/w:pPr/w:numPr/w:ilvl/@w:val"/>
<xsl:variable name="first-lower-level-element" select="$list-elements[w:pPr/w:numPr/w:ilvl/@w:val > $cur-level][1]"/>
<xsl:variable name="lower-level" select="$first-lower-level-element/w:pPr/w:numPr/w:ilvl/@w:val"/>
<xsl:variable name="first-diff-level-element" select="$list-elements[w:pPr/w:numPr/w:ilvl/@w:val != $cur-level][1]"/>
<xsl:variable name="first-following-cur-level-element" select="$first-lower-level-element/following-sibling::*[w:pPr/w:numPr/w:ilvl/@w:val = $cur-level][1]"/>
<xsl:variable name="num-of-first-cur-level-elements" select="count($first-diff-level-element/preceding-sibling::*) - count($first-element/preceding-sibling::*)"/>
<xsl:variable name="num-of-first-lower-level-elements" select="count($first-following-cur-level-element/preceding-sibling::*) - count($first-lower-level-element/preceding-sibling::*)"/>
<!-- Element name for current level -->
<xsl:variable name="first-num-id" select="$first-element/w:pPr/w:numPr/w:numId/@w:val"/>
<xsl:variable name="first-abstract-num-id" select="$numbering/w:num[@w:numId = $first-num-id]/w:abstractNumId/@w:val"/>
<xsl:variable name="first-num-format" select="$numbering/w:abstractNum[@w:abstractNumId = $first-abstract-num-id]/w:lvl[@w:ilvl = $cur-level]/w:numFmt/@w:val"/>
<xsl:variable name="cur-level-list-tag-name">
<xsl:call-template name="get-list-tag-name">
<xsl:with-param name="num-format" select="$first-num-format"/>
</xsl:call-template>
</xsl:variable>
<!-- Element name for lower level -->
<xsl:variable name="first-lower-level-num-id" select="$first-lower-level-element/w:pPr/w:numPr/w:numId/@w:val"/>
<xsl:variable name="first-lower-level-abstract-num-id" select="$numbering/w:num[@w:numId = $first-lower-level-num-id]/w:abstractNumId/@w:val"/>
<xsl:variable name="first-lower-level-num-format" select="$numbering/w:abstractNum[@w:abstractNumId = $first-lower-level-abstract-num-id]/w:lvl[@w:ilvl = $lower-level]/w:numFmt/@w:val"/>
<xsl:variable name="lower-level-list-tag-name">
<xsl:call-template name="get-list-tag-name">
<xsl:with-param name="num-format" select="$first-lower-level-num-format"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<!-- Check: Any different levels at first run? -->
<xsl:when test="not($first-diff-level-element) and $prev-level = -1">
<xsl:element name="{$cur-level-list-tag-name}" namespace="{$ns}">
<!-- List Attributes -->
<xsl:call-template name="insert-list-attributes">
<xsl:with-param name="id" select="$first-num-id"/>
</xsl:call-template>
<!-- List Items -->
<xsl:for-each select="$list-elements">
<xsl:element name="{$list-item-tag-name}" namespace="{$ns}">
<!-- List Item Attributes -->
<xsl:call-template name="insert-list-item-attributes">
<xsl:with-param name="level" select="$cur-level"/>
</xsl:call-template>
<!-- Liste Item Content -->
<xsl:apply-templates select="."/> <!-- omit paragraph tag: mode="content-only" -->
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:when>
<!-- Check: First run with different levels? -->
<xsl:when test="$prev-level = -1">
<xsl:element name="{$cur-level-list-tag-name}" namespace="{$ns}">
<!-- List Attributes -->
<xsl:call-template name="insert-list-attributes">
<xsl:with-param name="id" select="$first-num-id"/>
</xsl:call-template>
<!-- List Content -->
<xsl:call-template name="create-html-list">
<xsl:with-param name="list-elements" select="$list-elements"/>
<xsl:with-param name="prev-level" select="$cur-level"/>
</xsl:call-template>
</xsl:element>
</xsl:when>
<!-- Check: Any lower level elements with following current level elements? -->
<xsl:when test="$first-lower-level-element and $first-following-cur-level-element">
<!-- List Items -->
<xsl:for-each select="$list-elements[position() < $num-of-first-cur-level-elements]">
<xsl:element name="{$list-item-tag-name}" namespace="{$ns}">
<!-- List Item Attributes -->
<xsl:call-template name="insert-list-item-attributes">
<xsl:with-param name="level" select="$cur-level"/>
</xsl:call-template>
<!-- Liste Item Content -->
<xsl:apply-templates select="."/> <!-- omit paragraph tag: mode="content-only" -->
</xsl:element>
</xsl:for-each>
<!-- List Item -->
<xsl:element name="{$list-item-tag-name}" namespace="{$ns}">
<!-- List Item Attributes -->
<xsl:call-template name="insert-list-item-attributes">
<xsl:with-param name="level" select="$cur-level"/>
</xsl:call-template>
<!-- List Item Content -->
<xsl:apply-templates select="$list-elements[position() = $num-of-first-cur-level-elements]"/> <!-- omit paragraph tag: mode="content-only" -->
<!-- Nested List Element (lower Level) -->
<xsl:element name="{$lower-level-list-tag-name}" namespace="{$ns}">
<!-- List Attributes -->
<xsl:call-template name="insert-list-attributes">
<xsl:with-param name="id" select="$first-lower-level-num-id"/>
</xsl:call-template>
<!-- List Content -->
<xsl:call-template name="create-html-list">
<xsl:with-param name="list-elements" select="$list-elements[position() > $num-of-first-cur-level-elements and position() <= ($num-of-first-cur-level-elements + $num-of-first-lower-level-elements)]"/>
<xsl:with-param name="prev-level" select="$cur-level"/>
</xsl:call-template>
</xsl:element>
</xsl:element>
<!-- Remaining Elements (same Level) -->
<xsl:call-template name="create-html-list">
<xsl:with-param name="list-elements" select="$list-elements[position() > ($num-of-first-cur-level-elements + $num-of-first-lower-level-elements)]"/>
<xsl:with-param name="prev-level" select="$cur-level"/>
</xsl:call-template>
</xsl:when>
<!-- Check: Any lower level elements with NO following current level elements? -->
<xsl:when test="$first-lower-level-element and not($first-following-cur-level-element)">
<!-- List Items -->
<xsl:for-each select="$list-elements[position() < $num-of-first-cur-level-elements]">
<xsl:element name="{$list-item-tag-name}" namespace="{$ns}">
<!-- List Item Attributes -->
<xsl:call-template name="insert-list-item-attributes">
<xsl:with-param name="level" select="$cur-level"/>
</xsl:call-template>
<!-- List Item Content -->
<xsl:apply-templates select="."/> <!-- omit paragraph tag: mode="content-only" -->
</xsl:element>
</xsl:for-each>
<!-- List Item -->
<xsl:element name="{$list-item-tag-name}" namespace="{$ns}">
<!-- List Item Attributes -->
<xsl:call-template name="insert-list-item-attributes">
<xsl:with-param name="level" select="$cur-level"/>
</xsl:call-template>
<!-- List Item Content -->
<xsl:apply-templates select="$list-elements[position() = $num-of-first-cur-level-elements]"/> <!-- omit paragraph tag: mode="content-only" -->
<!-- Nested List Element (lower Level) -->
<xsl:element name="{$lower-level-list-tag-name}" namespace="{$ns}">
<!-- List Attributes -->
<xsl:call-template name="insert-list-attributes">
<xsl:with-param name="id" select="$first-lower-level-num-id"/>
</xsl:call-template>
<!-- List Content -->
<xsl:call-template name="create-html-list">
<xsl:with-param name="list-elements" select="$list-elements[position() > $num-of-first-cur-level-elements]"/>
<xsl:with-param name="prev-level" select="$cur-level"/>
</xsl:call-template>
</xsl:element>
</xsl:element>
</xsl:when>
<!-- The boring rest -->
<xsl:otherwise>
<!-- List Items -->
<xsl:for-each select="$list-elements">
<xsl:element name="{$list-item-tag-name}" namespace="{$ns}">
<!-- List Item Attributes -->
<xsl:call-template name="insert-list-item-attributes">
<xsl:with-param name="level" select="$cur-level"/>
</xsl:call-template>
<!-- List Item Content -->
<xsl:apply-templates select="."/> <!-- omit paragraph tag: mode="content-only" -->
</xsl:element>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- Tag name for List Element --><xsl:template name="get-list-tag-name">
<xsl:param name="num-format" select="''"/>
<xsl:choose>
<xsl:when test="not($num-format) or $num-format = 'bullet' or $num-format ='none'">
<xsl:text>ul</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>ol</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- Attributes for List Element (ol, ul) --><!-- Attribute for List Item Element --><xsl:template name="insert-list-item-attributes">
<xsl:param name="level" select="''"/>
<!-- Level -->
<xsl:attribute name="{$list-item-level-attribute-name}">
<xsl:value-of select="$level"/>
</xsl:attribute>
</xsl:template><!-- Paragraph --><!-- Paragraph content (without container element) --><!--
<xsl:template match="w:p" mode="content-only">
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="*"/>
</xsl:call-template>
</xsl:template>
--><!-- Tag Name for Paragraph (h1, h2, ..., li, p) --><xsl:template name="get-paragraph-tag-name">
<xsl:param name="target-element" select="."/>
<xsl:variable name="paragraph-style-id" select="$target-element/w:pPr/w:pStyle/@w:val"/>
<xsl:variable name="paragraph-style-name">
<xsl:call-template name="get-style-name">
<xsl:with-param name="style-id" select="$paragraph-style-id"/>
<xsl:with-param name="style-type" select="'paragraph'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="heading-level">
<xsl:choose>
<!-- Heading: Default WordML Name -->
<xsl:when test="starts-with($paragraph-style-name, 'heading')">
<xsl:variable name="heading-level-string" select="substring-after($paragraph-style-name, 'heading')"/>
<xsl:variable name="heading-level-number" select="number($heading-level-string)"/>
<xsl:choose>
<xsl:when test="$heading-level-number">
<xsl:value-of select="$heading-level-number"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- Heading: User Paragraph Name (H1, H2, H3, H4, H5, H6) -->
<xsl:when test=" translate($paragraph-style-name, 'H ', 'h') = 'h1' or translate($paragraph-style-name, 'H ', 'h') = 'h2' or translate($paragraph-style-name, 'H ', 'h') = 'h3' or translate($paragraph-style-name, 'H ', 'h') = 'h4' or translate($paragraph-style-name, 'H ', 'h') = 'h5' or translate($paragraph-style-name, 'H ', 'h') = 'h6' ">
<xsl:value-of select="number(substring-after(translate($paragraph-style-name, 'H','h'), 'h'))"/>
</xsl:when>
<!-- Heading: User Paragraph Name with $heading-marker -->
<xsl:when test="contains($paragraph-style-name, $heading-marker)">
<xsl:value-of select="number(substring-after(translate($paragraph-style-name, 'h','H'), $heading-marker))"/>
</xsl:when>
<!-- Heading: User Paragraph Name in $h1-paragraph-style-names -->
<xsl:when test="boolean($h1-paragraph-style-names)">
<xsl:choose>
<xsl:when test="($h1-paragraph-style-names = $paragraph-style-name or (contains($h1-paragraph-style-names, concat('»', $paragraph-style-name, '«'))))">
<xsl:value-of select="1"/>
</xsl:when>
<xsl:when test="($h2-paragraph-style-names = $paragraph-style-name or (contains($h2-paragraph-style-names, concat('»', $paragraph-style-name, '«'))))">
<xsl:value-of select="2"/>
</xsl:when>
<xsl:when test="($h3-paragraph-style-names = $paragraph-style-name or (contains($h3-paragraph-style-names, concat('»', $paragraph-style-name, '«'))))">
<xsl:value-of select="3"/>
</xsl:when>
<xsl:when test="($h4-paragraph-style-names = $paragraph-style-name or (contains($h4-paragraph-style-names, concat('»', $paragraph-style-name, '«'))))">
<xsl:value-of select="4"/>
</xsl:when>
<xsl:when test="($h5-paragraph-style-names = $paragraph-style-name or (contains($h5-paragraph-style-names, concat('»', $paragraph-style-name, '«'))))">
<xsl:value-of select="5"/>
</xsl:when>
<xsl:when test="($h6-paragraph-style-names = $paragraph-style-name or (contains($h6-paragraph-style-names, concat('»', $paragraph-style-name, '«'))))">
<xsl:value-of select="6"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- Heading: Defined Font Size (last in chain) -->
<xsl:when test="$h1-font-size or $h2-font-size or $h3-font-size or $h4-font-size or $h5-font-size or $h6-font-size">
<xsl:variable name="sz-attribute-value">
<xsl:choose>
<xsl:when test="$target-element/w:pPr/w:rPr/w:sz">
<xsl:value-of select="$target-element/w:pPr/w:rPr/w:sz/@w:val"/>
</xsl:when>
<xsl:when test="$target-element/w:pPr/w:szCs">
<xsl:value-of select="$target-element/w:pPr/w:rPr/w:szCs/@w:val"/>
</xsl:when>
<xsl:when test="$styles/w:style[@w:type='paragraph' and @w:styleId=$paragraph-style-id]/w:rPr/w:sz">
<xsl:value-of select="$styles/w:style[@w:type='paragraph' and @w:styleId=$paragraph-style-id]/w:rPr/w:sz/@w:val"/>
</xsl:when>
<xsl:when test="$styles/w:style[@w:type='paragraph' and @w:styleId=$paragraph-style-id]/w:rPr/w:szCs">
<xsl:value-of select="$styles/w:style[@w:type='paragraph' and @w:styleId=$paragraph-style-id]/w:rPr/w:szCs/@w:val"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="p-font-size" select="number($sz-attribute-value) div 2"/>
<xsl:choose>
<xsl:when test="$p-font-size and $p-font-size = $h1-font-size">
<xsl:value-of select="1"/>
</xsl:when>
<xsl:when test="$p-font-size and $p-font-size = $h2-font-size">
<xsl:value-of select="2"/>
</xsl:when>
<xsl:when test="$p-font-size and $p-font-size = $h3-font-size">
<xsl:value-of select="3"/>
</xsl:when>
<xsl:when test="$p-font-size and $p-font-size = $h4-font-size">
<xsl:value-of select="4"/>
</xsl:when>
<xsl:when test="$p-font-size and $p-font-size = $h5-font-size">
<xsl:value-of select="5"/>
</xsl:when>
<xsl:when test="$p-font-size and $p-font-size = $h6-font-size">
<xsl:value-of select="6"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<!-- Heading -->
<xsl:when test="boolean($heading-level) and $heading-level > 0 and $heading-level <= 6">
<xsl:value-of select="concat($heading-tag-name,$heading-level)"/>
</xsl:when>
<!-- Normal Paragraph -->
<xsl:otherwise>
<xsl:value-of select="$paragraph-tag-name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- Attribute for Headline and Paragraph --><!-- Table --><!-- Attributes for Table --><!-- Table Column Group --><!-- Table Column --><!-- Table Row --><!-- Table Cell --><!-- Merged Table Cell --><!-- Tag Name for Cell (th, td) --><xsl:template name="get-cell-tag-name">
<xsl:choose>
<xsl:when test="parent::w:tr/w:trPr/w:tblHeader">
<xsl:value-of select="$table-header-cell-tag-name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$table-cell-tag-name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- Attributes for Table Cell --><!-- Rowspan value for merged cells (w:vMerge) --><xsl:template name="get-rowspan-value">
<xsl:param name="following-row-elements"/>
<xsl:param name="target-column-num"/>
<xsl:param name="num-of-rowspans" select="1"/>
<!-- First row -->
<xsl:variable name="target-row-element" select="$following-row-elements[1]"/>
<!-- Check: Is a merged cell in the examined column? -->
<xsl:variable name="is-merged-cell">
<xsl:for-each select="$target-row-element/w:tc">
<xsl:variable name="cur-column-num">
<xsl:call-template name="get-column-number"/>
</xsl:variable>
<xsl:if test="$cur-column-num = $target-column-num">
<xsl:choose>
<xsl:when test="w:tcPr/w:vMerge[not(@w:val='restart')]">
<xsl:value-of select="'true'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'false'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="$target-row-element and $is-merged-cell = 'true'">
<xsl:call-template name="get-rowspan-value">
<xsl:with-param name="following-row-elements" select="$following-row-elements[position() > 1]"/>
<xsl:with-param name="target-column-num" select="$target-column-num"/>
<xsl:with-param name="num-of-rowspans" select="$num-of-rowspans + 1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$num-of-rowspans"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- Column number (considering merged cells with w:gridSpan) --><xsl:template name="get-column-number">
<xsl:variable name="absolute-column-num" select="count(preceding-sibling::w:tc) + 1"/>
<xsl:variable name="offset" select="sum(preceding-sibling::w:tc/w:tcPr/w:gridSpan/@w:val) - count(preceding-sibling::w:tc/w:tcPr/w:gridSpan[@w:val])"/>
<xsl:value-of select="number($absolute-column-num) + number($offset)"/>
</xsl:template><!-- Structured Document Tags --><xsl:template match="w:sdt">
<xsl:apply-templates/>
</xsl:template><!-- Structured Document Block Content --><xsl:template match="w:sdtContent[child::w:p]">
<xsl:call-template name="structure-paragraphs">
<xsl:with-param name="target-elements" select="*"/>
</xsl:call-template>
</xsl:template><!-- Structured Document Run Content --><xsl:template match="w:sdtContent[child::w:r]">
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="*"/>
</xsl:call-template>
</xsl:template><!-- Block-Level Custom XML Element --><xsl:template match="w:customXml[w:p]">
<xsl:call-template name="structure-paragraphs">
<xsl:with-param name="target-elements" select="*"/>
</xsl:call-template>
</xsl:template><!-- Inline-Level Custom XML Element --><xsl:template match="w:customXml[w:r]">
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="*"/>
</xsl:call-template>
</xsl:template><!-- Track Changes --><!-- Inserted Run Content --><xsl:template match="w:ins[w:r]">
<xsl:element name="{$inserted-text-tag-name}" namespace="{$ns}">
<xsl:call-template name="insert-track-change-attributes"/>
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="*"/>
</xsl:call-template>
</xsl:element>
</xsl:template><!-- Inserted Run Content (ancestor::w:numPr or ancestor::w:rPr or ancestor::w:trPr or child::w:rPr) --><xsl:template match="w:ins">
<xsl:apply-templates/>
</xsl:template><!-- Deleted Run Content --><xsl:template match="w:del[w:r]">
<xsl:element name="{$deleted-text-tag-name}" namespace="{$ns}">
<xsl:call-template name="insert-track-change-attributes"/>
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="*"/>
</xsl:call-template>
</xsl:element>
</xsl:template><!-- Deleted Run Content (ancestor::w:numPr or ancestor::w:rPr or ancestor::w:trPr or child::w:rPr) --><xsl:template match="w:del">
<xsl:apply-templates/>
</xsl:template><!-- Deleted Text --><xsl:template match="w:delText">
<xsl:apply-templates/>
</xsl:template><!-- Move Source Run Content --><xsl:template match="w:moveFrom[w:r]">
<xsl:element name="{$moved-from-text-tag-name}" namespace="{$ns}">
<xsl:call-template name="insert-track-change-attributes"/>
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="*"/>
</xsl:call-template>
</xsl:element>
</xsl:template><!-- Move Source Run Content (ancestor::w:numPr or ancestor::w:rPr or ancestor::w:trPr or child::w:rPr) --><xsl:template match="w:moveFrom">
<xsl:apply-templates/>
</xsl:template><!-- Move Destination Run Content --><xsl:template match="w:moveTo[w:r]">
<xsl:element name="{$moved-to-text-tag-name}" namespace="{$ns}">
<xsl:call-template name="insert-track-change-attributes"/>
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="*"/>
</xsl:call-template>
</xsl:element>
</xsl:template><!-- Move Destination Run Content (ancestor::w:numPr or ancestor::w:rPr or ancestor::w:trPr or child::w:rPr) --><xsl:template match="w:moveTo">
<xsl:apply-templates/>
</xsl:template><!-- Attributes for Track Changes --><xsl:template name="insert-track-change-attributes">
<xsl:attribute name="{$track-change-author-attribute-name}">
<xsl:value-of select="@w:author"/>
</xsl:attribute>
<xsl:attribute name="{$track-change-date-attribute-name}">
<xsl:value-of select="@w:date"/>
</xsl:attribute>
</xsl:template><!-- Structure text runs (e.g. complex fields) --><xsl:template name="structure-text-runs">
<xsl:param name="target-elements"/>
<xsl:param name="parent-field" select="''"/>
<xsl:choose>
<!-- Check: Are there any complex field starts? -->
<xsl:when test="$target-elements/w:fldChar[@w:fldCharType='begin']">
<xsl:variable name="field-begin-position">
<xsl:call-template name="get-field-begin-position">
<xsl:with-param name="target-elements" select="$target-elements"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="field-end-position">
<xsl:call-template name="get-field-end-position">
<xsl:with-param name="target-elements" select="$target-elements"/>
</xsl:call-template>
</xsl:variable>
<!-- Elements before complex field (first level) -->
<xsl:apply-templates select="$target-elements[position() < $field-begin-position]"/>
<!-- Elements of complex field (nested fields possible) -->
<xsl:call-template name="transform-complex-field">
<xsl:with-param name="field-begin-element" select="$target-elements[position() = $field-begin-position]"/>
<xsl:with-param name="field-content-elements" select="$target-elements[position() > $field-begin-position and position() < $field-end-position]"/>
<xsl:with-param name="field-end-element" select="$target-elements[position() = $field-end-position]"/>
<xsl:with-param name="parent-field" select="$parent-field"/>
</xsl:call-template>
<!-- Elements after (first) complex field (first level) -->
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="$target-elements[position() > $field-end-position]"/>
<xsl:with-param name="parent-field" select="$parent-field"/>
</xsl:call-template>
</xsl:when>
<!-- No complex field starts -->
<xsl:otherwise>
<xsl:apply-templates select="$target-elements"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- Begin position of complex field --><xsl:template name="get-field-begin-position">
<xsl:param name="target-elements"/>
<xsl:param name="position" select="0"/>
<xsl:variable name="first-element" select="$target-elements[position() = 1]"/>
<xsl:choose>
<xsl:when test="not($first-element) or $first-element[w:fldChar/@w:fldCharType='begin']">
<xsl:value-of select="number($position) + 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="get-field-begin-position">
<xsl:with-param name="target-elements" select="$target-elements[position() > 1]"/>
<xsl:with-param name="position" select="number($position) + 1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- End position of complex field --><xsl:template name="get-field-end-position">
<xsl:param name="target-elements"/>
<xsl:param name="position" select="0"/>
<xsl:param name="level" select="0"/>
<xsl:variable name="first-element" select="$target-elements[position() = 1]"/>
<xsl:choose>
<xsl:when test="not($first-element) or ($first-element/w:fldChar[@w:fldCharType='end'] and $level = 1)">
<xsl:value-of select="number($position) + 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="get-field-end-position">
<xsl:with-param name="target-elements" select="$target-elements[position() > 1]"/>
<xsl:with-param name="position" select="number($position) + 1"/>
<xsl:with-param name="level">
<xsl:choose>
<xsl:when test="$first-element/w:fldChar[@w:fldCharType='begin']">
<xsl:value-of select="number($level) + 1"/>
</xsl:when>
<xsl:when test="$first-element/w:fldChar[@w:fldCharType='end']">
<xsl:value-of select="number($level) - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$level"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- Complex field transformation --><xsl:template name="transform-complex-field">
<xsl:param name="field-begin-element"/>
<xsl:param name="field-content-elements"/>
<xsl:param name="field-end-element"/>
<xsl:param name="parent-field" select="''"/>
<!-- Text content -->
<xsl:variable name="complex-field-content">
<xsl:call-template name="get-complex-field-content">
<xsl:with-param name="following-sibling-elements" select="$field-begin-element/following-sibling::w:r"/>
</xsl:call-template>
</xsl:variable>
<!-- Check: Type of complex field? -->
<xsl:choose>
<!-- Ignored field e.g. nested hyperlinks, Table of Content field -->
<xsl:when test=" starts-with($complex-field-content, 'TOC') or $parent-field = 'HYPERLINK' and (starts-with($complex-field-content, 'HYPERLINK') or starts-with($complex-field-content, 'REF') or starts-with($complex-field-content, 'PAGEREF') or starts-with($complex-field-content, 'NOTEREF')) ">
<!-- Field elements -->
<xsl:apply-templates select="$field-begin-element"/>
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="$field-content-elements"/>
<xsl:with-param name="parent-field" select="$parent-field"/>
</xsl:call-template>
<xsl:apply-templates select="$field-end-element"/>
</xsl:when>
<!-- Index Mark -->
<xsl:when test="starts-with($complex-field-content, 'XE')">
<xsl:element name="{$indexmark-tag-name}" namespace="{$ns}">
<!-- Attributes -->
<xsl:call-template name="insert-indexmark-attributes">
<xsl:with-param name="complex-field-content" select="$complex-field-content"/>
</xsl:call-template>
</xsl:element>
<!-- Field elements -->
<xsl:apply-templates select="$field-begin-element"/>
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="$field-content-elements"/>
<xsl:with-param name="parent-field" select="$parent-field"/>
</xsl:call-template>
<xsl:apply-templates select="$field-end-element"/>
</xsl:when>
<!-- Hyperlink (across several paragraphs) -->
<xsl:when test="starts-with($complex-field-content, 'HYPERLINK')">
<xsl:element name="{$hyperlink-tag-name}" namespace="{$ns}">
<!-- Attributes -->
<xsl:call-template name="insert-complex-field-hyperlink-attributes">
<xsl:with-param name="complex-field-content" select="$complex-field-content"/>
</xsl:call-template>
<!-- Field elements -->
<xsl:apply-templates select="$field-begin-element"/>
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="$field-content-elements"/>
<xsl:with-param name="parent-field" select="'HYPERLINK'"/>
</xsl:call-template>
<xsl:apply-templates select="$field-end-element"/>
</xsl:element>
</xsl:when>
<!-- Cross References -->
<xsl:when test="starts-with($complex-field-content, 'REF') or starts-with($complex-field-content, 'PAGEREF') or starts-with($complex-field-content, 'NOTEREF')">
<xsl:element name="{$cross-reference-tag-name}" namespace="{$ns}">
<!-- Attributes -->
<xsl:call-template name="insert-cross-reference-attributes">
<xsl:with-param name="complex-field-content" select="$complex-field-content"/>
</xsl:call-template>
<!-- Field elements -->
<xsl:apply-templates select="$field-begin-element"/>
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="$field-content-elements"/>
<xsl:with-param name="parent-field" select="'HYPERLINK'"/>
</xsl:call-template>
<xsl:apply-templates select="$field-end-element"/>
</xsl:element>
</xsl:when>
<!-- Date/Time -->
<xsl:when test=" starts-with($complex-field-content, 'TIME') or starts-with($complex-field-content, 'DATE') or starts-with($complex-field-content, 'CREATEDATE') or starts-with($complex-field-content, 'PRINTDATE') or starts-with($complex-field-content, 'SAVEDATE') ">
<xsl:element name="{$time-tag-name}" namespace="{$ns}">
<!-- Attributes -->
<xsl:call-template name="insert-time-attributes">
<xsl:with-param name="complex-field-content" select="$complex-field-content"/>
</xsl:call-template>
<!-- Field elements -->
<xsl:apply-templates select="$field-begin-element"/>
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="$field-content-elements"/>
<xsl:with-param name="parent-field" select="$parent-field"/>
</xsl:call-template>
<xsl:apply-templates select="$field-end-element"/>
</xsl:element>
</xsl:when>
<!-- Citations -->
<xsl:when test="starts-with($complex-field-content, 'CITATION')">
<xsl:variable name="citation-id" select="substring-before(normalize-space(substring-after($complex-field-content, 'CITATION')), ' ')"/>
<xsl:element name="{$citation-tag-name}" namespace="{$ns}">
<!-- Attributes -->
<xsl:call-template name="insert-citation-attributes">
<xsl:with-param name="id" select="$citation-id"/>
</xsl:call-template>
<!-- Field elements (Call) -->
<xsl:element name="{$citation-call-tag-name}" namespace="{$ns}">
<xsl:apply-templates select="$field-begin-element"/>
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="$field-content-elements"/>
<xsl:with-param name="parent-field" select="$parent-field"/>
</xsl:call-template>
<xsl:apply-templates select="$field-end-element"/>
</xsl:element>
<!-- Source elements -->
<xsl:call-template name="insert-citation-source">
<xsl:with-param name="id" select="$citation-id"/>
</xsl:call-template>
</xsl:element>
</xsl:when>
<!-- Other Complex Field -->
<xsl:otherwise>
<xsl:element name="{$complex-field-tag-name}" namespace="{$ns}">
<!-- Attributes -->
<xsl:call-template name="insert-general-complex-field-attributes">
<xsl:with-param name="complex-field-content" select="$complex-field-content"/>
<xsl:with-param name="field-begin-element" select="$field-begin-element"/>
</xsl:call-template>
<!-- Field elements -->
<xsl:apply-templates select="$field-begin-element"/>
<xsl:call-template name="structure-text-runs">
<xsl:with-param name="target-elements" select="$field-content-elements"/>
<xsl:with-param name="parent-field" select="$parent-field"/>
</xsl:call-template>
<xsl:apply-templates select="$field-end-element"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- Content of complex field --><xsl:template name="get-complex-field-content">
<xsl:param name="following-sibling-elements"/>
<xsl:param name="complex-field-text" select="''"/>
<xsl:variable name="target-element" select="$following-sibling-elements[1]"/>
<xsl:variable name="target-element-text">
<xsl:value-of select="$target-element/w:instrText"/>
</xsl:variable>
<xsl:choose>
<xsl:when test=" $target-element and not($target-element/w:fldChar[@w:fldCharType = 'end']) and not($target-element/w:fldChar[@w:fldCharType = 'begin']) ">
<xsl:call-template name="get-complex-field-content">
<xsl:with-param name="following-sibling-elements" select="$following-sibling-elements[position() > 1]"/>
<xsl:with-param name="complex-field-text" select="concat($complex-field-text, $target-element-text)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(concat($complex-field-text, $target-element-text))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- Attributes for indexmark element --><xsl:template name="insert-indexmark-attributes">
<xsl:param name="complex-field-content" select="''"/>
<xsl:variable name="index-flags">
<xsl:call-template name="get-complex-field-flags">
<xsl:with-param name="complex-field-content" select="$complex-field-content"/>
</xsl:call-template>
</xsl:variable>
<!-- Style -->
<xsl:attribute name="{$indexmark-style-attribute-name}">
<xsl:value-of select="$indexmark-style-attribute-value"/>
</xsl:attribute>
<!-- Type -->
<xsl:choose>
<xsl:when test="contains($index-flags,'r')">
<xsl:attribute name="{$indexmark-type-attribute-name}">
<xsl:value-of select="'r'"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="contains($index-flags,'t')">
<xsl:attribute name="{$indexmark-type-attribute-name}">
<xsl:value-of select="'t'"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="not(contains($index-flags,'r') or contains($index-flags,'t'))">
<xsl:attribute name="{$indexmark-type-attribute-name}">
<xsl:value-of select="'x'"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="{$indexmark-type-attribute-name}">
<xsl:value-of select="''"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<!-- Styling -->
<xsl:choose>
<xsl:when test="contains($index-flags,'b') and contains($index-flags,'i')">
<xsl:attribute name="{$indexmark-format-attribute-name}">
<xsl:value-of select="'b i'"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="contains($index-flags,'b')">
<xsl:attribute name="{$indexmark-format-attribute-name}">
<xsl:value-of select="'b'"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="contains($index-flags,'i')">
<xsl:attribute name="{$indexmark-format-attribute-name}">
<xsl:value-of select="'i'"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="{$indexmark-format-attribute-name}">
<xsl:value-of select="''"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<!-- Entry (e.g. »Animal:Cat« for entry with subentry) -->
<xsl:attribute name="{$indexmark-entry-attribute-name}">
<xsl:value-of select="normalize-space(substring-before(substring-after($complex-field-content,'"'), '"'))"/>
</xsl:attribute>
<!-- Target (page range or see here entry, e.g. name of the textmark/bookmark or see here entry) -->
<xsl:attribute name="{$indexmark-target-attribute-name}">
<xsl:value-of select="normalize-space(substring-before(substring-after(substring-after(substring-after($complex-field-content,'"'), '"'), '"'), '"'))"/>
</xsl:attribute>
</xsl:template><!-- Attributes for complex field hyperlink --><xsl:template name="insert-complex-field-hyperlink-attributes">
<xsl:param name="complex-field-content" select="''"/>
<!-- URI -->
<xsl:attribute name="{$hyperlink-uri-attribute-name}">
<xsl:call-template name="get-complex-field-hyperlink-uri">
<xsl:with-param name="complex-field-content" select="$complex-field-content"/>
</xsl:call-template>
</xsl:attribute>
<!-- Title -->
<xsl:variable name="title">
<xsl:value-of select="substring-before(substring-after($complex-field-content,'\o "'), '"')"/>
</xsl:variable>
<xsl:if test="not($title = '')">
<xsl:attribute name="{$hyperlink-title-attribute-name}">
<xsl:value-of select="$title"/>
</xsl:attribute>
</xsl:if>
</xsl:template><!-- Value of hyperlink href attribute of complex field --><xsl:template name="get-complex-field-hyperlink-uri">
<xsl:param name="complex-field-content" select="''"/>
<xsl:variable name="uri">
<xsl:value-of select="substring-before(substring-after($complex-field-content,'"'), '"')"/>
</xsl:variable>
<xsl:variable name="anchor">
<xsl:value-of select="substring-before(substring-after($complex-field-content,'\l "'), '"')"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="not($anchor = '')">
<xsl:value-of select="concat($uri, '#', $anchor)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$uri"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- Attributes for cross referenc element --><xsl:template name="insert-cross-reference-attributes">
<xsl:param name="complex-field-content" select="''"/>
<!-- URI -->
<xsl:attribute name="{$cross-reference-uri-attribute-name}">
<xsl:text>#</xsl:text>
<xsl:value-of select="substring-before(substring-after($complex-field-content,'REF '), ' \')"/>
</xsl:attribute>
<!-- Type -->
<xsl:attribute name="{$cross-reference-type-attribute-name}">
<xsl:value-of select="substring-before($complex-field-content,' ')"/>
</xsl:attribute>
<!-- Format -->
<xsl:attribute name="{$cross-reference-format-attribute-name}">
<xsl:call-template name="get-complex-field-flags">
<xsl:with-param name="complex-field-content" select="$complex-field-content"/>
</xsl:call-template>
</xsl:attribute>
</xsl:template><!-- Attributes for complex field time element --><xsl:template name="insert-time-attributes">
<xsl:param name="complex-field-content" select="''"/>
<!-- Type -->
<xsl:attribute name="{$time-type-attribute-name}">
<xsl:value-of select="normalize-space(translate(substring-before($complex-field-content,' '), $uppercase, $lowercase))"/>
</xsl:attribute>
<!-- Format -->
<xsl:attribute name="{$time-format-attribute-name}">
<xsl:value-of select="substring-before(substring-after($complex-field-content,'"'), '"')"/>
</xsl:attribute>
</xsl:template><!-- Attributes for citation element --><xsl:template name="insert-citation-attributes">
<xsl:param name="id" select="''"/>
<!-- Style Attribute -->
<xsl:attribute name="{$citation-style-attribute-name}">
<xsl:value-of select="$citation-style-attribute-value"/>
</xsl:attribute>
<!-- Type -->
<xsl:attribute name="{$citation-style-type-attribute-name}">
<xsl:value-of select="$citations-relationships/b:Sources[b:Source/b:Tag = $id]/@SelectedStyle"/>
</xsl:attribute>
<!-- Name -->
<xsl:attribute name="{$citation-style-name-attribute-name}">
<xsl:value-of select="$citations-relationships/b:Sources[b:Source/b:Tag = $id]/@StyleName"/>
</xsl:attribute>
<!-- Version -->
<xsl:attribute name="{$citation-version-attribute-name}">
<xsl:value-of select="$citations-relationships/b:Sources[b:Source/b:Tag = $id]/@Version"/>
</xsl:attribute>
</xsl:template><!-- Citation source element --><xsl:template name="insert-citation-source">
<xsl:param name="id" select="''"/>
<xsl:element name="{$citation-source-tag-name}" namespace="{$ns}">
<xsl:apply-templates select="$citations-relationships/b:Sources/b:Source[b:Tag = $id]/*" mode="citation-source"/>
</xsl:element>
</xsl:template><xsl:template match="*" mode="citation-source">
<xsl:element name="{local-name()}" namespace="{$ns}">
<xsl:apply-templates select="@*|*|text()" mode="citation-source"/>
</xsl:element>
</xsl:template><xsl:template match="@*" mode="citation-source">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template><xsl:template match="text()" mode="citation-source">
<xsl:if test="normalize-space()">
<xsl:element name="{$citation-text-tag-name}" namespace="{$ns}">
<xsl:attribute name="{$citation-value-attribute-name}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:element>
</xsl:if>
</xsl:template><!-- Attributes for general complex field --><xsl:template name="insert-general-complex-field-attributes">
<xsl:param name="complex-field-content" select="''"/>
<xsl:param name="field-begin-element"/>
<!-- Style -->
<xsl:attribute name="{$complex-field-style-attribute-name}">
<xsl:value-of select="$complex-field-style-attribute-value"/>
</xsl:attribute>
<!-- Content -->
<xsl:attribute name="{$complex-field-content-attribute-name}">
<xsl:value-of select="$complex-field-content"/>
</xsl:attribute>
<!-- Data -->
<xsl:if test="$field-begin-element/w:fldChar/w:fldData">
<xsl:attribute name="{$complex-field-data-attribute-name}">
<xsl:value-of select="$field-begin-element/w:fldChar/w:fldData"/>
</xsl:attribute>
</xsl:if>
</xsl:template><!-- Value of type attribute for index mark --><!--
»b« for bold style of entry
»i« for italic style of entry
»r« for page range with textmark/bookmark
»t« for see here entry
empty string for normal entry without style
a colon separates the entry levels (e.g. Animal:Cat)
--><xsl:template name="get-complex-field-flags">
<xsl:param name="complex-field-content" select="''"/>
<xsl:param name="index-flags" select="''"/>
<xsl:choose>
<xsl:when test="contains($complex-field-content, '\')">
<xsl:variable name="target-flags">
<xsl:value-of select="substring(substring-after($complex-field-content,'\'), 1, 1)"/>
</xsl:variable>
<xsl:call-template name="get-complex-field-flags">
<xsl:with-param name="complex-field-content" select="substring-after($complex-field-content, '\')"/>
<xsl:with-param name="index-flags" select="concat($index-flags, ' ', $target-flags)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space($index-flags)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template><!-- Complex Field (handeled in template »transform-complex-field«) --><xsl:template match="w:fldChar">
<xsl:apply-templates/>
</xsl:template><xsl:template match="w:fldChar[@w:fldCharType='begin']">
<xsl:if test="$is-comment-inserted">
<xsl:comment>
<xsl:value-of select="'complex field begin'"/>
</xsl:comment>
</xsl:if>
<xsl:apply-templates/>