summaryrefslogtreecommitdiff
path: root/help3xsl/online_transform.xsl
blob: 849a77f2e1ac2409a5bcaa0f020cb7c7a8acf182 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
<?xml version="1.0" encoding="UTF-8"?>
<!--
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes" method="html" doctype-system= "about:legacy-compat"/>

<xsl:include href="links.txt.xsl"/>
<!--
############################
# Variables and Parameters #
############################
//-->

<xsl:param name="local" />
<xsl:param name="root"/>
<xsl:param name="Language"/>
<xsl:param name="productname"/>
<xsl:param name="productversion"/>
<xsl:param name="xapian"/>

<xsl:param name="System" select="'WIN'"/>
<xsl:param name="imgtheme" select="''"/>
<xsl:param name="Id" />

<!-- General Usage -->
<xsl:variable name="am" select="'&amp;'"/>
<xsl:variable name="sl" select="'/'"/>
<xsl:variable name="qt" select="'&quot;'"/>

<!-- For calculating pixel sizes -->
<xsl:variable name="dpi" select="'96'"/>
<xsl:variable name="dpcm" select="'38'"/>
<xsl:variable name="dpmm" select="'3.8'"/>

<!-- Product brand variables used in the help files -->
<xsl:variable name="brand1" select="'$[officename]'"/>
<xsl:variable name="brand2" select="'$[officeversion]'"/>
<xsl:variable name="brand3" select="'%PRODUCTNAME'"/>
<xsl:variable name="brand4" select="'%PRODUCTVERSION'"/>

<!-- Installation -->
<xsl:variable name="online" select="$local!='yes'"/>
<xsl:variable name="target">
    <xsl:choose>
        <xsl:when test="$online"><xsl:value-of select="concat($productversion,'/')"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
    </xsl:choose>
</xsl:variable>

<!-- meta data variables from the help file -->
<xsl:variable name="filename" select="/helpdocument/meta/topic/filename"/>
<xsl:variable name="title" select="/helpdocument/meta/topic/title"/>

<!-- the other parameters given by the help caller -->

<xsl:variable name="pversion">
	<xsl:value-of select="translate($productversion,' ','')"/>
</xsl:variable>
<!-- this is were the images are -->

<xsl:variable name="lang" select="$Language"/>
<xsl:variable name="urlpre" select="$root"/>


<!-- generic Icon alt text -->
<xsl:variable name="alttext" select="concat($root,'text/shared/00/icon_alt.xhp')"/>

  <!-- parts of help and image urls -->

<xsl:variable name="img_url_prefix" select="concat($target,'media',$imgtheme,'/')"/>

<xsl:variable name="urlpost" select="concat('?Language=',$lang,$am,'System=',$System,$am,'UseDB=no')"/>

<xsl:variable name="linkprefix" select="concat($target,$lang,'/')"/>

<!--<xsl:variable name="linkpostfix" select="$urlpost"/>-->
<xsl:variable name="linkpostfix" select="''"/>

<!-- images for notes, tips and warnings -->
<xsl:variable name="iconsizestyle" select="'width:40px;height:40px;'"/>
<xsl:variable name="note_img" select="concat($img_url_prefix,'icon-themes/res/helpimg/note.svg')"/>
<xsl:variable name="tip_img" select="concat($img_url_prefix,'icon-themes/res/helpimg/tip.svg')"/>
<xsl:variable name="warning_img" select="concat($img_url_prefix,'icon-themes/res/helpimg/warning.svg')"/>

<!-- Strings for the help UI page -->
<xsl:variable name="tmp_href_ui"><xsl:value-of select="concat($urlpre,'text/shared/help/browserhelp.xhp')"/></xsl:variable>
<xsl:variable name="tmp_doc_ui" select="document($tmp_href_ui)"/>
<xsl:variable name ="ui_contents"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='contents']"/></xsl:variable>
<xsl:variable name ="ui_index"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='index']"/></xsl:variable>
<xsl:variable name ="ui_pholderall"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='pholderall']"/></xsl:variable>
<xsl:variable name ="ui_pholderchosen"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='pholderchosen']"/></xsl:variable>
<xsl:variable name ="ui_module"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='module']"/></xsl:variable>
<xsl:variable name ="ui_language"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='language']"/></xsl:variable>
<xsl:variable name ="ui_donate"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='donate']"/></xsl:variable>
<xsl:variable name ="ui_logo"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='LibreOfficeHelp']"/></xsl:variable>
<xsl:variable name ="ui_selectmodule"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='selectmodule']"/></xsl:variable>
<xsl:variable name ="ui_selectlang"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='selectlanguage']"/></xsl:variable>
<xsl:variable name ="ui_search"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='searchhelpcontents']"/></xsl:variable>
<xsl:variable name ="ui_copyclip"><xsl:apply-templates select="$tmp_doc_ui//variable[@id='copyclip']"/></xsl:variable>
<!--
#############
# Templates #
#############
//-->

<!-- Create the document skeleton -->
<xsl:template match="/">
    <xsl:variable name="htmlpage"><xsl:value-of select="concat(substring-before($filename,'.xhp'),'.html')"/></xsl:variable>
    <xsl:variable name="titleL10N">
        <xsl:call-template name="brand"><xsl:with-param name="string"><xsl:value-of select="$title"/></xsl:with-param></xsl:call-template>
    </xsl:variable>
    <xsl:variable name="install">
        <xsl:call-template name="tokenize">
            <xsl:with-param name="str" select="$filename"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="logoprodversion">
        <xsl:choose>
            <xsl:when test="$productversion='latest'"><xsl:value-of select="''"/></xsl:when>
            <xsl:otherwise><xsl:value-of select="$productversion"/></xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
