-
Notifications
You must be signed in to change notification settings - Fork 14
/
wml2dbk.xsl
executable file
·1870 lines (1692 loc) · 93.7 KB
/
wml2dbk.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" ?>
<xsl:stylesheet xmlns:xsl="http:https://www.w3.org/1999/XSL/Transform"
xmlns:xs="http:https://www.w3.org/2001/XMLSchema"
xmlns:fn="http:https://www.w3.org/2005/xpath-functions"
xmlns:w= "http:https://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:dbk="http:https://docbook.org/ns/docbook"
xmlns:r="http:https://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:rel="http:https://schemas.openxmlformats.org/package/2006/relationships"
xmlns:tr="http:https://transpect.io"
xmlns:m="http:https://schemas.openxmlformats.org/officeDocument/2006/math"
xmlns:mc="http:https://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:xlink="http:https://www.w3.org/1999/xlink"
xmlns:docx2hub="http:https://transpect.io/docx2hub"
xmlns:css="http:https://www.w3.org/1996/css"
xmlns:mml="http:https://www.w3.org/1998/Math/MathML"
xmlns:wp="http:https://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w14="http:https://schemas.microsoft.com/office/word/2010/wordml"
xmlns:w15="http:https://schemas.microsoft.com/office/word/2012/wordml"
xmlns="http:https://docbook.org/ns/docbook"
version="2.0"
exclude-result-prefixes = "w xs dbk fn r rel tr m mc docx2hub v wp">
<!-- ================================================================================ -->
<!-- IMPORT OF OTHER STYLESHEETS -->
<!-- ================================================================================ -->
<xsl:import href="modules/catch-all/catch-all.xsl"/>
<xsl:import href="modules/error-handler/error-handler.xsl"/>
<xsl:param name="debug" select="'yes'" as="xs:string?"/>
<xsl:param name="debug-dir-uri" select="'debug-dir-uri_not_set'" as="xs:string?"/>
<xsl:param name="fail-on-error" select="'no'" as="xs:string?"/>
<xsl:param name="field-vars" select="'no'" as="xs:string?"/>
<xsl:param name="srcpaths" select="'no'" as="xs:string?"/>
<xsl:param name="base-dir" select="replace(base-uri(), '[^/]+$', '')"/>
<xsl:param name="extract-dir-uri" select="''" as="xs:string"/><!-- tmp unzip dir URI -->
<xsl:param name="local-href" select="''" as="xs:string"/><!-- docx file URI -->
<xsl:variable name="debug-dir" select="concat(replace($base-dir, '^(.+/)(.+?/)$', '$1'), 'debug')"/>
<!-- Links that probably have been inserted by Word without user content: -->
<xsl:param name="unwrap-tooltip-links" select="'no'" as="xs:string?"/>
<xsl:param name="hub-version" select="'1.2'" as="xs:string"/>
<xsl:param name="discard-alternate-choices" select="'yes'" as="xs:string"/>
<xsl:param name="include-header-and-footer" select="'no'" as="xs:string"/>
<xsl:param name="convert-footer" select="false()" as="xs:boolean"/>
<xsl:param name="remove-biblioentry-paragraphs" select="'yes'" as="xs:string"/>
<xsl:param name="mathtype2mml" select="'no'" as="xs:string?"/>
<xsl:param name="lang-variant" select="'no'" as="xs:string"/>
<xsl:param name="charmap-policy" select="'unicode'" as="xs:string">
<!-- Values: unicode or xs:string. For xs:string, mapping attribute in the fashion @char-{xs:string} must exist in the symbols file -->
</xsl:param>
<xsl:param name="keep-paraid" select="'false'"/>
<xsl:variable name="docx2hub:discard-alternate-choices" as="xs:boolean"
select="$discard-alternate-choices = ('yes', 'true', '1')"/>
<xsl:variable name="symbol-font-map" as="document-node(element(symbols))"
select="document('http:https://transpect.io/fontmaps/Symbol.xml')"/>
<xsl:key name="style-by-id" match="w:style" use="@w:styleId" />
<xsl:key name="numbering-by-id" match="w:num" use="@w:numId" />
<xsl:key name="abstract-numbering-by-id" match="w:abstractNum" use="@w:abstractNumId" />
<xsl:key name="footnote-by-id" match="w:footnote" use="@w:id" />
<xsl:key name="footnoteReference-by-id" match="w:footnoteReference" use="@w:id" />
<xsl:key name="endnote-by-id" match="w:endnote" use="@w:id" />
<xsl:key name="endnoteReference-by-id" match="w:endnoteReference" use="@w:id" />
<xsl:key name="comment-by-id" match="w:comment" use="@w:id" />
<xsl:key name="doc-rel-by-id" match="w:docRels/rel:Relationships/rel:Relationship" use="@Id" />
<xsl:key name="footnote-rel-by-id" match="w:footnoteRels/rel:Relationships/rel:Relationship" use="@Id" />
<xsl:key name="endnote-rel-by-id" match="w:endnoteRels/rel:Relationships/rel:Relationship" use="@Id" />
<xsl:key name="comment-rel-by-id" match="w:commentRels/rel:Relationships/rel:Relationship" use="@Id" />
<xsl:key name="symbol-by-number" match="symbol" use="upper-case(replace(@number, '^0*(.+?)$', '$1'))" />
<xsl:key name="symbol-by-entity" match="symbol" use="@entity" />
<xsl:key name="style-by-name" match="css:rule | dbk:style" use="@name | @role"/>
<xsl:key name="by-id" match="*" use="@xml:id"/>
<!-- sorted includes -->
<xsl:include href="changemarkup.xsl"/>
<xsl:include href="comments.xsl"/>
<xsl:include href="endnotes.xsl"/>
<xsl:include href="footnotes.xsl"/>
<xsl:include href="index.xsl"/>
<xsl:include href="numbering.xsl"/>
<xsl:include href="objects.xsl"/>
<xsl:include href="images.xsl"/>
<xsl:include href="omml2mml/omml2mml.xsl"/>
<xsl:include href="sym.xsl"/>
<xsl:include href="tables.xsl"/>
<xsl:function name="tr:node-index-of" as="xs:integer?">
<xsl:param name="nodes" as="node()*"/>
<xsl:param name="node" as="node()"/>
<xsl:sequence select="index-of(for $n in $nodes return generate-id($n), generate-id($node))"/>
</xsl:function>
<xsl:function name="docx2hub:rel-lookup" as="element(rel:Relationship)">
<xsl:param name="rid" as="attribute(r:id)"/>
<xsl:variable name="key-name" as="xs:string"
select="if ($rid/../ancestor::w:footnote)
then 'footnote-rel-by-id'
else
if ($rid/../ancestor::w:endnote)
then 'endnote-rel-by-id'
else
if ($rid/../ancestor::w:comment)
then 'comment-rel-by-id'
else 'doc-rel-by-id'" />
<xsl:sequence select="key($key-name, $rid, root($rid))"/>
</xsl:function>
<!-- ================================================================================ -->
<!-- Mode: docx2hub:field-functions -->
<!-- ================================================================================ -->
<!-- Each field function will be replaced with an XML element with the same name as the field function -->
<xsl:template match="/dbk:hub" mode="docx2hub:field-functions" priority="2">
<xsl:variable name="field-begins" as="element(w:fldChar)*"
select="key('docx2hub:item-by-id', .//w:instrText/@docx2hub:fldChar-start-id)"/>
<xsl:variable name="field-begin-ids" select="$field-begins/@xml:id" as="xs:string*"/>
<xsl:variable name="field-ends" as="element(w:fldChar)*"
select=".//w:fldChar[@w:fldCharType = 'end']
[@linkend = $field-begin-ids]"/>
<xsl:variable name="non-block-field-begins" as="element(w:fldChar)*"
select="$field-begins[not(
key('docx2hub:instrText-by-start-id', @xml:id)/@docx2hub:field-function-name
= $docx2hub:block-field-functions
)]"/>
<xsl:variable name="non-block-field-begin-ids" select="$non-block-field-begins/@xml:id" as="xs:string*"/>
<xsl:variable name="non-block-field-ends" as="element(w:fldChar)*"
select="$field-ends[@linkend = $non-block-field-begin-ids]"/>
<xsl:variable name="block-begins" as="element(w:fldChar)*"
select="$field-begins[key('docx2hub:instrText-by-start-id', @xml:id)/@docx2hub:field-function-name = $docx2hub:block-field-functions]"/>
<xsl:variable name="lookaround-count" as="xs:double*">
<xsl:for-each select="$non-block-field-begins">
<xsl:variable name="c" as="element(w:fldChar)?"
select="key('docx2hub:linking-item-by-id', @xml:id)[@w:fldCharType = 'end']"/>
<xsl:variable name="distance" as="xs:double" select="xs:double(count(ancestor::w:p/following-sibling::*[$c >> .]))"/>
<xsl:if test="$distance gt 10">
<xsl:message select="'Large lookaround distance', $distance, 'due to', ancestor::w:p"/>
</xsl:if>
<xsl:sequence select="$distance"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="max-lookaround-count" as="xs:integer" select="xs:integer((max($lookaround-count), 0)[1])"/>
<xsl:if test="$debug = 'yes'">
<xsl:message select="'Number of lookaround paragraphs for inline field functions: ', $max-lookaround-count"/>
</xsl:if>
<xsl:next-match>
<!-- Pre-calculating all these params for large documents with many field functions, such as prEN_16815 -->
<xsl:with-param name="field-begins" select="$field-begins" tunnel="yes"/>
<xsl:with-param name="field-ends" select="$field-ends" tunnel="yes"/>
<xsl:with-param name="non-block-field-begin-ids" select="$non-block-field-begin-ids" tunnel="yes"/>
<xsl:with-param name="non-block-field-begins" select="$non-block-field-begins" tunnel="yes"/>
<xsl:with-param name="non-block-field-ends" select="$non-block-field-ends" tunnel="yes"/>
<xsl:with-param name="block-begins" select="$block-begins" tunnel="yes"/>
<xsl:with-param name="block-begin-ids" select="$block-begins/@xml:id" as="xs:string*" tunnel="yes"/>
<xsl:with-param name="lookaround-count" select="$max-lookaround-count" tunnel="yes"/>
</xsl:next-match>
</xsl:template>
<xsl:key name="docx2hub:instrText-by-start-id" match="w:instrText[@docx2hub:fldChar-start-id]"
use="@docx2hub:fldChar-start-id"/>
<xsl:variable name="docx2hub:block-field-functions" as="xs:string+"
select="('ADDRESSBLOCK', 'BIBLIOGRAPHY', 'CITAVI_XML', 'COMMENTS', 'CSL_XML', 'DATABASE', 'INDEX', 'RD', 'TOA', 'TOC')"/>
<xsl:variable name="docx2hub:hybrid-field-functions" as="xs:string+"
select="('IF')"/>
<!-- Handle block field functions. The inline field functions will be handled when processing
the individual current-group()s in docx2hub:field-functions mode, with tunneled begin/end
field chars. -->
<xsl:template match="*[w:p]" mode="docx2hub:field-functions">
<xsl:param name="field-begins" as="element(w:fldChar)*" tunnel="yes"/>
<xsl:param name="field-ends" as="element(w:fldChar)*" tunnel="yes"/>
<xsl:param name="block-begins" as="element(w:fldChar)*" tunnel="yes"/>
<xsl:param name="block-begin-ids" as="xs:string*" tunnel="yes"/>
<xsl:copy>
<xsl:apply-templates select="@*" mode="#current"/>
<!-- Assumption 1: Block field functions are not nested. There may be inline field functions
nested within block field functions, but there are no block field functions within other block field functions.
Therefore, we may use group-starting-with/group-ending-with to balance them, without recurring to recursion.
Assumption 2: There is at most only one block field function begin per paragraph.
Caveat: Since block field functions may be contained in table cells, we should only consider the
w:p/w:r/w:fldChars in this context, not arbitrarily deep .//w:fldChars (those in w:tbl/w:tc/w:p). -->
<xsl:for-each-group select="*" group-starting-with="w:p[w:r/w:fldChar/@xml:id = $block-begin-ids]">
<xsl:variable name="begin-fldChar-candidates" as="element(w:fldChar)*"
select="w:r/w:fldChar[@xml:id = $block-begin-ids]"/>
<xsl:variable name="begin-fldChar" as="element(w:fldChar)?"
select="($begin-fldChar-candidates)[1]"/>
<xsl:if test="count($begin-fldChar-candidates) gt 1">
<xsl:message select="'More than one begin w:fldChar found for ', $block-begins/@xml:id"/>
</xsl:if>
<xsl:choose>
<xsl:when test="exists($begin-fldChar)">
<xsl:variable name="instr-text" as="element(w:instrText)"
select="key('docx2hub:instrText-by-start-id', $begin-fldChar/@xml:id)"/>
<xsl:variable name="end-fldChar" as="element(w:fldChar)?" select="$field-ends[@linkend = $begin-fldChar/@xml:id]"/>
<xsl:variable name="ffname" as="xs:string" select="$instr-text/@docx2hub:field-function-name"/>
<xsl:variable name="ffargs" as="xs:string?" select="$instr-text/@docx2hub:field-function-args"/>
<!-- GI 2010-16-13: It turns out that if the block end field function is at the beginning of a paragraph, then this
paragraph must be excluded from the block. -->
<xsl:variable name="end-p" as="element(w:p)*"
select="for $p in current-group()/self::w:p[.//w:fldChar[@w:fldCharType = 'end']/@linkend = $end-fldChar/@linkend]
return if (
empty($end-fldChar/ancestor::w:p[1]//w:t intersect $end-fldChar/parent::w:r/preceding::w:t)
and
exists($p/preceding-sibling::w:p[1])
)
then $p/preceding-sibling::w:p[1]
else $p"/>
<xsl:for-each-group select="current-group()" group-ending-with="w:p[. is $end-p]">
<xsl:choose>
<xsl:when test="current-group()[last()] is $end-p">
<xsl:element name="{$ffname}">
<xsl:attribute name="fldArgs" select="$ffargs"/>
<xsl:apply-templates select="current-group()" mode="#current">
<xsl:with-param name="field-begins" select="$field-begins except $begin-fldChar" tunnel="yes"/>
<xsl:with-param name="field-ends" select="$field-ends except $end-fldChar" tunnel="yes"/>
</xsl:apply-templates>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()" mode="#current"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()" mode="#current"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
<!--<xsl:function name="docx2hub:corresponding-end-fldChar" as="element(w:fldChar)?">
<xsl:param name="begin" as="element(w:fldChar)"/>
<xsl:variable name="prelim" as="element(w:fldChar)*"
select="key('docx2hub:linking-item-by-id', $begin/@xml:id, root($begin))[@w:fldCharType = 'end']"/>
<xsl:if test="count($prelim) gt 1">
<xsl:message terminate="no" select="'More than one docx2hub:corresponding-end-fldChar() result for ', $begin"/>
</xsl:if>
<xsl:if test="count($prelim) eq 0">
<xsl:message terminate="no" select="'No docx2hub:corresponding-end-fldChar() result for ', $begin"/>
</xsl:if>
<xsl:sequence select="$prelim[1]"/>
</xsl:function>-->
<!--<xsl:function name="docx2hub:corresponding-begin-fldChar" as="element(w:fldChar)">
<xsl:param name="end" as="element(w:fldChar)"/>
<xsl:sequence select="key('docx2hub:item-by-id', $end/@linkend, root($end))"/>
</xsl:function>-->
<!-- convert inline field functions to elements of the same names -->
<xsl:template match="w:p | w:hyperlink | w:sdtContent[w:r/w:instrText]" mode="docx2hub:field-functions">
<xsl:param name="non-block-field-begins" as="element(w:fldChar)*" tunnel="yes"/>
<xsl:param name="non-block-field-ends" as="element(w:fldChar)*" tunnel="yes"/>
<xsl:param name="lookaround-count" as="xs:integer" tunnel="yes">
<!-- Number of elments to look back or ahead from the current paragraph in order to find
inline field functions that span multiple paragraphs (HYPERLINK would be a candidate).
This limit has been introduced because it would be too expensive to consider the whole
document when looking for field begins or ends that stretch across the current para. -->
</xsl:param>
<!-- <xsl:variable name="preceding-field-begins" as="element(w:fldChar)*" select="$non-block-field-begins[. << current()]"/>
<xsl:variable name="following-or-contained-field-ends" as="element(w:fldChar)*" select="$non-block-field-ends[. >> current()]"/>
<xsl:variable name="last-in-para" as="element(*)" select="(current()/*[last()]/w:fldChar, current()/*[last()], current())[1]"/>
<xsl:variable name="following-field-ends" as="element(w:fldChar)*" select="$non-block-field-ends[. >> $last-in-para]"/>
<xsl:variable name="contained-field-begins" as="element(w:fldChar)*" select="$non-block-field-begins intersect .//w:fldChar"/>-->
<xsl:variable name="preceding-field-begins" as="element(w:fldChar)*" select="preceding-sibling::*[position() le $lookaround-count]//w:fldChar[@w:fldCharType='begin']"/>
<xsl:variable name="contained-field-begins" as="element(w:fldChar)*" select=".//w:fldChar[@w:fldCharType='begin']"/>
<xsl:variable name="following-field-ends" as="element(w:fldChar)*" select="following-sibling::*[position() le $lookaround-count]//w:fldChar[@w:fldCharType='end']"/>
<xsl:variable name="following-or-contained-field-ends" as="element(w:fldChar)*" select=".//w:fldChar[@w:fldCharType='end'] union $following-field-ends"/>
<!--<xsl:variable name="last-in-para" as="element(*)" select="(current()/*[last()]/w:fldChar, current()/*[last()], current())[1]"/>-->
<xsl:variable name="begins-before-ids" as="xs:string*"
select="$following-or-contained-field-ends[@linkend = $preceding-field-begins/@xml:id]/@linkend"/>
<xsl:variable name="ends-after-ids" as="xs:string*"
select="$following-field-ends[@linkend = ($preceding-field-begins | $contained-field-begins)/@xml:id]/@xml:id"/>
<xsl:variable name="begins-before-para" as="element(w:r)*">
<xsl:for-each select="key('docx2hub:item-by-id', $begins-before-ids)">
<w:r>
<xsl:sequence select="., key('docx2hub:instrText-by-start-id', @xml:id)"/>
</w:r>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="ends-after-para" as="element(*)*"
select="key('docx2hub:item-by-id', $ends-after-ids)/.."/>
<xsl:for-each select="$ends-after-para[not(name() = ('w:r', 'm:r'))]">
<xsl:sequence select="docx2hub:message(., $fail-on-error = 'yes', false(), 'W2D_096', 'WRN', 'wml-to-dbk',
concat('Unexpected field function context ''', name(), ''' with content ''', string(.), ''''))"/>
</xsl:for-each>
<xsl:variable name="props" as="element(*)*" select="w:numPr, w:pPr"/>
<xsl:copy>
<xsl:apply-templates select="@*, $props" mode="#current"/>
<xsl:call-template name="docx2hub:nest-inline-field-function">
<xsl:with-param name="para-contents" as="document-node()">
<xsl:document>
<xsl:sequence select="$begins-before-para, * except $props, $ends-after-para"/>
</xsl:document>
</xsl:with-param>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="docx2hub:nest-inline-field-function" as="element(*)*">
<xsl:param name="para-contents" as="document-node()"/>
<xsl:param name="non-block-field-begin-ids" as="xs:string*" tunnel="yes"/>
<xsl:variable name="innermost-nesting-begins" as="element(w:fldChar)*"
select="for $f in ($para-contents/w:r/w:fldChar[@xml:id = $non-block-field-begin-ids])
return $f[@xml:id
=
($para-contents/w:r/w:fldChar[not(@w:fldCharType = 'separate')]
[. >> $f]
)[1]/@linkend
]"/>
<xsl:choose>
<xsl:when test="empty($para-contents/*)"/>
<xsl:when test="exists($innermost-nesting-begins)">
<xsl:variable name="innermost-nesting-begin" as="element(w:fldChar)" select="$innermost-nesting-begins[1]"/>
<xsl:variable name="innermost-nesting-end" as="element(w:fldChar)"
select="$para-contents/w:r/w:fldChar[@w:fldCharType = 'end'][@linkend =$innermost-nesting-begin/@xml:id]">
<!-- don’t try to find it by key – the nodes in $para-contents are copies of the original document nodes -->
</xsl:variable>
<xsl:variable name="instr-text" as="element(w:instrText)*"
select="key('docx2hub:instrText-by-start-id', $innermost-nesting-begin/@xml:id)[not(@docx2hub:field-function-error)]"/>
<xsl:if test="empty($instr-text[matches(@docx2hub:field-function-name, 'MACROBUTTON|GOTOBUTTON')]) and count($instr-text) gt 1">
<xsl:message select="'More than one instrText: '"/>
<xsl:for-each select="$instr-text">
<xsl:message select="'ID: ', string(@docx2hub:fldChar-start-id), ', Error: ', string(@docx2hub:field-function-error),
', Name: ', string(@docx2hub:field-function-name), ', Args: ', string(@docx2hub:field-function-args)"/>
</xsl:for-each>
</xsl:if>
<xsl:variable name="ffname" as="xs:string?" select="$instr-text[1]/@docx2hub:field-function-name"/>
<xsl:variable name="ffargs" as="xs:string?" select="$instr-text[1]/@docx2hub:field-function-args"/>
<xsl:call-template name="docx2hub:nest-inline-field-function">
<xsl:with-param name="para-contents">
<xsl:document>
<xsl:sequence select="$para-contents/*[. << $innermost-nesting-begin/..]"/>
<xsl:variable name="inner" as="node()*" select="$para-contents/*[. >> $innermost-nesting-begin/..]
[. << $innermost-nesting-end/..]"/>
<xsl:choose>
<xsl:when test="exists($ffargs)"><!-- no error -->
<xsl:element name="{translate($ffname, '\:', '')}" xmlns="">
<xsl:attribute name="fldArgs" select="$ffargs"/>
<xsl:copy-of select="$inner/@css:*, $inner/@role"/>
<xsl:if test="exists($instr-text[1]/*) and not($ffname = 'NOTEREF')">
<!-- exclude NOTEREF: Testset file EN_ISO_473_D_tr_NOTEREF.docx will otherwise have undesired
superscript around the field codes -->
<xsl:attribute name="docx2hub:contains-markup" select="'yes'"/>
<xsl:sequence select="$instr-text[1]/node()"/>
</xsl:if>
<xsl:sequence select="$inner, $instr-text[position() gt 1]/node()"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="$inner"/>
</xsl:otherwise>
</xsl:choose>
<xsl:sequence select="$para-contents/*[. >> $innermost-nesting-end/..]"/>
</xsl:document>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$para-contents" mode="#current"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="w:r[every $child in * satisfies $child/(self::w:instrText | self::w:fldChar)]" mode="docx2hub:field-functions"/>
<xsl:template match="w:fldSimple[@docx2hub:field-function-name]" mode="docx2hub:field-functions">
<xsl:element name="{@docx2hub:field-function-name}" xmlns="">
<xsl:attribute name="fldArgs" select="@docx2hub:field-function-args"/>
<xsl:apply-templates mode="#current"/>
</xsl:element>
</xsl:template>
<xsl:template match="w:p/w:r/@*[not(name() = $docx2hub:toggle-prop-names)]" mode="docx2hub:remove-redundant-run-atts">
<xsl:variable name="self-name" select="name()"/>
<xsl:variable name="p-style" select="../../@role/key('style-by-name', .)/@*[name() = $self-name]" as="attribute()*"/>
<xsl:variable name="r-style" select="../@role/key('style-by-name', .)/@*[name() = $self-name]" as="attribute()*"/>
<xsl:choose>
<xsl:when test="exists($r-style) and . = $r-style">
<!-- inherit from run-style -->
</xsl:when>
<xsl:when test="exists($p-style) and . = $p-style and exists($r-style) and not(. = $r-style)">
<!-- style would be the same like para, but different from run -->
<xsl:copy/>
</xsl:when>
<xsl:when test="exists($p-style) and . = $p-style">
<!-- inherit from para-style -->
</xsl:when>
<xsl:otherwise>
<!-- cant inherit -->
<xsl:copy/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="w:p/@*[not(name() = $docx2hub:toggle-prop-names)]" mode="docx2hub:remove-redundant-run-atts">
<xsl:variable name="self-name" select="name()"/>
<xsl:variable name="p-style" as="attribute()*"
select="../@role/key('style-by-name', .)/@*[name() = $self-name]"/>
<xsl:if test="not(exists($p-style) and . = $p-style)">
<!-- can't inherit from para style -->
<xsl:copy/>
</xsl:if>
</xsl:template>
<!-- ================================================================================ -->
<!-- Mode: wml-to-dbk -->
<!-- ================================================================================ -->
<!-- default for elements -->
<xsl:template match="*" mode="wml-to-dbk" priority="-1">
<xsl:call-template name="signal-error" xmlns="">
<xsl:with-param name="error-code" select="'W2D_020'"/>
<xsl:with-param name="fail-on-error" select="$fail-on-error"/>
<xsl:with-param name="hash">
<value key="xpath"><xsl:value-of select="@srcpath"/></value>
<value key="level">INT</value>
<value key="mode">wml-to-dbk</value>
<value key="info-text"><xsl:value-of select="concat('Element: ', name(), ' Parent: ', ../name())"/></value>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<!-- GI 2012-10-08 §§§
Want to get rid of the warnings. Does that hurt? Not tested.
KW 2013-03-28: It hurts in case of w:numPr. Indentation properties are missing.
-->
<xsl:template match=" w:p/w:numPr
| css:rule/w:numPr
| css:rule/w:tblStylePr
| *:style/w:numPr
| *:phrase/w:numPr
| /*/w:numbering
| /*/w:docRels
| /*/w:footnoteRels
| /*/w:endnoteRels
| /*/w:commentRels
| /*/w:fonts
| /*/w:comments
| /*/w15:commentsEx
| /*/w:footnotes
| /*/w:endnotes
| mc:AlternateContent
| w:fldChar" mode="wml-to-dbk" priority="-0.25"/>
<xsl:template match="w:permStart | w:permEnd" mode="wml-to-dbk">
<xsl:variable name="tokens" as="xs:string*" select="for $att in @* return concat($att/name(),'=',$att)"/>
<xsl:processing-instruction name="tr" select="string-join((name(), $tokens), ' ')"/>
</xsl:template>
<xsl:template match="css:rule/w:tblPr" mode="wml-to-dbk">
<xsl:apply-templates select="@*[not(some $pa in ../@*/name() satisfies $pa = name())]" mode="#current"/>
</xsl:template>
<xsl:template match="dbk:* | css:*" mode="wml-to-dbk" priority="-0.1">
<xsl:copy>
<xsl:apply-templates select="@*" mode="#current" />
<xsl:apply-templates select="node()" mode="#current" />
</xsl:copy>
</xsl:template>
<xsl:template match="css:rule | *:style" mode="wml-to-dbk">
<xsl:param name="content" as="element(*)*">
<!-- linked-style, css:attic -->
</xsl:param>
<xsl:copy>
<xsl:if test="w:numPr">
<xsl:variable name="ilvl" select="w:numPr/w:ilvl/@w:val"/>
<xsl:variable name="lvl-properties" select="key('abstract-numbering-by-id',key('numbering-by-id',w:numPr/w:numId/@w:val)/w:abstractNumId/@w:val)/w:lvl[@w:ilvl=$ilvl]"/>
<xsl:apply-templates select="$lvl-properties/@* except $lvl-properties/@w:ilvl" mode="#current"/>
</xsl:if>
<xsl:apply-templates select="@*, w:tblPr, *[not(self::w:tblPr)], $content" mode="#current" />
</xsl:copy>
</xsl:template>
<xsl:template match="@srcpath" mode="wml-to-dbk">
<xsl:copy/>
</xsl:template>
<xsl:template match="@*:paraId" mode="wml-to-dbk" priority="3" />
<xsl:template match="@*:textId" mode="wml-to-dbk" priority="3" />
<!-- default for attributes -->
<xsl:template match="@*" mode="wml-to-dbk" priority="1">
<xsl:copy/>
</xsl:template>
<xsl:template match="@*[not(starts-with(name(), 'docx2hub:generated'))]" mode="wml-to-dbk" priority="-0.5">
<xsl:call-template name="signal-error" xmlns="">
<xsl:with-param name="error-code" select="'W2D_021'"/>
<xsl:with-param name="fail-on-error" select="$fail-on-error"/>
<xsl:with-param name="hash">
<value key="xpath"><xsl:value-of select="../@srcpath"/></value>
<value key="level">INT</value>
<value key="mode">wml-to-dbk</value>
<value key="info-text"><xsl:value-of select="concat('Attribut: ', name(), ' Parent: ', ../name())"/></value>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<!-- default for comments -->
<xsl:template match="comment()" mode="wml-to-dbk">
<xsl:call-template name="signal-error" xmlns="">
<xsl:with-param name="error-code" select="'W2D_022'"/>
<xsl:with-param name="fail-on-error" select="$fail-on-error"/>
<xsl:with-param name="hash">
<value key="xpath"><xsl:value-of select="preceding::*[1]/@srcpath"/></value>
<value key="level">INT</value>
<value key="mode">wml-to-dbk</value>
<value key="info-text"><xsl:value-of select="."/></value>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<!-- standard Kommentar von Aspose nicht warnen -->
<xsl:template match="comment()[matches(., '^ Generated by Aspose')]" mode="wml-to-dbk"/>
<!-- default for PIs -->
<xsl:template match="processing-instruction()" mode="wml-to-dbk">
<xsl:call-template name="signal-error" xmlns="">
<xsl:with-param name="error-code" select="'W2D_023'"/>
<xsl:with-param name="fail-on-error" select="$fail-on-error"/>
<xsl:with-param name="hash">
<value key="xpath"><xsl:value-of select="preceding::*[1]/@srcpath"/></value>
<value key="level">INT</value>
<value key="mode">wml-to-dbk</value>
<value key="info-text"><xsl:value-of select="."/></value>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="w:commentRels" mode="wml-to-dbk"/>
<!-- element section -->
<xsl:template match="w:document" mode="wml-to-dbk">
<xsl:apply-templates select="@* except @srcpath, *" mode="wml-to-dbk"/>
</xsl:template>
<xsl:template match="@mc:Ignorable" mode="wml-to-dbk"/>
<!-- collateral, has to happen before wml-to-hub because redundant xml:lang attributes will
be eliminated then (redundant = same as this top-level language) -->
<xsl:template match="/dbk:*" mode="docx2hub:join-instrText-runs">
<xsl:copy>
<xsl:apply-templates select="@*" mode="#current"/>
<xsl:variable name="most-frequent-lang" select="docx2hub:most-frequent-lang(.)" as="xs:string?"/>
<xsl:if test="exists($most-frequent-lang) and not($most-frequent-lang eq 'x')">
<xsl:attribute name="xml:lang" select="$most-frequent-lang"/>
</xsl:if>
<xsl:apply-templates mode="#current">
<xsl:with-param name="most-frequent-lang" select="$most-frequent-lang" as="xs:string?" tunnel="yes"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:function name="docx2hub:most-frequent-lang" as="xs:string?">
<xsl:param name="context" as="element(*)"/>
<xsl:variable name="langs" as="xs:string*">
<xsl:for-each-group select="$context//w:t" group-by="docx2hub:text-lang(.)">
<xsl:sort select="string-length(string-join(current-group(), ''))" order="descending"/>
<xsl:sequence select="current-grouping-key()"/>
</xsl:for-each-group>
</xsl:variable>
<xsl:sequence select="$langs[1]"/>
</xsl:function>
<xsl:function name="docx2hub:text-lang" as="xs:string?">
<xsl:param name="text" as="element(w:t)"/>
<xsl:variable name="closest" select="$text/ancestor::*[@xml:lang | @role[key('style-by-name', ., root($text))/@xml:lang]][1]" as="element(*)?"/>
<xsl:sequence select="($closest/@xml:lang, key('style-by-name', $closest/@role, root($text))/@xml:lang)[1]"/>
</xsl:function>
<!-- changes in this commit: because of vr_SB_525-12345_NESTOR-Testdaten-01 ($most-frequent-lang) -->
<xsl:template match="w:p | w:r" mode="docx2hub:join-instrText-runs">
<xsl:copy>
<xsl:call-template name="docx2hub:adjust-lang"/>
<xsl:apply-templates select="@*, node()" mode="#current"/>
</xsl:copy>
</xsl:template>
<xsl:template name="docx2hub:adjust-lang">
<xsl:param name="most-frequent-lang" as="xs:string?" tunnel="yes"/>
<xsl:choose>
<xsl:when test="empty(@role | ancestor::w:p[1]/@role)
and
not($most-frequent-lang = ancestor-or-self::*[@xml:lang][1]/@xml:lang)">
<xsl:copy-of select="ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
</xsl:when>
<xsl:when test="exists(w:r[w:t[matches(., '\w')]])
and
(every $run in w:r[w:t[matches(., '\w')]]
satisfies (($run/@xml:lang, key('docx2hub:style-by-role', $run/@role))[1] = $most-frequent-lang)
)
and not($most-frequent-lang eq 'x')">
<xsl:attribute name="xml:lang" select="$most-frequent-lang"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="@css:font-stretch[.='normal']" mode="docx2hub:join-instrText-runs">
<!-- <w:w w:val="98"/> is an override, but it will be mapped to 'normal'. Unless this is different
from the style’s font-stretch property, remove this property -->
<!-- assuming they are only on w:r, not also on w:p -->
<xsl:variable name="rule" as="element(css:rule)?" select="key('docx2hub:style-by-role', ../@role)"/>
<xsl:if test="exists($rule/@css:font-stretch[not(.='normal')])">
<xsl:next-match/>
</xsl:if>
</xsl:template>
<xsl:template match="/dbk:*" mode="wml-to-dbk">
<xsl:variable name="citavi-refs" as="document-node()?">
<xsl:call-template name="docx2hub:citavi-json-to-xml"/>
</xsl:variable>
<xsl:variable name="csl-refs" as="document-node()?">
<xsl:call-template name="docx2hub:csl-json-to-xml"/>
</xsl:variable>
<xsl:copy>
<xsl:apply-templates select="@*, *" mode="#current">
<xsl:with-param name="citavi-refs" select="$citavi-refs" as="document-node()?" tunnel="yes"/>
<xsl:with-param name="csl-refs" select="$csl-refs" as="document-node()?" tunnel="yes"/>
</xsl:apply-templates>
<xsl:call-template name="insert-bibliography">
<xsl:with-param name="citavi-refs" select="$citavi-refs" as="document-node()?"/>
<xsl:with-param name="csl-refs" select="$csl-refs" as="document-node()?"/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:variable name="docx2hub:formatted-CSL-bibliography" as="xs:boolean"
select="true()"/>
<xsl:variable name="docx2hub:formatted-Citavi-bibliography" as="xs:boolean"
select="true()"/>
<xsl:template name="insert-bibliography">
<xsl:param name="citavi-refs" as="document-node()?"/>
<xsl:param name="csl-refs" as="document-node()?"/>
<xsl:variable name="citavi-bib" as="element(dbk:biblioentry)*">
<xsl:choose>
<xsl:when test="$citavi-refs/docx2hub:citavi-xml">
<xsl:for-each-group select="$citavi-refs/docx2hub:citavi-xml/Placeholder/Entries/Entry/Reference"
group-by="Id">
<xsl:apply-templates select="." mode="citavi"/>
</xsl:for-each-group>
</xsl:when>
<xsl:when test="$citavi-refs/docx2hub:citavi-jsons">
<xsl:for-each-group select="$citavi-refs/docx2hub:citavi-jsons/fn:map/fn:array/fn:map/fn:map[@key = 'Reference']"
group-by="fn:string[@key = 'Id']">
<xsl:apply-templates select="." mode="citavi"/>
</xsl:for-each-group>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="csl-bib" as="element(dbk:biblioentry)*">
<xsl:apply-templates mode="csl"
select="$csl-refs//fn:*[@key = 'citationItems']//fn:*[@key = 'itemData']"/>
</xsl:variable>
<xsl:if test="$docx2hub:formatted-Citavi-bibliography and $root//*:CITAVI_XML/w:p[normalize-space()]">
<bibliography role="Citavi-formatted">
<xsl:apply-templates select="$root//*:CITAVI_XML/w:p[normalize-space()]" mode="#current">
<xsl:with-param name="is-bibliomixed" select="true()" tunnel="yes"/>
</xsl:apply-templates>
</bibliography>
</xsl:if>
<xsl:if test="exists($citavi-bib)">
<bibliography role="Citavi">
<xsl:sequence select="$citavi-bib"/>
</bibliography>
</xsl:if>
<xsl:if test="$docx2hub:formatted-CSL-bibliography and $root//*:CSL_XML/w:p[normalize-space()]">
<bibliography role="CSL-formatted">
<xsl:apply-templates select="$root//*:CSL_XML/w:p[normalize-space()]" mode="#current">
<xsl:with-param name="is-bibliomixed" select="true()" tunnel="yes"/>
</xsl:apply-templates>
</bibliography>
</xsl:if>
<xsl:if test="exists($csl-bib)">
<bibliography role="CSL">
<xsl:sequence select="$csl-bib"/>
</bibliography>
</xsl:if>
<xsl:if test="contains($debug-dir-uri, 'debug-json-to-xml-bibliography=yes')">
<bibliography role="debug">
<xsl:sequence select="$csl-refs/node()"/>
<xsl:comment>SEP</xsl:comment>
<xsl:sequence select="$citavi-refs/node()"/>
</bibliography>
</xsl:if>
</xsl:template>
<!-- paragraphs (w:p) -->
<xsl:variable name="docx2hub:allowed-para-element-names" as="xs:string+"
select="('w:r',
'w:pPr',
'w:bookmarkStart',
'w:bookmarkEnd',
'w:smartTag',
'w:commentRangeStart',
'w:commentRangeEnd',
'w:proofErr',
'w:hyperlink',
'w:del',
'w:ins',
'w:fldSimple',
'm:oMathPara',
'm:oMath')" />
<xsl:template match="w:p" mode="wml-to-dbk">
<xsl:element name="para">
<xsl:apply-templates select="@* except @*[matches(name(),'^w:rsid')]" mode="#current"/>
<xsl:if test="w:r[1][count(*)=1][w:br[@w:type='page']]">
<xsl:attribute name="css:page-break-before" select="'always'"/>
</xsl:if>
<xsl:if test="w:r[last()][count(*)=1][w:br[@w:type='page']] and count(w:r[count(*)=1][w:br[@w:type='page']]) gt 1">
<xsl:attribute name="css:page-break-after" select="'always'"/>
</xsl:if>
<xsl:if test="not(@docx2hub:removable='true')">
<xsl:sequence select="tr:insert-numbering(.)"/>
</xsl:if>
<xsl:if test="@w14:paraId and $keep-paraid=('yes','true')">
<xsl:element name="anchor">
<xsl:attribute name="role" select="'w14:paraId'"/>
<xsl:attribute name="xml:id" select="concat('paraId_',@w14:paraId)"/>
</xsl:element>
<xsl:element name="anchor">
<xsl:attribute name="role" select="'w14:textId'"/>
<xsl:attribute name="xml:id" select="concat('textId_',@w14:textId)"/>
</xsl:element>
</xsl:if>
<!-- Only necessary in tables? They'll get lost otherwise. -->
<xsl:variable name="bookmarkstart-before-p" as="element(w:bookmarkStart)*"
select="preceding-sibling::w:bookmarkStart[. >> current()/preceding-sibling::*[not(self::w:bookmarkStart or self::w:bookmarkEnd)][1]]"/>
<xsl:variable name="bookmarkstart-before-tc" as="element(w:bookmarkStart)*"
select="parent::w:tc[current() is w:p[1]]/preceding-sibling::w:bookmarkStart[. >> current()/parent::w:tc/preceding-sibling::*[not(self::w:bookmarkStart or self::w:bookmarkEnd)][1]]"/>
<xsl:variable name="bookmarkstart-before-tr" as="element(w:bookmarkStart)*"
select="parent::w:tc/parent::w:tr[current() is (w:tc/w:p)[1]]/preceding-sibling::w:bookmarkStart[. >> current()/parent::w:tc/parent::w:tr/preceding-sibling::*[not(self::w:bookmarkStart or self::w:bookmarkEnd)][1]]"/>
<xsl:variable name="bookmarkstart-before-tbl" as="element(w:bookmarkStart)*"
select="parent::w:tc/parent::w:tr/parent::w:tbl[current() is (w:tr/w:tc/w:p)[1]]/preceding-sibling::w:bookmarkStart[. >> current()/parent::w:tc/parent::w:tr/parent::w:tbl/preceding-sibling::*[not(self::w:bookmarkStart or self::w:bookmarkEnd)][1]]"/>
<xsl:variable name="bookmarkend-after-p" as="element(w:bookmarkEnd)*"
select="following-sibling::w:bookmarkEnd[. << current()/following-sibling::*[not(self::w:bookmarkEnd)][1]]"/>
<xsl:variable name="bookmarkend-after-tc" as="element(w:bookmarkEnd)*"
select="parent::w:tc[current() is w:p[last()]]/following-sibling::w:bookmarkEnd[. << current()/parent::w:tc/following-sibling::*[not(self::w:bookmarkEnd)][1]]"/>
<xsl:variable name="bookmarkend-after-tr" as="element(w:bookmarkEnd)*"
select="parent::w:tc/parent::w:tr[current() is (w:tc/w:p)[last()]]/following-sibling::w:bookmarkEnd[. << current()/parent::w:tc/parent::w:tr/following-sibling::*[not(self::w:bookmarkEnd)][1]]"/>
<xsl:variable name="bookmarkend-after-tbl" as="element(w:bookmarkEnd)*"
select="parent::w:tc/parent::w:tr/parent::w:tbl[current() is (w:tr/w:tc/w:p)[last()]]/following-sibling::w:bookmarkEnd[. << current()/parent::w:tc/parent::w:tr/parent::w:tbl/following-sibling::*[not(self::w:bookmarkEnd)][1]]"/>
<xsl:apply-templates select="$bookmarkstart-before-p | $bookmarkstart-before-tc | $bookmarkstart-before-tr | $bookmarkstart-before-tbl" mode="wml-to-dbk-bookmarkStart"/>
<xsl:apply-templates select="node() except dbk:tabs" mode="#current"/>
<xsl:apply-templates select="$bookmarkend-after-p | $bookmarkend-after-tc | $bookmarkend-after-tr | $bookmarkend-after-tbl" mode="wml-to-dbk-bookmarkEnd"/>
</xsl:element>
</xsl:template>
<!-- Verlauf -->
<xsl:template match="w:del" mode="wml-to-dbk">
<!-- gelöschten Text wegwerfen -->
</xsl:template>
<xsl:template match="w:ins" mode="wml-to-dbk">
<xsl:apply-templates select="node()" mode="#current"/>
</xsl:template>
<!-- footer (w:ftr) -->
<xsl:template match="w:ftr[$convert-footer]" mode="wml-to-dbk">
<xsl:message select="'[WARNING] $convert-footer is DEPRECATED: use p:option or xsl:param $include-header-and-footer instead.'"/>
<xsl:apply-templates select="node()" mode="#current"/>
</xsl:template>
<!-- bookmarks -->
<xsl:key name="docx2hub:bookmarkStart" match="w:bookmarkStart" use="@w:id"/>
<!-- mode wml-to-dbk-bookmarkStart is for transforming bookmarkStarts that used to be in between w:ps
within the paras where they belong -->
<xsl:template match="w:bookmarkStart" mode="wml-to-dbk wml-to-dbk-bookmarkStart">
<anchor role="start">
<xsl:apply-templates select="@w:name" mode="bookmark-id"/>
</anchor>
</xsl:template>
<xsl:key name="docx2hub:bookmarkStart-by-name" match="w:bookmarkStart[@w:name]"
use="for $n in docx2hub:normalize-name-for-id(@w:name) return ($n, upper-case($n), lower-case($n))"/>
<xsl:function name="docx2hub:normalize-name-for-id" as="xs:string?">
<xsl:param name="name" as="xs:string?"/>
<xsl:choose>
<xsl:when test="not($name)"/>
<xsl:when test="not(matches($name, '^\i'))">
<xsl:sequence select="docx2hub:normalize-name-for-id(concat('_', $name))"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="replace($name, '[^-_.a-z\d]', '_', 'i')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:template match="w:bookmarkStart/@w:name"
mode="bookmark-id" as="attribute(xml:id)">
<xsl:param name="end" select="false()"/>
<xsl:variable name="normalized-string" as="xs:string?" select="docx2hub:normalize-name-for-id(.)"/>
<xsl:attribute name="xml:id"
select=" replace(
replace(
string-join(
(
$normalized-string,
if (count(key('docx2hub:bookmarkStart-by-name', $normalized-string)) = 1) then () else ../@w:id,
if ($end) then 'end' else ()
),
'_'
),
'%20',
'_'),
'^(\I)',
'_$1'
)"/>
</xsl:template>
<!-- remove $bookmarkstart-before-p (see template for w:p above) outside of tables -->
<xsl:template match="w:bookmarkStart[following-sibling::w:p]" mode="wml-to-dbk"/>
<!-- remove $bookmarkend-after-p (see template for w:p above) outside of tables -->
<xsl:template match="w:bookmarkEnd[preceding-sibling::w:p]" mode="wml-to-dbk"/>
<xsl:template match="w:bookmarkEnd" mode="wml-to-dbk wml-to-dbk-bookmarkEnd">
<xsl:if test="exists(key('docx2hub:bookmarkStart', @w:id)[not(@w:name='_GoBack')])">
<xsl:variable name="start" select="key('docx2hub:bookmarkStart', @w:id)[not(@w:name='_GoBack')]" as="element(w:bookmarkStart)+"/>
<xsl:if test="count($start) gt 1">
<xsl:message select="'Multiple bookmarkStart IDs ', @w:id, $start"/>
</xsl:if>
<anchor role="end">
<xsl:variable name="id" as="attribute(xml:id)">
<xsl:apply-templates select="$start[1]/@w:name" mode="bookmark-id"/>
</xsl:variable>
<xsl:apply-templates select="$start[1]/@w:name" mode="bookmark-id">
<xsl:with-param name="end" select="true()"/>
</xsl:apply-templates>
<xsl:attribute name="linkend" select="$id"/>
</anchor>
</xsl:if>
</xsl:template>
<xsl:template match="w:bookmarkStart[@w:name eq '_GoBack']" mode="wml-to-dbk wml-to-dbk-bookmarkStart" priority="2"/>
<xsl:template match="w:bookmarkEnd[key('docx2hub:bookmarkStart', @w:id)/@w:name = '_GoBack']" mode="wml-to-dbk wml-to-dbk-bookmarkEnd" priority="2">
<xsl:if test="not(preceding::w:bookmarkStart[@w:id=current()/@w:id][1]/@w:name = '_GoBack')">
<xsl:next-match/>
</xsl:if>
</xsl:template>
<!-- comments -->
<xsl:template match="w:commentRangeStart" mode="wml-to-dbk">
<anchor role="start" xml:id="comment_{@w:id}"/>
</xsl:template>
<xsl:template match="w:commentRangeEnd" mode="wml-to-dbk">
<anchor role="end" xml:id="comment_{@w:id}_end"/>
</xsl:template>
<xsl:template match="w:proofErr" mode="wml-to-dbk"/>
<!-- paragraph properties (w:pPr) -->
<xsl:template match="w:pPr" mode="wml-to-dbk">
<!-- para properties are collected by para-props.xsl -->
</xsl:template>
<!-- run properties (w:rPr) -->
<xsl:template match="w:rPr" mode="wml-to-dbk">
<!-- run properties are collected when text nodes are handled -->
</xsl:template>
<!-- smartTags (w:smartTag) -->
<xsl:template match="w:smartTag" mode="wml-to-dbk">
<xsl:apply-templates mode="#current"/>
</xsl:template>
<!-- Hyperlinks -->
<xsl:template match="w:hyperlink" mode="wml-to-dbk">
<link>
<xsl:apply-templates select="@*, *" mode="#current"/>
</link>
</xsl:template>
<xsl:template match="w:hyperlink[@w:tooltip][$unwrap-tooltip-links = ('yes', 'true')]" mode="wml-to-dbk">
<xsl:apply-templates select="*" mode="#current"/>
</xsl:template>
<xsl:template match="@w:anchor[parent::w:hyperlink]" mode="wml-to-dbk" priority="1.5">
<xsl:choose>
<xsl:when test="exists(parent::w:hyperlink/@r:id)"/>
<xsl:otherwise>
<xsl:attribute name="linkend" select="docx2hub:normalize-name-for-id(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="@w:tooltip[parent::w:hyperlink]" mode="wml-to-dbk" priority="1.5">
<!-- p1609: The method by which this string is surfaced by an application is outside the scope of this Office Open XML Standard. -->
</xsl:template>
<xsl:template match="@r:id[parent::w:hyperlink]" mode="wml-to-dbk" priority="1.5">
<xsl:variable name="value" select="."/>
<xsl:variable name="rel-item" select="docx2hub:rel-lookup(.)" as="element(rel:Relationship)" />
<xsl:choose>
<xsl:when test="exists(parent::w:hyperlink/@w:anchor)">
<xsl:attribute name="xlink:href" select="concat(
$rel-item/@Target,
'#',
parent::w:hyperlink/@w:anchor
)"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="insert-target">
<xsl:with-param name="rel-item" select="$rel-item"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="insert-target">
<xsl:param name="rel-item" as="element(rel:Relationship)"/>
<xsl:choose>
<xsl:when test="$rel-item/@Type = 'http:https://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink'">
<xsl:attribute name="xlink:href" select="$rel-item/@Target" />
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="linkend" select="$rel-item/@Target"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="w:hyperlink/@w:history | w:hyperlink/@w:tgtFrame" mode="wml-to-dbk" priority="1.5"/>
<xsl:template match="w:smartTagPr" mode="wml-to-dbk"/>
<!-- textbox -->
<xsl:template match="w:txbxContent" mode="wml-to-dbk">
<xsl:apply-templates select="@* except @srcpath" mode="#current"/>
<xsl:apply-templates select="*" mode="#current"/>
</xsl:template>
<!-- runs (w:r) -->
<xsl:template match="w:r[@* except (@srcpath,@xml:lang[matches(.,'^$')])][not(count(*)=count(w:instrText))]" mode="wml-to-dbk">
<xsl:element name="phrase">
<xsl:apply-templates select="@* except @*[matches(name(),'^w:rsid')]" mode="#current"/>
<xsl:apply-templates select="*" mode="#current"/>
</xsl:element>
</xsl:template>
<xsl:template match="w:r" mode="wml-to-dbk">
<xsl:apply-templates select="*" mode="#current"/>
</xsl:template>
<!-- text (w:t) -->
<xsl:template match="w:t" mode="wml-to-dbk">
<xsl:apply-templates mode="#current"/>
</xsl:template>
<xsl:template match="@xml:lang" mode="wml-to-dbk" priority="5">
<xsl:variable name="context" select="." as="attribute(*)"/>
<xsl:variable name="ancestors-with-langs" as="element(*)+">
<xsl:for-each select="ancestor::*">
<xsl:copy>
<xsl:sequence select="key('style-by-name', @role)/(@xml:lang, @css:direction, @docx2hub:rtl-lang)"/>
<xsl:sequence select="@xml:lang except $context, ../@css:direction, ../@docx2hub:rtl-lang"/>
</xsl:copy>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="dir" as="xs:string?" select="($ancestors-with-langs, ..)[@docx2hub:rtl-lang][last()]/@docx2hub:rtl-lang"/>
<xsl:variable name="last-lang" select="($ancestors-with-langs[@docx2hub:rtl-lang][@css:direction = 'rtl'][last()]/@docx2hub:rtl-lang,
$ancestors-with-langs[@xml:lang][not(@css:direction = 'rtl')][last()]/@xml:lang)[last()]"/>
<!-- Only output the next specific xml:lang if its string value differs from the current one’s: -->
<xsl:if test="not($dir = 'rtl') and not($last-lang = $context) and not($context eq 'x')">
<xsl:attribute name="xml:lang" select="$context"/>
</xsl:if>
</xsl:template>
<xsl:template match="@docx2hub:rtl-lang" mode="wml-to-dbk" priority="5">
<xsl:variable name="context" select="." as="attribute(*)"/>