<html lang="{$lang}">
    <head>
        <base href="{$install}"/>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <xsl:if test="$online">
            <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline' 'unsafe-eval'"/>
        </xsl:if>
        <title><xsl:value-of select="$titleL10N"/></title>
        <link rel="shortcut icon" href="{$target}media/navigation/favicon.ico"/>
        <link  type="text/css" href="{$target}normalize.css" rel="Stylesheet"/>
        <link  type="text/css" href="{$target}default.css" rel="Stylesheet"/>
        <link  type="text/css" href="{$target}prism.css" rel="Stylesheet"/>
        <script type="text/javascript" src="{$target}polyfills.js"></script>
        <script type="text/javascript" src="{$target}languages.js"></script>
        <script type="text/javascript" src="{$target}fuzzysort.js"></script>
        <script type="text/javascript" src="{$target}prism.js"></script>
        <script type="text/javascript" src="{$target}help2.js" defer=""></script>
        <script type="text/javascript" src="{$target}a11y-toggle.js" defer=""></script>
        <script type="text/javascript" src="{$target}{$lang}/langnames.js" defer=""></script>
        <script type="text/javascript" src="{$target}paginathing.js" defer=""></script>
        <script type="text/javascript" src="{$target}{$lang}/bookmarks.js" defer=""></script>
        <script type="text/javascript" src="{$target}{$lang}/contents.js" defer=""></script>
        <script type="text/javascript" src="{$target}help.js" defer=""></script>
        <meta name="viewport" content="width=device-width,initial-scale=1"/>
    </head>
    <body itemscope="true" itemtype="http://schema.org/TechArticle">
    <xsl:if test="$online">
        <!-- help2.js checks, if meta elements exist in the body -->
        <meta itemprop="version" content="{$productversion}"/>
        <meta itemprop="inLanguage" content="{$lang}"/>
        <meta itemprop="datePublished" content="2017"/>
        <meta itemprop="headline" content="{$titleL10N}"/>
    </xsl:if>
    <div class="header-extrawurst">
        <header>
            <div class="logo-container">
                <a class="logo" href="{$target}{$lang}/text/shared/05/new_help.html">
                    <div class="symbol"></div>
                    <p><xsl:value-of select="$ui_logo"/></p>
                </a>
            </div>
        </header>
        <div class="modules">
            <button type="button" data-a11y-toggle="modules-nav" id="modules" onclick="setupModules('{$target}', '{$lang}');">
                <xsl:value-of select="$ui_module"/>
            </button>
	    <nav id="modules-nav"/><!-- is filled in via setupModules() on demand -->
        </div>
        <xsl:if test="$online">
            <div class="lang">
                <button type="button" data-a11y-toggle="langs-nav" id="langs" onclick="setupLanguages('{$target}', '{$htmlpage}');">
                    <xsl:value-of select="$ui_language"/>
                </button>
                <nav id="langs-nav"/><!-- is filled in via setupLanguages() on demand -->
            </div>
        </xsl:if>
    </div>
    <aside class="rightside">
        <input id="accordion-1" name="accordion-menu" type="checkbox"/>
        <label for="accordion-1"><xsl:value-of select="$ui_contents"/></label>
        <div id="Contents" class="contents-treeview"></div>
    </aside>
    <aside class="leftside">
        <div id="Index">
        <div class="index-label"><xsl:value-of select="$ui_index"/> &#32;&#x1f50e;&#xfe0e;&#32;</div>
            <div id="Bookmarks">
                <xsl:variable name="pholder">
                    <xsl:choose>
                        <xsl:when test="not(contains($htmlpage, '/text/shared/explorer/database/')) and contains($htmlpage, '/text/shared/')">
                            <xsl:value-of select="$ui_pholderall"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="$ui_pholderchosen"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>
                <input id="search-bar" type="text" class="search" placeholder="{$pholder}"/>
                <nav class="index"></nav>
            </div>
        </div>
    </aside>
    <div id="DisplayArea" itemprop="articleBody">
        <xsl:apply-templates select="/helpdocument/body"/>
    </div>
    <div class="search-frame">
        <xsl:if test="$online">
            <xsl:if test="$xapian='yes'">
                <div class="xapian-omega-search">
                    <form name="P" method="get" action="/{$productversion}/{$lang}/search" target="_top">
                        <input id="omega-autofocus" type="search" name="P"/>
                        <input type="submit" class="xapian-omega-search-button" value="&#x1f50d;"/>
                    </form>
                </div>
            </xsl:if>
        </xsl:if>
      </div>
    <div class="donation-frame">
        <xsl:if test="$online">
            <div class="donation">
                <p><a href="https://www.libreoffice.org/donate/?pk_campaign=help" target ="_blank"><xsl:value-of select="$ui_donate"/></a></p>
            </div>
        </xsl:if>
    </div>
    <footer>
        <xsl:if test="$online">
            <p><a href="https://www.collaboraoffice.com/about-us/" target="_blank">About Us</a> | <a href="https://www.collaboraoffice.com/privacy-policy/" target="_blank">Privacy Policy</a> | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the <a href="https://www.mozilla.org/en-US/MPL/2.0/" target="_blank">Mozilla Public License v2.0</a>. “LibreOffice” and “The Document Foundation” are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in TDF's <a href="https://wiki.documentfoundation.org/TradeMark_Policy" target="_blank">trademark policy</a>. Collabora Office is derived from LibreOffice which was based on OpenOffice.org.</p>
        </xsl:if>
        <div id="DEBUG" class="debug">
            <h3 class="bug">Help content debug info:</h3>
            <p>This page is: <a href="https://opengrok.libreoffice.org/xref/help/source{$filename}" target="_blank"><xsl:value-of select="$filename"/></a></p>
            <p>Title is: <xsl:value-of select="$title"/></p>
            <p id="bm_module"></p>
            <p id="bm_system"></p>
            <p id="bm_HID"></p>
        </div>
    </footer>
    </body>
</html>
</xsl:template>

<!-- AHELP -->
<xsl:template match="ahelp">
	<xsl:if test="not(@visibility='hidden')"><span class="avis"><xsl:apply-templates /></span></xsl:if>
</xsl:template>

<!-- ALT -->
<xsl:template match="alt"/>

<!-- MATHML -->
<xsl:template match="math">
<div class="mathml"><xsl:apply-templates /></div>
</xsl:template>

<!-- BOOKMARK -->
<xsl:template match="bookmark">
	<a name="{@id}"></a>
	<xsl:choose>
		<xsl:when test="starts-with(@branch,'hid')" />
		<xsl:otherwise><xsl:apply-templates /></xsl:otherwise>
	</xsl:choose>
</xsl:template>
<xsl:template match="bookmark" mode="embedded" />

<!-- BOOKMARK_VALUE -->
<xsl:template match="bookmark_value">
    <xsl:variable name="aux1">
        <xsl:call-template name="brand">
            <xsl:with-param name="string" select="."/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:element name="meta">
        <xsl:attribute name="itemprop">keywords</xsl:attribute>
        <xsl:attribute name="content"><xsl:value-of select="translate($aux1,';',',')"/></xsl:attribute>
    </xsl:element>
</xsl:template>

<!-- BR -->
<xsl:template match="br"><br /></xsl:template>
<xsl:template match="br" mode="embedded"><br /></xsl:template>

<!-- CAPTION -->
<xsl:template match="caption" />

<!-- CASE -->
<xsl:template match="case"><xsl:call-template name="insertcase" /></xsl:template>
<xsl:template match="case" mode="embedded">
        <xsl:call-template name="insertcase">
            <xsl:with-param name="embedded" select="'yes'"/>
        </xsl:call-template>
</xsl:template>

<!-- CASEINLINE -->
<xsl:template match="caseinline"><xsl:call-template name="insertcase" /></xsl:template>
<xsl:template match="caseinline" mode="embedded">
	<xsl:call-template name="insertcase">
		<xsl:with-param name="embedded" select="'yes'"/>
	</xsl:call-template>
</xsl:template>

<!-- COMMENT -->
<xsl:template match="comment" />
<xsl:template match="comment" mode="embedded"/>

<!-- CREATED -->
<xsl:template match="created" />

<!-- DEFAULT -->
<xsl:template match="default"><xsl:call-template name="insertdefault" /></xsl:template>
<xsl:template match="default" mode="embedded">
	<xsl:call-template name="insertdefault">
		<xsl:with-param name="embedded" select="'yes'"/>
	</xsl:call-template>
</xsl:template>

<!-- DEFAULTINLINE -->
<xsl:template match="defaultinline"><xsl:call-template name="insertdefault" /></xsl:template>
<xsl:template match="defaultinline" mode="embedded">
	<xsl:call-template name="insertdefault">
		<xsl:with-param name="embedded" select="'yes'"/>
	</xsl:call-template>
</xsl:template>

<!-- EMBED -->
<xsl:template match="embed"><xsl:call-template name="resolveembed"/></xsl:template>
<xsl:template match="embed" mode="embedded"><xsl:call-template name="resolveembed"/></xsl:template>

<!-- EMBEDVAR -->
<xsl:template match="embedvar"><xsl:call-template name="resolveembedvar"/></xsl:template>
<xsl:template match="embedvar" mode="embedded"><xsl:call-template name="resolveembedvar"/></xsl:template>

<!-- EMPH -->
<xsl:template match="emph">
	<span class="emph"><xsl:apply-templates /></span>
</xsl:template>
<xsl:template match="emph" mode="embedded">
	<span class="emph"><xsl:apply-templates /></span>
</xsl:template>

<!-- SUB -->
<xsl:template match="sub">
	<sub><xsl:apply-templates /></sub>
</xsl:template>
<xsl:template match="sub" mode="embedded">
	<sub><xsl:apply-templates /></sub>
</xsl:template>

<!-- SUP -->
<xsl:template match="sup">
	<sup><xsl:apply-templates /></sup>
</xsl:template>
<xsl:template match="sup" mode="embedded">
	<sup><xsl:apply-templates /></sup>
</xsl:template>

<!-- FILENAME -->
<xsl:template match="filename"/>

<!-- HISTORY -->
<xsl:template match="history" />

<!-- IMAGE -->
<xsl:template match="image"><xsl:call-template name="insertimage"/></xsl:template>
<xsl:template match="image" mode="embedded"><xsl:call-template name="insertimage"/></xsl:template>

<!-- ITEM -->
<xsl:template match="item">
    <span class="{@type}">
<!-- Insert tooltip only to input classes and only if the content is longer than 3 characters -->
        <xsl:if test="@type='input' and string-length(.)>3">
            <xsl:attribute name="data-tooltip">
                <xsl:value-of select="$ui_copyclip"/>
            </xsl:attribute>
        </xsl:if>
        <xsl:apply-templates />
    </span>
</xsl:template>
<xsl:template match="item" mode="embedded">
    <span class="{@type}">
        <xsl:if test="@type='input' and string-length(.)>3">
            <xsl:attribute name="data-tooltip">
                <xsl:value-of select="$ui_copyclip"/>
            </xsl:attribute>
        </xsl:if>
        <xsl:apply-templates />
    </span>
</xsl:template>

<!-- LINK -->
<xsl:template match="link">
    <xsl:choose> <!-- don't insert the heading link to itself -->
        <xsl:when test="(concat('/',@href) = /helpdocument/meta/topic/filename) or (@href = /helpdocument/meta/topic/filename)">
            <xsl:apply-templates />
        </xsl:when>
        <xsl:when test="contains(child::embedvar/@href,'/00/00000004.xhp#wie')"> <!-- special treatment of howtoget links -->
            <xsl:call-template name="insert_howtoget">
                <xsl:with-param name="linkhref" select="@href"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:call-template name="createlink" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
<xsl:template match="link" mode="embedded">
	<xsl:call-template name="createlink"/>
</xsl:template>

<!-- LIST -->
<xsl:template match="list">
    <xsl:choose>
        <xsl:when test="@type='ordered'">
            <ol>
                <xsl:if test="@startwith">
                    <xsl:attribute name="start"><xsl:value-of select="@startwith"/></xsl:attribute>
                </xsl:if>
                <xsl:apply-templates />
            </ol>
        </xsl:when>
        <xsl:otherwise>
            <ul><xsl:apply-templates /></ul>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="list" mode="embedded">
    <xsl:choose>
        <xsl:when test="@type='ordered'">
            <ol>
                <xsl:if test="@startwith">
                    <xsl:attribute name="start"><xsl:value-of select="@startwith"/></xsl:attribute>
                </xsl:if>
                <xsl:apply-templates mode="embedded"/>
            </ol>
        </xsl:when>
        <xsl:otherwise>
            <ul><xsl:apply-templates mode="embedded"/></ul>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<!-- LISTITEM -->
<xsl:template match="listitem">
    <li><xsl:apply-templates /></li>
</xsl:template>

<xsl:template match="listitem" mode="embedded">
    <li><xsl:apply-templates mode="embedded"/></li>
</xsl:template>

<!-- META, SEE HEADER -->
<xsl:template match="meta" />

<!-- OBJECT -->
<xsl:template match="object">
    <xsl:if test="$online">
        <xsl:call-template name="insertobject"/>
    </xsl:if>
</xsl:template>
<xsl:template match="object" mode="embedded">
    <xsl:if test="$online">
        <xsl:call-template name="insertobject"/>
    </xsl:if>
</xsl:template>

<!-- PARAGRAPH -->
<xsl:template match="paragraph">
    <xsl:choose>

        <xsl:when test="@role='heading'">
            <xsl:call-template name="insertheading">
                <xsl:with-param name="level" select="@level"/>
            </xsl:call-template>
        </xsl:when>

        <xsl:when test="@role='note' or @role='tip' or @role='warning'">
            <xsl:call-template name="insertnote">
                <xsl:with-param name="type" select="@role" />
            </xsl:call-template>
        </xsl:when>

        <xsl:when test="contains(descendant::embedvar/@href,'/00/00000004.xhp#wie')"> <!-- special treatment of howtoget links -->
            <xsl:apply-templates />
        </xsl:when>

        <xsl:when test="@role='bascode' or @role='pycode'">
            <xsl:call-template name="brand">
                <xsl:with-param name="string" select="."/>
            </xsl:call-template>
        </xsl:when>

        <xsl:when test="@role='smathcode'">
            <p id="{@id}" class="smathcode"><span class="input" data-tooltip="{$ui_copyclip}"><xsl:apply-templates /></span></p>
        </xsl:when>

        <xsl:when test="@role='logocode'">
            <xsl:call-template name="insertlogocode" />
        </xsl:when>

        <xsl:otherwise>
            <xsl:call-template name="insertpara" />
        </xsl:otherwise>

    </xsl:choose>
</xsl:template>

<xsl:template match="paragraph" mode="embedded">
    <xsl:choose>
        <xsl:when test="@role='heading'">	<!-- increase the level of headings that are embedded -->
            <xsl:variable name="newlevel">
                <xsl:choose>
                    <xsl:when test="@level='1'"><xsl:value-of select="'2'"/></xsl:when>
                    <xsl:otherwise><xsl:value-of select="@level"/></xsl:otherwise>
                </xsl:choose>
            </xsl:variable>

            <xsl:call-template name="insertheading">
                <xsl:with-param name="level" select="$newlevel"/>
                <xsl:with-param name="embedded" select="'yes'"/>
            </xsl:call-template>
        </xsl:when>

        <xsl:when test="@role='note' or @role='tip' or @role='warning'">
            <xsl:call-template name="insertnote">
                <xsl:with-param name="type" select="@role" />
            </xsl:call-template>
        </xsl:when>

        <xsl:when test="contains(descendant::embedvar/@href,'/00/00000004.xhp#wie')"> <!-- special treatment of howtoget links -->
            <xsl:apply-templates />
        </xsl:when>

        <xsl:when test="@role='bascode' or @role='pycode'">
            <xsl:call-template name="brand">
                <xsl:with-param name="string" select="."/>
            </xsl:call-template>
        </xsl:when>

        <xsl:when test="@role='smathcode'">
            <p id="{@id}" class="smathcode"><span class="input" data-tooltip="{$ui_copyclip}"><xsl:apply-templates /></span></p>
        </xsl:when>

        <xsl:when test="@role='logocode'">
            <xsl:call-template name="insertlogocode" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:call-template name="insertpara" />
        </xsl:otherwise>

    </xsl:choose>
</xsl:template>

<!-- SECTION -->
<xsl:template match="section">
    <a name="{@id}"></a>
    <xsl:choose>
        <xsl:when test="@id='relatedtopics'">
            <div class="relatedtopics">
                <!--<xsl:variable name="href"><xsl:value-of select="concat($urlpre,'text/shared/00/00000004.xhp',$urlpost)"/></xsl:variable>-->
                <xsl:variable name="href"><xsl:value-of select="concat($urlpre,'text/shared/00/00000004.xhp')"/></xsl:variable>
                <xsl:variable name="anchor"><xsl:value-of select="'related'"/></xsl:variable>
                <xsl:variable name="doc" select="document($href)"/>
                <p class="related" itemprop="mentions">
                    <xsl:apply-templates select="$doc//variable[@id=$anchor]"/>
                </p>
                <div class="relatedbody" itemprop="mentions">
                    <xsl:apply-templates />
                </div>
            </div>
        </xsl:when>
        <xsl:when test="@id='howtoget'">
            <xsl:call-template name="insert_howtoget" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:apply-templates/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<!-- SECTION -->
<xsl:template match="section" mode="embedded">
    <a name="{@id}"></a>
    <xsl:apply-templates mode="embedded"/>
</xsl:template>

<!-- SORT -->
<xsl:template match="sort" >
    <xsl:variable name="order1">
        <xsl:choose>
            <xsl:when test="string-length(@order) = 0"><xsl:value-of  select="'ascending'"/></xsl:when>
            <xsl:otherwise><xsl:value-of select="concat(@order,'ending')"/></xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:apply-templates><xsl:sort order="{$order1}" select="descendant::paragraph"/></xsl:apply-templates>
</xsl:template>
<xsl:template match="sort" mode="embedded">
    <xsl:variable name="order1">
        <xsl:choose>
            <xsl:when test="string-length(@order) = 0"><xsl:value-of  select="'ascending'"/></xsl:when>
            <xsl:otherwise><xsl:value-of select="concat(@order,'ending')"/></xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:apply-templates><xsl:sort order="{$order1}" select="descendant::paragraph"/></xsl:apply-templates>
</xsl:template>

<!-- SWITCH -->
<xsl:template match="switch">
    <xsl:choose>
        <xsl:when test ="@select = 'sys'">
            <xsl:variable name="idsw" select="concat('swlnsys',generate-id())"/>
            <span id="{$idsw}" class="switch">
                <xsl:apply-templates />
            </span>
        </xsl:when>
        <xsl:when test ="@select = 'appl'">
            <xsl:variable name="idsw" select="concat('swlnappl',generate-id())"/>
            <span id="{$idsw}" class="switch">
                <xsl:apply-templates />
            </span>
        </xsl:when>
        <xsl:otherwise>
            <p class="debug">Unsupported switch condition.</p>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
<xsl:template match="switch" mode="embedded">
    <xsl:choose>
        <xsl:when test ="@select = 'sys'">
            <xsl:variable name="idsw" select="concat('swlnsys',generate-id())"/>
            <span id="{$idsw}" class="switch">
                <xsl:apply-templates mode="embedded"/>
            </span>
        </xsl:when>
        <xsl:when test ="@select = 'appl'">
            <xsl:variable name="idsw" select="concat('swlnappl',generate-id())"/>
            <span id="{$idsw}" class="switch">
                <xsl:apply-templates mode="embedded"/>
            </span>
        </xsl:when>
        <xsl:otherwise>
            <p class="debug">Unsupported switch condition.</p>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<!-- SWITCHINLINE -->
<xsl:template match="switchinline">
    <xsl:choose>
        <xsl:when test ="@select = 'sys'">
            <xsl:variable name="idsw" select="concat('swlnsys',generate-id())"/>
            <span id="{$idsw}" class="switchinline">
                <xsl:apply-templates />
            </span>
        </xsl:when>
        <xsl:when test ="@select = 'appl'">
            <xsl:variable name="idsw" select="concat('swlnappl',generate-id())"/>
            <span id="{$idsw}" class="switchinline">
                <xsl:apply-templates />
            </span>
        </xsl:when>
        <xsl:otherwise>
            <p class="debug">Unsupported switch condition.</p>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
<xsl:template match="switchinline" mode="embedded">
    <xsl:choose>
        <xsl:when test ="@select = 'sys'">
            <xsl:variable name="idsw" select="concat('swlnsys',generate-id())"/>
            <span id="{$idsw}" class="switchinline">
                <xsl:apply-templates mode="embedded"/>
            </span>
        </xsl:when>
        <xsl:when test ="@select = 'appl'">
            <xsl:variable name="idsw" select="concat('swlnappl',generate-id())"/>
            <span id="{$idsw}" class="switchinline">
                <xsl:apply-templates mode="embedded"/>
            </span>
        </xsl:when>
        <xsl:otherwise>
            <p class="debug">Unsupported switch condition.</p>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<!-- TABLE -->
<xsl:template match="table"><xsl:call-template name="inserttable"/></xsl:template>
<xsl:template match="table" mode="embedded"><xsl:call-template name="inserttable"/></xsl:template>

<!-- TABLECELL -->
<xsl:template match="tablecell">
    <xsl:choose>
        <xsl:when test="paragraph[@role='tablehead']">
            <td rowspan="{@rowspan}" colspan="{@colspan}" class='tableheadcell'><xsl:apply-templates /></td>
        </xsl:when>
        <xsl:otherwise>
            <td rowspan="{@rowspan}" colspan="{@colspan}"><xsl:apply-templates /></td>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
<xsl:template match="tablecell" mode="onecell"><xsl:apply-templates/></xsl:template>
<xsl:template match="tablecell" mode="icontable"><div class="iconcell"><xsl:apply-templates/></div></xsl:template>
<xsl:template match="tablecell" mode="embedded">
    <xsl:choose>
        <xsl:when test="paragraph[@role='tablehead']">
            <td rowspan="{@rowspan}" colspan="{@colspan}" class='tableheadcell'><xsl:apply-templates mode="embedded"/></td>
        </xsl:when>
        <xsl:otherwise>
            <td rowspan="{@rowspan}" colspan="{@colspan}"><xsl:apply-templates mode="embedded"/></td>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<!-- TABLEROW -->
<xsl:template match="tablerow"><tr><xsl:apply-templates /></tr></xsl:template>
<xsl:template match="tablerow" mode="onecell"><xsl:apply-templates mode="onecell"/></xsl:template>
<xsl:template match="tablerow" mode="icontable"><div class="icontable"><xsl:apply-templates mode="icontable"/></div></xsl:template>
<xsl:template match="tablerow" mode="embedded"><tr><xsl:apply-templates mode="embedded"/></tr></xsl:template>

<!-- TITLE -->
<xsl:template match="title"/>

<!-- TOPIC -->
<xsl:template match="topic"/>

<!-- VARIABLE -->
<xsl:template match="variable"><a name="{@id}"></a><xsl:apply-templates /></xsl:template>
<xsl:template match="variable" mode="embedded"><a name="{@id}"></a><xsl:apply-templates mode="embedded"/></xsl:template>

<xsl:template match="text()">
    <xsl:call-template name="brand">
        <xsl:with-param name="string"><xsl:value-of select="."/></xsl:with-param>
    </xsl:call-template>
</xsl:template>

<xsl:template match="text()" mode="embedded">
    <xsl:call-template name="brand">
        <xsl:with-param name="string"><xsl:value-of select="."/></xsl:with-param>
    </xsl:call-template>
</xsl:template>

<!-- XHP extensions (2018) -->
<!-- H1-H6 -->
<xsl:template match="h1 | h2 | h3 | h4 | h5 | h6">
    <xsl:element name="{local-name()}">
        <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute><xsl:apply-templates />
    </xsl:element>
</xsl:template>
<xsl:template match="h1 | h2 | h3 | h4 | h5 | h6" mode="embedded">
    <xsl:element name="{concat('h',substring-after(local-name(),'h') + 1)}">
        <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute><xsl:apply-templates mode="embedded"/>
    </xsl:element>
</xsl:template>

<!-- INPUT -->
<xsl:template match="input">
    <span class="input" data-tooltip="{$ui_copyclip}"><xsl:apply-templates /></span>
</xsl:template>
<xsl:template match="input" mode="embedded">
    <span class="input" data-tooltip="{$ui_copyclip}"><xsl:apply-templates mode="embedded"/></span>
</xsl:template>

<!--MENUITEM, KEYCODE, LITERAL, WIDGET-->
<xsl:template match="menuitem | keycode | literal | widget">
    <span class="{local-name()}"><xsl:apply-templates /></span>
</xsl:template>
<xsl:template match="menuitem | input | keycode | literal" mode="embedded">
    <span class="{local-name()}"><xsl:apply-templates mode="embedded"/></span>
</xsl:template>

<!--NOTE TIP AND WARNING-->
<xsl:template match="tip | note | warning">
    <xsl:variable name="imgsrc">
        <xsl:choose>
            <xsl:when test="local-name()='note'"><xsl:value-of select="$note_img"/></xsl:when>
            <xsl:when test="local-name()='tip'"><xsl:value-of select="$tip_img"/></xsl:when>
            <xsl:when test="local-name()='warning'"><xsl:value-of select="$warning_img"/></xsl:when>
        </xsl:choose>
    </xsl:variable>
    <div class="{local-name()}">
        <div class="noteicon"><img src="{$imgsrc}" alt="{local-name()}" title="{local-name()}" style="{$iconsizestyle}"/></div>
        <div class="notetext"><p id="{@id}"><xsl:apply-templates /></p></div>
    </div>
    <br/>
</xsl:template>
<xsl:template match="tip | note | warning" mode="embedded">
    <xsl:variable name="imgsrc">
        <xsl:choose>
            <xsl:when test="local-name()='note'"><xsl:value-of select="$note_img"/></xsl:when>
            <xsl:when test="local-name()='tip'"><xsl:value-of select="$tip_img"/></xsl:when>
            <xsl:when test="local-name()='warning'"><xsl:value-of select="$warning_img"/></xsl:when>
        </xsl:choose>
    </xsl:variable>
    <div class="{local-name()}">
        <div class="noteicon"><img src="{$imgsrc}" alt="{local-name()}" title="{local-name()}" style="{$iconsizestyle}"/></div>
        <div class="notetext"><p id="{@id}"><xsl:apply-templates mode="embedded"/></p></div>
    </div>
    <br/>
</xsl:template>

<!-- In case of missing help files -->
<xsl:template match="help-id-missing"><xsl:value-of select="$Id"/></xsl:template>

<!--
###################
# NAMED TEMPLATES #
###################
//-->

<!-- Branding -->
<xsl:template name="brand" >
    <xsl:param name="string"/>

    <xsl:choose>

        <xsl:when test="contains($string,$brand1)">
            <xsl:variable name="newstr">
                <xsl:value-of select="substring-before($string,$brand1)"/>
                <xsl:value-of select="$productname"/>
                <xsl:value-of select="substring-after($string,$brand1)"/>
            </xsl:variable>
            <xsl:call-template name="brand">
                <xsl:with-param name="string" select="$newstr"/>
            </xsl:call-template>
        </xsl:when>

        <xsl:when test="contains($string,$brand2)">
            <xsl:variable name="newstr">
                <xsl:value-of select="substring-before($string,$brand2)"/>
                <xsl:value-of select="$pversion"/>
                <xsl:value-of select="substring-after($string,$brand2)"/>
            </xsl:variable>
            <xsl:call-template name="brand">
                <xsl:with-param name="string" select="$newstr"/>
            </xsl:call-template>
        </xsl:when>

        <xsl:when test="contains($string,$brand3)">
            <xsl:variable name="newstr">
                <xsl:value-of select="substring-before($string,$brand3)"/>
                <xsl:value-of select="$productname"/>
                <xsl:value-of select="substring-after($string,$brand3)"/>
            </xsl:variable>
            <xsl:call-template name="brand">
                <xsl:with-param name="string" select="$newstr"/>
            </xsl:call-template>
        </xsl:when>

        <xsl:when test="contains($string,$brand4)">
            <xsl:variable name="newstr">
                <xsl:value-of select="substring-before($string,$brand4)"/>
                <xsl:value-of select="$pversion"/>
                <xsl:value-of select="substring-after($string,$brand4)"/>
            </xsl:variable>
            <xsl:call-template name="brand">
                <xsl:with-param name="string" select="$newstr"/>
            </xsl:call-template>
        </xsl:when>

        <xsl:otherwise>
            <xsl:value-of select="$string"/>
        </xsl:otherwise>
    </xsl:choose>

</xsl:template>

<!-- Insert Paragraph -->
<xsl:template name="insertpara">
    <xsl:variable name="role">
        <xsl:choose>
            <xsl:when test="ancestor::table">
                <xsl:value-of select="concat(@role,'intable')"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="@role"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <p id="{@id}" class="{$role}"><xsl:apply-templates /></p>
</xsl:template>

<xsl:template match="bascode">
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet">
        <xsl:attribute name="data-tooltip"><xsl:value-of select="$ui_copyclip"/></xsl:attribute>
        <pre><code class="language-visual-basic line-numbers"><xsl:apply-templates /></code></pre>
    </div>
</xsl:template>
<xsl:template match="bascode" mode="embedded">
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet">
        <xsl:attribute name="data-tooltip"><xsl:value-of select="$ui_copyclip"/></xsl:attribute>
        <pre><code class="language-visual-basic line-numbers"><xsl:apply-templates mode="embedded" /></code></pre>
    </div>
</xsl:template>

<xsl:template match="pycode">
    <div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet">
        <xsl:attribute name="data-tooltip"><xsl:value-of select="$ui_copyclip"/></xsl:attribute>
        <pre><code class="language-python line-numbers"><xsl:apply-templates /></code></pre>
    </div>
</xsl:template>
<xsl:template match="pycode" mode="embedded">
    <div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet">
        <xsl:attribute name="data-tooltip"><xsl:value-of select="$ui_copyclip"/></xsl:attribute>
        <pre><code class="language-python line-numbers"><xsl:apply-templates mode="embedded" /></code></pre>
    </div>
</xsl:template>

<!-- Insert Logo code snippet  -->
<xsl:template name="insertlogocode">
    <pre><xsl:apply-templates /></pre>
</xsl:template>

<!-- Insert "How to get Link" -->
<xsl:template name="insert_howtoget">
    <xsl:param name="linkhref" />
    <xsl:variable name="archive" select="'shared'"/>
    <xsl:variable name="tmp_href"><xsl:value-of select="concat($urlpre,'text/shared/00/00000004.xhp')"/></xsl:variable>
    <xsl:variable name="tmp_doc" select="document($tmp_href)"/>
    <div class="howtoget">
        <div>
            <p class="howtogetheader"><xsl:apply-templates select="$tmp_doc//variable[@id='wie']"/></p>
        </div>
        <div class="howtogetbody">
            <xsl:choose>
                <xsl:when test="$linkhref = ''"> <!-- new style -->
                    <xsl:apply-templates/>
                </xsl:when>
                <xsl:otherwise> <!-- old style -->
                    <xsl:variable name="href"><xsl:value-of select="concat($urlpre,substring-before($linkhref,'#'))"/></xsl:variable>
                    <xsl:variable name="anc"><xsl:value-of select="substring-after($linkhref,'#')"/></xsl:variable>
                    <xsl:variable name="docum" select="document($href)"/>
                    <xsl:call-template name="insertembed">
                        <xsl:with-param name="doc" select="$docum" />
                        <xsl:with-param name="anchor" select="$anc" />
                    </xsl:call-template>
                </xsl:otherwise>
            </xsl:choose>
        </div>
    </div>
    <br/>
</xsl:template>

<!-- Create a link -->
<xsl:template name="createlink">
    <xsl:choose>
        <xsl:when test="starts-with(@href,'http://') or starts-with(@href,'https://')">  <!-- web links -->
            <a target ="_blank" href="{@href}"><xsl:apply-templates /></a>
        </xsl:when>
        <xsl:when test="contains(@href,'#')"> <!-- internal links with bookmark -->
            <xsl:variable name="anchor"><xsl:value-of select="concat('#',substring-after(@href,'#'))"/></xsl:variable>
            <xsl:variable name="href"><xsl:value-of select="concat($linkprefix,substring-before(@href, 'xhp'),'html',$anchor,$linkpostfix)"/></xsl:variable>
            <a target ="_top" href="{$href}"><xsl:apply-templates /></a>
        </xsl:when>
        <xsl:otherwise>
            <xsl:variable name="href"><xsl:value-of select="concat($linkprefix,substring-before(@href, 'xhp'),'html',$linkpostfix)"/></xsl:variable>
            <a target ="_top" href="{$href}"><xsl:apply-templates /></a>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<!-- Insert Note, Warning, or Tip -->
<xsl:template name="insertnote">
    <xsl:param name="type" /> <!-- note, tip, or warning -->
    <xsl:variable name="imgsrc">
        <xsl:choose>
            <xsl:when test="$type='note'"><xsl:value-of select="$note_img"/></xsl:when>
            <xsl:when test="$type='tip'"><xsl:value-of select="$tip_img"/></xsl:when>
            <xsl:when test="$type='warning'"><xsl:value-of select="$warning_img"/></xsl:when>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="alt">
        <xsl:variable name="href"><xsl:value-of select="$alttext"/></xsl:variable>
        <xsl:variable name="anchor"><xsl:value-of select="concat('alt_',$type)"/></xsl:variable>
        <xsl:variable name="doc" select="document($href)"/>
        <xsl:apply-templates select="$doc//variable[@id=$anchor]" mode="embedded"/>
    </xsl:variable>
    <div class="{$type}">
        <div class="noteicon"><img src="{$imgsrc}" alt="{$alt}" title="{$alt}" style="{$iconsizestyle}"/></div>
        <div class="notetext"><p><xsl:apply-templates /></p></div>
    </div>
    <br/>
</xsl:template>

<!-- Insert a heading -->
<xsl:template name="insertheading">
        <xsl:param name="level" />
        <xsl:param name="embedded" />
        <xsl:element name="{concat('h',$level)}">
                <xsl:if test="$level = '1' or $level='2'">
                        <xsl:attribute name="itemprop"><xsl:text>articleSection</xsl:text></xsl:attribute>
                </xsl:if>
                <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
                <xsl:choose>
                    <xsl:when test="$embedded = 'yes'">
                        <xsl:apply-templates mode="embedded"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:apply-templates />
                    </xsl:otherwise>
                </xsl:choose>
        </xsl:element>
</xsl:template>

<!-- Evaluate a case or caseinline switch -->
<xsl:template name="insertcase">
    <xsl:param name="embedded" />
    <xsl:variable name="auxID" select="concat(@select,generate-id())"/>
    <xsl:choose>
        <xsl:when test="$embedded = 'yes'">
            <span hidden="true" id="{$auxID}" class="{@select}"><xsl:apply-templates mode="embedded"/></span>
        </xsl:when>
        <xsl:otherwise>
            <span hidden="true" id="{$auxID}" class="{@select}"><xsl:apply-templates/></span>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<!-- Evaluate a default or defaultinline switch -->
<xsl:template name="insertdefault">
    <xsl:param name="embedded" />
    <xsl:choose>
        <xsl:when test="parent::switch[@select='sys'] or parent::switchinline[@select='sys']">
            <xsl:variable name="auxID" select="concat('default',generate-id())"/>
            <xsl:choose>
                <xsl:when test="$embedded = 'yes'">
                    <span hidden="true" id="{$auxID}"><xsl:apply-templates mode="embedded"/></span>
                </xsl:when>
                <xsl:otherwise>
                    <span hidden="true" id="{$auxID}"><xsl:apply-templates /></span>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:when>
        <xsl:when test="parent::switch[@select='appl'] or parent::switchinline[@select='appl']">
            <xsl:variable name="auxID" select="concat('default',generate-id())"/>
            <xsl:choose>
                <xsl:when test="$embedded = 'yes'">
                    <span hidden="true" id="{$auxID}"><xsl:apply-templates mode="embedded"/></span>
                </xsl:when>
                <xsl:otherwise>
                    <span hidden="true" id="{$auxID}"><xsl:apply-templates /></span>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:when>
        <xsl:when test="parent::switch[@select='distrib'] or parent::switchinline[@select='distrib']"><!--TODO: fix this distrib case if relevant-->
            <xsl:if test="not(../child::case[@select=$distrib]) and not(../child::caseinline[@select=$distrib])">
                <xsl:choose>
                    <xsl:when test="$embedded = 'yes'">
                        <span hidden="true" itemprop="distrib" value="DEFDIST"><xsl:apply-templates mode="embedded"/></span>
                    </xsl:when>
                    <xsl:otherwise>
                        <span hidden="true" itemprop="distrib" value="DEFDIST"><xsl:apply-templates /></span>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<!-- evaluate embeds -->
<xsl:template name="insertembed">
    <xsl:param name="doc" />
    <xsl:param name="anchor" />
    <!-- different embed targets (also falsely used embed instead embedvar) -->
    <xsl:choose>
        <xsl:when test="$doc//section[@id=$anchor]"> <!-- first test for a section of that name -->
            <xsl:apply-templates select="$doc//section[@id=$anchor]" mode="embedded"/>
        </xsl:when>
        <xsl:when test="$doc//paragraph[@id=$anchor]"> <!-- then test for a para of that name -->
            <p class="embedded">
                <xsl:apply-templates select="$doc//paragraph[@id=$anchor]" mode="embedded"/>
            </p>
        </xsl:when>
        <xsl:when test="$doc//variable[@id=$anchor]"> <!-- then test for a variable of that name -->
            <p class="embedded">
                <xsl:apply-templates select="$doc//variable[@id=$anchor]" mode="embedded"/>
            </p>
        </xsl:when>
        <xsl:otherwise> <!-- then give up -->
            <p class="bug">D'oh! You found a bug (<xsl:value-of select="@href"/> not found).</p>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<!-- Insert an image -->
<xsl:template name="insertimage">
    <xsl:variable name="src2">
        <xsl:choose>
            <xsl:when test="starts-with(@src,'media/screenshots/')">
                <xsl:choose>
                    <xsl:when test="not(@localize=false) and not($lang='en-US')">
                        <xsl:variable name="tmp0" select="substring-before(@src, '/ui/')"/>
                        <xsl:variable name="tmp1" select="substring-after(@src, '/ui/')"/>
                        <xsl:variable name="tmp2" select="substring-before($tmp1,'/')"/>
                        <xsl:variable name="tmp3" select="substring-after($tmp1,'/')"/>
                        <xsl:value-of select="concat($target,$tmp0,'/ui/', $tmp2, '/',$lang,'/',$tmp3)"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="concat($target,@src)"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <!-- generic media file -->
            <xsl:when test="starts-with(@src,'media/')">
                <xsl:value-of select="concat($target,@src)"/>
            </xsl:when>
            <!-- handle icons -->
            <xsl:when test="not(starts-with(@src,'media/'))">
                <xsl:variable name="linklist">
                    <xsl:call-template name="linktxt"><xsl:with-param name="src1" select="@src"/></xsl:call-template>
                </xsl:variable>
                <xsl:variable name="aux00">
                    <xsl:choose>
                        <xsl:when test="substring($linklist,string-length($linklist) - 3, 4)='.png'">
                            <xsl:value-of select="concat(substring-before($linklist,'.png'),'.svg')"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="$linklist"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>
                <xsl:value-of select="concat($target,'media/icon-themes/',$aux00)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="concat($target,@src)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="imagestyle">
        <xsl:choose>
            <xsl:when test="starts-with(@src,'media/screenshots/')">
                <xsl:value-of select="'screenshot'"/>
            </xsl:when>
            <xsl:when test="starts-with(@src,'media/')">
                <xsl:value-of select="'genericimage'"/>
            </xsl:when>
            <xsl:when test="not(starts-with(@src,'media/'))">
                <xsl:value-of select="'iconimage'"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="'genericimage'"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="alt"><xsl:value-of select="./alt"/></xsl:variable>
    <xsl:variable name="width">
        <xsl:if test="string-length(@width)!=0">
            <xsl:call-template name="convert2px"><xsl:with-param name="value" select="@width"/></xsl:call-template>
        </xsl:if>
    </xsl:variable>
    <xsl:variable name="height">
        <xsl:if test="string-length(@height)!=0">
            <xsl:call-template name="convert2px"><xsl:with-param name="value" select="@height"/></xsl:call-template>
        </xsl:if>
    </xsl:variable>
    <img src="{$src2}" class="{$imagestyle}" alt="{$alt}" title="{$alt}" style="{concat('width:',$width,';height:',$height)}"/>
</xsl:template>

<!-- Insert an object -->
<xsl:template name="insertobject">
    <xsl:variable name="tmp_href"><xsl:value-of select="concat($urlpre,'text/shared/00/00000004.xhp')"/></xsl:variable>
    <xsl:variable name="tmp_doc" select="document($tmp_href)"/>
    <xsl:variable name="data">
        <xsl:value-of select="concat($img_url_prefix,@data)"/>
    </xsl:variable>
    <xsl:variable name="type"><xsl:value-of select="@type"/></xsl:variable>
    <xsl:variable name="width">
        <xsl:call-template name="convert2px"><xsl:with-param name="value" select="@width"/></xsl:call-template>
    </xsl:variable>
    <xsl:variable name="height">
        <xsl:call-template name="convert2px"><xsl:with-param name="value" select="@height"/></xsl:call-template>
    </xsl:variable>
    <xsl:variable name="auxID" select="concat('obj',generate-id())"/>
    <xsl:choose>
        <xsl:when test="starts-with(@type,'video/youtube')">
                <div id="mediadiv">
                    <iframe id="{@id}" src="{@data}" width="{$width}" height="{$height}" frameborder="0" allowfullscreen="true"></iframe>
                </div>
        </xsl:when>
        <xsl:when test="not(starts-with(@type,'video/youtube')) and starts-with(@type,'video')">
            <div id="mediadiv">
                <video src="{$data}" type="{@type}" width="{$width}" height="{$height}" controls="'1'"></video>
            </div>
        </xsl:when>
        <xsl:when test="starts-with(@type,'audio')">
            <div id="mediadiv">
                <audio src="{$data}" type="{@type}" controls="'1'"></audio>
            </div>
        </xsl:when>
        <xsl:when test="@type='application/vnd.oasis.opendocument.spreadsheet'">
            <xsl:variable name="src">
                <xsl:call-template name="addlang2path">
                    <xsl:with-param name="string" select="@data"/>
                </xsl:call-template>
            </xsl:variable>
            <div class="samplefilesection" id="{$auxID}">
            <h3><xsl:apply-templates select="$tmp_doc//variable[@id='samplefile']"/></h3>
            <a class="objectfiles" href="{concat($target,$src)}"><img src="{concat($target,'media/navigation/libo-calc.svg')}" width="25px" height="30px"></img></a>
            </div>
        </xsl:when>
        <xsl:when test="@type='application/vnd.oasis.opendocument.text'">
            <xsl:variable name="src">
                <xsl:call-template name="addlang2path">
                    <xsl:with-param name="string" select="@data"/>
                </xsl:call-template>
            </xsl:variable>
            <div class="samplefilesection" id="{$auxID}">
            <h3><xsl:apply-templates select="$tmp_doc//variable[@id='samplefile']"/></h3>
            <a class="objectfiles" href="{concat($target,$src)}"><img src="{concat($target,'media/navigation/libo-writer.svg')}" width="25px" height="30px"></img></a>
            </div>
        </xsl:when>
        <xsl:when test="@type='application/vnd.oasis.opendocument.presentation'">
            <xsl:variable name="src">
                <xsl:call-template name="addlang2path">
                    <xsl:with-param name="string" select="@data"/>
                </xsl:call-template>
            </xsl:variable>
            <div class="samplefilesection" id="{$auxID}">
            <h3><xsl:apply-templates select="$tmp_doc//variable[@id='samplefile']"/></h3>
            <a class="objectfiles" href="{concat($target,$src)}"><img src="{concat($target,'media/navigation/libo-impress.svg')}" width="25px" height="30px"></img></a>
            </div>
            </xsl:when>
        <xsl:when test="@type='application/vnd.oasis.opendocument.drawing'">
            <xsl:variable name="src">
                <xsl:call-template name="addlang2path">
                    <xsl:with-param name="string" select="@data"/>
                </xsl:call-template>
            </xsl:variable>
            <div class="samplefilesection" id="{$auxID}">
            <h3><xsl:apply-templates select="$tmp_doc//variable[@id='samplefile']"/></h3>
            <a class="objectfiles" href="{concat($target,$src)}"><img src="{concat($target,'media/navigation/libo-draw.svg')}" width="25px" height="30px"></img></a>
            </div>
        </xsl:when>
        <xsl:when test="@type='application/vnd.oasis.opendocument.formula'">
            <xsl:variable name="src">
                <xsl:call-template name="addlang2path">
                    <xsl:with-param name="string" select="@data"/>
                </xsl:call-template>
            </xsl:variable>
            <div class="samplefilesection" id="{$auxID}">
            <h3><xsl:apply-templates select="$tmp_doc//variable[@id='samplefile']"/></h3>
            <a class="objectfiles" href="{concat($target,$src)}"><img src="{concat($target,'media/navigation/libo-math.svg')}" width="25px" height="30px"></img></a>
            </div>
        </xsl:when>
        <xsl:when test="@type='application/vnd.oasis.opendocument.database'">
            <xsl:variable name="src">
                <xsl:call-template name="addlang2path">
                    <xsl:with-param name="string" select="@data"/>
                </xsl:call-template>
            </xsl:variable>
            <div class="samplefilesection" id="{$auxID}">
            <h3><xsl:apply-templates select="$tmp_doc//variable[@id='samplefile']"/></h3>
            <a class="objectfiles" href="{concat($target,$src)}"><img src="{concat($target,'media/navigation/libo-base.svg')}" width="25px" height="30px"></img></a>
            </div>
        </xsl:when>
        <xsl:otherwise>
            <object width="{$width}" height="{$height}" data="{$data}" type="{@type}"></object>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<!-- changing measure to pixel -->
<xsl:template name="convert2px">
    <xsl:param name="value"/>
    <xsl:choose>
        <xsl:when test="contains($value, 'cm')">
            <xsl:value-of select="concat(round(number(substring-before($value, 'cm')) * $dpcm),'px')"/>
        </xsl:when>
        <xsl:when test="contains($value, 'mm')">
            <xsl:value-of select="concat(round(number(substring-before($value, 'mm')) * $dpmm),'px')"/>
        </xsl:when>
        <xsl:when test="contains($value, 'in')">
            <xsl:value-of select="concat(round(number(substring-before($value, 'in')) * $dpi),'px')"/>
        </xsl:when>
        <xsl:when test="contains($value, 'px')">
            <xsl:value-of select="$value"/>
        </xsl:when>
        <xsl:otherwise>
<!--                      <xsl:message>measure_conversion.xsl: Find no conversion for <xsl:value-of select="$value"/> to 'px'!</xsl:message> -->
            <xsl:value-of select="concat($value, 'px;')"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<!-- Insert a Table -->
<xsl:template name="inserttable">
    <xsl:variable name="imgsrc">	<!-- see if we are in an image table -->
        <xsl:value-of select="tablerow/tablecell[1]/paragraph[1]/image/@src"/>
    </xsl:variable>

    <xsl:choose>
        <xsl:when test="count(descendant::tablecell)=1">
            <div class="onecell"><xsl:apply-templates mode="onecell"/></div>
        </xsl:when>

        <xsl:when test="descendant::tablecell[1]/descendant::image">
            <xsl:apply-templates mode="icontable"/>
        </xsl:when>

        <xsl:when test="@class='wide'">
            <table border="1" class="{@class}" cellpadding="0" cellspacing="0" width="100%" >
                <xsl:apply-templates />
            </table>
            <br/>
        </xsl:when>

        <xsl:when test="not(@class='')">
            <table border="1" class="{@class}" cellpadding="0" cellspacing="0" >
                <xsl:apply-templates />
            </table>
            <br/>
        </xsl:when>

        <xsl:otherwise>
            <table border="1" class="border" cellpadding="0" cellspacing="0" >
                <xsl:apply-templates />
            </table>
            <br/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="resolveembed">
    <div class="embedded">
        <xsl:variable name="href"><xsl:value-of select="concat($urlpre,substring-before(@href,'#'))"/></xsl:variable>
        <xsl:variable name="anc"><xsl:value-of select="substring-after(@href,'#')"/></xsl:variable>
        <xsl:variable name="docum" select="document($href)"/>
        <xsl:call-template name="insertembed">
            <xsl:with-param name="doc" select="$docum" />
            <xsl:with-param name="anchor" select="$anc" />
        </xsl:call-template>
    </div>
</xsl:template>

<xsl:template name="resolveembedvar">
    <xsl:if test="not(@href='text/shared/00/00000004.xhp#wie')"> <!-- special treatment if howtoget links -->
        <xsl:variable name="archive"><xsl:value-of select="concat(substring-before(substring-after(@href,'text/'),'/'),'/')"/></xsl:variable>
        <xsl:variable name="href"><xsl:value-of select="concat($urlpre,substring-before(@href,'#'))"/></xsl:variable>
        <xsl:variable name="anchor"><xsl:value-of select="substring-after(@href,'#')"/></xsl:variable>
        <xsl:variable name="doc" select="document($href)"/>
        <xsl:choose>
            <xsl:when test="$doc//variable[@id=$anchor]"> <!-- test for a variable of that name -->
                <xsl:apply-templates select="$doc//variable[@id=$anchor]" mode="embedded"/>
            </xsl:when>
            <xsl:otherwise> <!-- or give up -->
                <span class="bug">[<xsl:value-of select="@href"/> not found].</span>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:if>
</xsl:template>

<!-- Apply -->
<xsl:template name="apply">
    <xsl:param name="embedded" />
    <xsl:choose>
        <xsl:when test="$embedded = 'yes'">
            <xsl:apply-templates mode="embedded"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:apply-templates />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="filehtml">
   <xsl:param name="file"/>
   <xsl:value-of select="concat(substring-before($file,'.xhp'),'.html')"/>
</xsl:template>

<!-- recursive named template -->
<xsl:template name="tokenize">
    <xsl:param name="str" />
    <xsl:param name="result" select="''" />
    <xsl:choose>
        <xsl:when test="substring-after($str,'/')">
            <xsl:call-template name="tokenize">
                <xsl:with-param name="str" select="substring-after($str,'/')" />
                <xsl:with-param name="result" select="concat($result,'../')" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:choose>
                <xsl:when test="$online"><xsl:value-of select="concat('../',$result)" /></xsl:when>
                <xsl:otherwise><xsl:value-of select="$result" /></xsl:otherwise>
            </xsl:choose>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
<!--Add language to path for file -->
<xsl:template name="addlang2path">
    <xsl:param name="string"/>
    <xsl:choose>
        <xsl:when test="not($lang='en-US')">
            <xsl:variable name="tmpfn">
                <xsl:call-template name="substring-after-last">
                    <xsl:with-param name="string" select="$string"/>
                    <xsl:with-param name="char" select="'/'"/>
                </xsl:call-template>
            </xsl:variable>
            <xsl:value-of select="concat(substring-before($string, $tmpfn),$lang,'/',$tmpfn)"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$string"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="substring-after-last">
    <xsl:param name="string"/>
    <xsl:param name="char"/>
    <xsl:choose>
        <xsl:when test="contains($string, $char)">
            <xsl:call-template name="substring-after-last">
                <xsl:with-param name="string" select="substring-after($string, $char)"/>
                <xsl:with-param name="char" select="$char"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$string"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
</xsl:stylesheet>