-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlists.xsl
695 lines (641 loc) · 38.1 KB
/
lists.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
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:word200x="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:dbk="http://docbook.org/ns/docbook"
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:rel="http://schemas.openxmlformats.org/package/2006/relationships"
xmlns:exsl='http://exslt.org/common'
xmlns:saxon="http://saxon.sf.net/"
xmlns:tr="http://transpect.io"
xmlns:hub="http://transpect.io/hub"
xmlns:css="http://www.w3.org/1996/css"
xmlns="http://docbook.org/ns/docbook"
version="2.0"
xpath-default-namespace="http://docbook.org/ns/docbook"
exclude-result-prefixes = "w o v wx xs dbk pkg r rel word200x exsl saxon fn tr css">
<xsl:variable name="hub:orderedlist-mark-open-quote-regex" as="xs:string" select="'[‚„«‹›»“‘]?'"/>
<xsl:variable name="hub:itemizedlist-mark-chars-regex" as="xs:string"
select="'([·̶▪□●◻◼◽▶●−•\p{So}\p{Pd}⎯⮚-])'"/>
<!-- Do not use round brackets in hub:orderedlist-one-or-more-letter-chars-regex!
[A-Z] not followed by dot: confusion with people’s initials in indented paras -->
<xsl:variable name="hub:orderedlist-one-or-more-letter-chars-regex" as="xs:string"
select="'[a-z]|[A-Z]'"/>
<xsl:variable name="hub:orderedlist-mark-chars-regex" as="xs:string"
select="concat('[\(\[]?(([ivx]+|[IVX]+|', $hub:orderedlist-one-or-more-letter-chars-regex,'|\p{Zs}*\d+)(\.\d+)*)[.:]?[\)\]]?')"/>
<!-- orderedlist-mark-chars-regex: the case  (9) was not handled. perhas it should be done in the general regex as well?-->
<xsl:variable name="hub:itemizedlist-mark-regex" as="xs:string"
select="concat('^', $hub:itemizedlist-mark-chars-regex, '$')"/>
<xsl:variable name="hub:orderedlist-mark-regex" as="xs:string"
select="concat('^', $hub:orderedlist-mark-open-quote-regex, $hub:orderedlist-mark-chars-regex, '$')"/>
<xsl:variable name="hub:itemizedlist-mark-at-start-regex" as="xs:string"
select="concat('^', $hub:itemizedlist-mark-chars-regex, '([\p{Zs}\s]+|$)')"/>
<xsl:variable name="hub:orderedlist-mark-at-start-regex" as="xs:string"
select="concat('^(', $hub:orderedlist-mark-open-quote-regex, $hub:orderedlist-mark-chars-regex, ')([\p{Zs}\s]+|$)')"/>
<!-- var hub:equation-roles:
List of paragraph role attribute values to exclude from list processing.
-->
<xsl:variable name="hub:equation-roles" as="xs:string+" select="('Formula', 'Equation')" />
<!-- itemizedlist -->
<xsl:template match="orderedlist[
hub:is-itemized-list(.) and
listitem[1]/para[1]//phrase[
hub:same-scope(., current()/listitem[1]/para[1])
][hub:is-identifier(.)]
]" mode="hub:lists" priority="1">
<xsl:variable name="first-para" as="element(para)" select="listitem[1]/para[1]"/>
<xsl:variable name="identifier" as="element(phrase)"
select="($first-para//phrase[hub:same-scope(., $first-para)][hub:is-identifier(.)])[1]"/>
<itemizedlist mark="{hub:get-list-type-with-warning($identifier)}">
<!-- mark="{listitem[1]/para[1]//descendant::phrase[hub:is-identifier(.)]}" -->
<xsl:apply-templates mode="#current">
<xsl:with-param name="set-override" select="'no'" tunnel="yes"/>
<xsl:with-param name="identifier-needed" select="'no'" tunnel="yes"/>
</xsl:apply-templates>
</itemizedlist>
</xsl:template>
<!-- orderedlist -->
<xsl:template match="orderedlist[hub:is-ordered-list(.)]" mode="hub:lists">
<xsl:variable name="list-type" select="hub:get-list-type-with-warning(listitem/para[1]//phrase[hub:is-identifier(.)])"/>
<xsl:copy>
<xsl:attribute name="numeration" select="$list-type"/>
<xsl:apply-templates mode="#current">
<xsl:with-param name="set-override" select="'yes'" tunnel="yes"/>
<xsl:with-param name="identifier-needed" select="'no'" tunnel="yes"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="listitem" mode="hub:lists">
<xsl:param name="set-override" select="'no'" tunnel="yes"/>
<xsl:copy>
<xsl:if test="$set-override = 'yes'">
<xsl:attribute name="override" select="para[1]//phrase[hub:same-scope(., current())][hub:is-identifier(.)]"/>
</xsl:if>
<xsl:apply-templates mode="#current"/>
</xsl:copy>
</xsl:template>
<!-- variablelist -->
<xsl:template match="orderedlist[hub:is-variable-list(.)]" mode="hub:lists">
<variablelist>
<xsl:apply-templates mode="#current">
<xsl:with-param name="is-variable-list" select="true()"/>
</xsl:apply-templates>
</variablelist>
</xsl:template>
<xsl:template match="listitem[parent::orderedlist[hub:is-variable-list(.)]]" mode="hub:lists">
<xsl:param name="is-variable-list" select="false()"/>
<xsl:variable name="first-para" select="para[1]" as="element(para)?"/>
<xsl:variable name="tabs" select="$first-para//tab[not(@role) or @role='docx2hub:generated']
[not(parent::tabs)]
[hub:same-scope(., current())]"/>
<xsl:choose>
<xsl:when test="$is-variable-list and (not($first-para) or empty($tabs))"><!-- for ex., informaltable in listitem -->
<varlistentry>
<term/>
<xsl:copy>
<xsl:apply-templates select="node()" mode="#current"/>
</xsl:copy>
</varlistentry>
</xsl:when>
<xsl:when test="$is-variable-list">
<xsl:variable name="first-tab" select="$tabs[1]" as="element(tab)"/>
<varlistentry>
<term>
<xsl:apply-templates select="$first-para/@srcpath" mode="#current"/>
<xsl:sequence select="hub:split-term-at-tab($first-para,$first-tab)"/>
</term>
<xsl:copy>
<xsl:apply-templates select="node()[. << $first-para]" mode="#current"/>
<xsl:sequence select="hub:split-listitem-at-tab($first-para,$first-tab)"/>
<xsl:apply-templates select="node()[. >> $first-para]" mode="#current"/>
</xsl:copy>
</varlistentry>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*" mode="#current"/>
<xsl:attribute name="override" select="$first-para//phrase[hub:same-scope(., current())][hub:is-identifier(.)]"/>
<xsl:apply-templates mode="#current"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:function name="hub:split-term-at-tab">
<xsl:param name="node" as="node()"/>
<xsl:param name="split-point" as="node()"/>
<xsl:apply-templates select="$node/node() intersect $split-point/preceding::node()" mode="hub:lists-remove-identifier"/>
<xsl:if test="count($node/node() intersect $split-point) = 0">
<xsl:apply-templates select="hub:split-term-element-at-tab($node/node()[count(descendant::node() intersect $split-point)=1],$split-point)" mode="hub:lists"/>
</xsl:if>
</xsl:function>
<xsl:function name="hub:split-term-element-at-tab">
<xsl:param name="node" as="node()"/>
<xsl:param name="split-point" as="node()"/>
<xsl:element name="{$node/local-name()}">
<xsl:apply-templates select="$node/@*" mode="hub:lists"/>
<xsl:apply-templates select="$node/node() intersect $split-point/preceding::node()" mode="hub:lists"/>
<xsl:if test="count($node/node() intersect $split-point) = 0">
<xsl:apply-templates select="hub:split-term-element-at-tab($node/node()[count(descendant::node() intersect $split-point)=1],$split-point)" mode="hub:lists"/>
</xsl:if>
</xsl:element>
</xsl:function>
<xsl:function name="hub:split-listitem-at-tab">
<xsl:param name="node" as="node()"/>
<xsl:param name="split-point" as="node()"/>
<xsl:element name="{$node/local-name()}">
<xsl:apply-templates select="$node/@*" mode="hub:lists"/>
<xsl:if test="count($node/node() intersect $split-point) = 0">
<xsl:apply-templates select="hub:split-listitem-at-tab($node/node()[count(descendant::node() intersect $split-point)=1],$split-point)" mode="hub:lists"/>
</xsl:if>
<xsl:apply-templates select="$node/node() intersect $split-point/following::node()" mode="hub:lists"/>
</xsl:element>
</xsl:function>
<xsl:template match="node()[not(self::phrase[@role eq 'hub:identifier'])]" mode="hub:lists-remove-identifier">
<xsl:apply-templates select="." mode="hub:lists"/>
</xsl:template>
<xsl:template match="phrase[@role eq 'hub:identifier']" mode="hub:lists-remove-identifier">
<xsl:choose>
<xsl:when test="@css:*">
<xsl:copy>
<xsl:apply-templates select="@* except @role, node()" mode="hub:lists"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="hub:lists"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- continuations: -->
<xsl:template match="orderedlist[parent::listitem]
[hub:has-no-identifiers(.)]
[not(hub:is-variable-list(.))]
[hub:same-margin-left(., parent::listitem/para[1]/@margin-left)]"
mode="hub:lists" priority="1.5"><!-- higher priority than 1, which is the priority of the itemizedlist template (around line 50) -->
<xsl:apply-templates select="listitem/node()" mode="#current"/>
</xsl:template>
<!-- Set to ('phrase', 'anchor') if formatting around the marker shouldn’t impede marker recognition -->
<xsl:variable name="hub:ordered-list-marker-acceptable-markup" as="xs:string+" select="('anchor')"/>
<xsl:function name="hub:is-ordered-list-marker-acceptable-markup" as="xs:boolean">
<xsl:param name="node" as="element()"/>
<xsl:sequence select="empty($node//*[not(name() = $hub:ordered-list-marker-acceptable-markup)]
(: for better orderedlist support in DocBook/Hub we ignore a letter-spacing phrase element, atm :)
[not(self::phrase and count(@*) = 1 and @css:letter-spacing)]
)"/>
</xsl:function>
<xsl:variable name="hub:variable-list-exception-roles" select="($hub:equation-roles)" as="xs:string+"/>
<!-- Mischung aus Folgeabsätzen und Unterpunkten oder Listen verschiedenen Typs, die zerschnitten werden müssen -->
<xsl:template match="orderedlist[some $x in listitem/para[1]
satisfies exists($x//phrase[hub:same-scope(., $x)][hub:is-identifier(.)])
and not(hub:is-ordered-list(.))
and not(hub:is-itemized-list(.))
and not(hub:is-variable-list(.))]" mode="hub:lists">
<xsl:variable name="current" select="."/>
<xsl:for-each-group select="*"
group-adjacent="if (para[1][descendant::phrase[hub:same-scope(., current())][hub:is-identifier(.)][1]][not(@role=($hub:equation-roles))])
then
if (matches(para[1]/descendant::phrase[hub:same-scope(., current())][hub:is-identifier(.)][1], $hub:itemizedlist-mark-regex))
then 'itemizedlist'
else
if (matches(para[1]/descendant::phrase[hub:same-scope(., current())][hub:is-identifier(.)][1], $hub:orderedlist-mark-regex)
and para[1]/descendant::phrase[hub:same-scope(., current())][hub:is-identifier(.)][1]
[hub:is-ordered-list-marker-acceptable-markup(.)]
and (if (count($current/listitem) gt 1)
then count($current/listitem[matches(para[1]/descendant::phrase[hub:same-scope(., current())][hub:is-identifier(.)][1], $hub:orderedlist-mark-regex)
and para[1]/descendant::phrase[hub:same-scope(., current())][hub:is-identifier(.)][1]
[hub:is-ordered-list-marker-acceptable-markup(.)] ]) gt 1
else true()))
then 'orderedlist'
else 'variablelist'
else
if (hub:is-variable-list-listitem-without-phrase-identifier(para[1]))
then 'variablelist'
else 'nolist'">
<!-- <xsl:message select="'+#####', current-grouping-key(), para[1]/descendant::phrase[hub:same-scope(., current())][hub:is-identifier(.)][1]//text(), '###', count(distinct-values(for $para in current-group()/para return $para//phrase[hub:is-identifier(.)][hub:same-scope(., $para)])), '++', count(for $para in current-group()/para return $para//phrase[hub:is-identifier(.)][hub:same-scope(., $para)])"/>-->
<xsl:choose>
<xsl:when test="current-grouping-key() = 'itemizedlist'">
<xsl:for-each-group select="current-group()" group-adjacent="hub:get-list-type-with-warning(para[1]//phrase[hub:same-scope(.,current-group()[1]/para[1])][hub:is-identifier(.)][1])">
<itemizedlist mark="{current-grouping-key()}">
<xsl:apply-templates select="current-group()" mode="#current">
<xsl:with-param name="identifier-needed" tunnel="yes" select="'no'"/>
<xsl:with-param name="set-override" select="'no'" tunnel="yes"/>
</xsl:apply-templates>
</itemizedlist>
</xsl:for-each-group>
</xsl:when>
<xsl:when test="((current-grouping-key() = 'variablelist') and (every $first-para-in-listitem
in current-group()/self::listitem/para[1]
satisfies (not($first-para-in-listitem/@role = $hub:variable-list-exception-roles))))
or
(current-grouping-key() = 'orderedlist' and
(
count(distinct-values(for $para in current-group()/para return $para//phrase[hub:is-identifier(.)][hub:same-scope(., $para)]))
ne
count(for $para in current-group()/para return $para//phrase[hub:is-identifier(.)][hub:same-scope(., $para)])
)
)">
<variablelist>
<xsl:for-each select="current-group()">
<xsl:variable name="li" select="." as="element(listitem)"/>
<xsl:variable name="first-para" select="para[1]" as="element(para)?"/>
<varlistentry>
<xsl:choose>
<xsl:when test="$first-para//phrase[hub:same-scope(., $li/$first-para)][hub:is-identifier(.)]">
<term>
<xsl:sequence select="$first-para//phrase[hub:same-scope(., $li/$first-para)][hub:is-identifier(.)]"/>
</term>
<xsl:copy>
<para>
<xsl:apply-templates select="$first-para/@*,
$first-para/node()[hub:same-scope(., $li/$first-para)]
except (
$first-para/tab[preceding-sibling::*[1][self::phrase][hub:is-identifier(.)]],
$first-para//phrase[hub:same-scope(., $li/$first-para)][hub:is-identifier(.)]
)" mode="#current"/>
</para>
<xsl:apply-templates select="node()[. >> $li/$first-para]" mode="#current"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="first-tab" select="($first-para//tab[hub:same-scope(., current())][not(ancestor::tabs)])[1]"/>
<term>
<xsl:sequence select="hub:split-term-at-tab($first-para, $first-tab)"/>
</term>
<xsl:copy>
<xsl:sequence select="hub:split-listitem-at-tab($first-para, $first-tab)"/>
<xsl:apply-templates select="node()[. >> $li/$first-para]" mode="#current"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</varlistentry>
</xsl:for-each>
</variablelist>
</xsl:when>
<xsl:when test="current-grouping-key() = 'orderedlist'">
<xsl:choose>
<xsl:when test="hub:get-list-type-with-warning(current-group()/para[1]//phrase[hub:same-scope(.,current-group()[1]/para[1])][hub:is-identifier(.)][1])=('other','multiple')">
<xsl:for-each-group select="current-group()"
group-adjacent="hub:get-list-type-with-warning(para[1]//phrase[hub:same-scope(.,current-group()[1]/para[1])][hub:is-identifier(.)][1])">
<orderedlist numeration="{current-grouping-key()}">
<xsl:apply-templates select="current-group()" mode="#current">
<xsl:with-param name="set-override" select="'yes'" tunnel="yes"/>
<xsl:with-param name="identifier-needed" tunnel="yes" select="'no'"/>
</xsl:apply-templates>
</orderedlist>
</xsl:for-each-group>
</xsl:when>
<xsl:when test="hub:is-ordered-list-exception(current-group())">
<orderedlist numeration="{hub:get-list-type-with-warning(current-group()/para[1]//phrase[hub:same-scope(.,current-group()[1]/para[1])][hub:is-identifier(.)][1])}">
<xsl:apply-templates select="current-group()" mode="#current">
<xsl:with-param name="set-override" select="'no'" tunnel="yes"/>
<xsl:with-param name="identifier-needed" tunnel="yes" select="'yes'"/>
</xsl:apply-templates>
</orderedlist>
</xsl:when>
<xsl:otherwise>
<orderedlist numeration="{hub:get-list-type-with-warning(current-group()/para[1]//phrase[hub:same-scope(.,current-group()[1]/para[1])][hub:is-identifier(.)][1])}">
<xsl:apply-templates select="current-group()" mode="#current">
<xsl:with-param name="set-override" select="'yes'" tunnel="yes"/>
<xsl:with-param name="identifier-needed" tunnel="yes" select="'no'"/>
</xsl:apply-templates>
</orderedlist>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!--
<xsl:message>
<xsl:value-of select="current-group()/node()"/>
</xsl:message>
-->
<xsl:apply-templates select="current-group()/node()" mode="#current"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:template>
<xsl:function name="hub:is-ordered-list-exception" as="xs:boolean">
<xsl:param name="group"/>
<xsl:sequence select="false()"/>
</xsl:function>
<!-- indentations that are not list items as blockquote -->
<xsl:template match="orderedlist[not(hub:is-itemized-list(.))]
[not(hub:is-ordered-list(.))]
[not(hub:is-variable-list(.))]
[hub:has-no-identifiers(.)]
[if (parent::listitem/para[1]/@margin-left) then not(hub:same-margin-left(., parent::listitem/para[1]/@margin-left)) else true()]
[not(every $n in listitem/node() satisfies $n/self::para[hub:is-equation-para(.)]
)]"
mode="hub:lists">
<xsl:choose>
<xsl:when test="parent::listitem">
<xsl:apply-templates select="listitem/node()" mode="#current"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="every $n in listitem/node() satisfies $n[self::para[hub:is-equation-para(.)] or self::orderedlist]">
<xsl:apply-templates select="listitem/node()" mode="#current"/>
</xsl:when>
<xsl:when test="listitem[1][count(node()) eq 1][orderedlist]">
<xsl:apply-templates select="listitem[1]/node()" mode="#current"/>
<blockquote role="hub:lists">
<xsl:apply-templates select="listitem[position() gt 1]/node()" mode="#current"/>
</blockquote>
</xsl:when>
<xsl:otherwise>
<blockquote role="hub:lists">
<xsl:apply-templates select="listitem/node()" mode="#current"/>
</blockquote>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- identifier im listitem entfernen, wenn durch itemizedlist oder orderedlist erfasst -->
<xsl:function as="xs:boolean" name="hub:is-identifier-in-listitem">
<xsl:param name="node" as="element(phrase)"/>
<xsl:sequence select="boolean($node[@role = 'hub:identifier' and ancestor::listitem and not(ancestor::footnote) and not(ancestor::remark[@role = 'endnote']) and not(ancestor::para[@role=$hub:equation-roles])])"/>
</xsl:function>
<xsl:template match="phrase[hub:is-identifier-in-listitem(.)]//node()
| phrase[hub:is-identifier-in-listitem(.)]" mode="hub:lists">
<xsl:param name="identifier-needed" select="'yes'" tunnel="yes"/>
<xsl:choose>
<xsl:when test="$identifier-needed = 'no'">
<xsl:apply-templates mode="#current"/>
</xsl:when>
<xsl:otherwise>
<xsl:next-match/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="phrase[hub:is-identifier-in-listitem(.)]//processing-instruction()
| phrase[hub:is-identifier-in-listitem(.)]//anchor" mode="hub:lists" priority="1.5">
<xsl:sequence select="."/>
</xsl:template>
<!-- identifier-needed (tunnel) zuruecksetzen -->
<xsl:template match="informaltable | table | figure" mode="hub:lists">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="#current">
<xsl:with-param name="identifier-needed" select="'yes'" tunnel="yes"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<!-- Funktionen -->
<xsl:function name="hub:same-margin-left" as="xs:boolean">
<xsl:param name="list" as="element(*)"/>
<xsl:param name="margin" as="xs:string?"/>
<xsl:variable name="margin-int" select="xs:integer(number(($margin, 0)[1]))" as="xs:integer"/>
<xsl:value-of select="every $x in $list/listitem/para[1]/@margin-left[. castable as xs:integer]
satisfies abs(xs:integer($x) - $margin-int) le $hub:indent-epsilon"/>
</xsl:function>
<xsl:function name="hub:has-no-identifiers" as="xs:boolean">
<xsl:param name="list" as="element(*)"/>
<xsl:sequence select="if (hub:is-variable-list($list)) (: GI 2018-09-10: due to recently introduced heuristics,
a list may be identified as a variable list even if not every item contains an identifier :)
then false()
else
(
every $x in $list/listitem/para[1]
satisfies empty($x//phrase[hub:same-scope(., $x)][hub:is-identifier(.)])
)"/>
</xsl:function>
<xsl:function name="hub:is-itemized-list" as="xs:boolean">
<xsl:param name="list" as="element(*)"/>
<xsl:sequence select="if(
(
matches(
$list/listitem[1]/para[1]//phrase[hub:same-scope(., $list/listitem[1]/para[1])][hub:is-identifier(.)][1],
$hub:itemizedlist-mark-regex
)
and (
every $first-para-in-listitem in $list/listitem/para[1]
satisfies exists(
$first-para-in-listitem//phrase[hub:same-scope(., $first-para-in-listitem)][hub:is-identifier(.)]
)
)
and (
every $first-para-in-listitem in $list/listitem/para[1]
satisfies (
every $first-identifier
in $first-para-in-listitem//phrase[
hub:same-scope(., $first-para-in-listitem)][hub:is-identifier(.)
][1]
satisfies matches($first-identifier, $hub:itemizedlist-mark-regex)
)
)
)
or hub:is-itemized-list-because-we-know-better($list)
) then true() else false()"/>
</xsl:function>
<xsl:function name="hub:is-itemized-list-because-we-know-better" as="xs:boolean">
<xsl:param name="list" as="element(*)"/>
<xsl:sequence select="false()"/>
</xsl:function>
<xsl:function name="hub:is-ordered-list" as="xs:boolean">
<xsl:param name="list" as="element(*)"/>
<xsl:sequence select="(
exists(
$list/listitem/para[1]//phrase[hub:same-scope(., $list/listitem[1]/para[1])][hub:is-identifier(.)]
)
and (
every $first-para-in-listitem in $list/listitem/para[1]
satisfies exists(
$first-para-in-listitem//phrase[hub:same-scope(., $first-para-in-listitem)][hub:is-identifier(.)]
)
)
and (
hub:get-list-type(
for $para in $list/listitem/para[1]
return $para//phrase[hub:is-identifier(.)][hub:same-scope(., $para)][1]
) = $hub:known-ordered-list-types
)
and (
count(distinct-values(for $para in $list/listitem/para return string-join($para//phrase[hub:is-identifier(.)][hub:same-scope(., $para)]//text(), '')))
eq
count(for $para in $list/listitem/para return $para//phrase[hub:is-identifier(.)][hub:same-scope(., $para)])
)
)
or hub:is-ordered-list-because-we-know-better($list)"/>
</xsl:function>
<xsl:function name="hub:is-ordered-list-because-we-know-better" as="xs:boolean">
<xsl:param name="list" as="element(*)"/>
<xsl:sequence select="false()"/>
</xsl:function>
<xsl:function name="hub:is-above-variable-list-threshold" as="xs:boolean">
<xsl:param name="total-list-para-count" as="xs:integer"/>
<xsl:param name="var-list-para-count" as="xs:integer"/>
<xsl:choose>
<xsl:when test="$total-list-para-count eq 0">
<xsl:sequence select="false()"/>
</xsl:when>
<xsl:when test="$total-list-para-count le 5">
<xsl:sequence select="$var-list-para-count ge 0.6 * $total-list-para-count"/>
</xsl:when>
<xsl:when test="$total-list-para-count le 20">
<xsl:sequence select="$var-list-para-count ge 0.8 * $total-list-para-count"/>
</xsl:when>
<xsl:when test="$total-list-para-count le 40">
<xsl:sequence select="$var-list-para-count ge 0.9 * $total-list-para-count"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="$var-list-para-count ge 0.95 * $total-list-para-count"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="hub:is-variable-list" as="xs:boolean">
<xsl:param name="list" as="element(*)"/>
<xsl:variable name="first-paras" as="element(para)*" select="$list/listitem/para[1]"/>
<xsl:variable name="first-para-count" as="xs:integer" select="count($first-paras)"/>
<xsl:variable name="variable-list-paras-with-phrase-identifier" as="element(para)*"
select="$first-paras[hub:is-variable-list-listitem-with-phrase-identifier(.)
and
not(@role = 'Note' or hub:is-equation-para(.))]"/>
<xsl:variable name="variable-list-paras-without-phrase-identifier" as="element(para)*"
select="$first-paras[hub:is-variable-list-listitem-without-phrase-identifier(.)
and
not(@role = 'Note' or hub:is-equation-para(.))]"/>
<!--<xsl:if test="contains($list, 'der Behälter würde sicherlich zerstört ')">
<xsl:message select="'CCCCCCCCCCCCC ', count($variable-list-paras-with-phrase-identifier), ' ', count($variable-list-paras-without-phrase-identifier)
, 'fp:', exists($first-paras), ' glt:',hub:get-list-type(
for $first-para-in-listitem in $first-paras
return $first-para-in-listitem
//phrase[hub:is-identifier(.)][hub:same-scope(., $first-para-in-listitem)][1]
),
' above:', $first-para-count, count($variable-list-paras-with-phrase-identifier
| $variable-list-paras-without-phrase-identifier),hub:is-above-variable-list-threshold($first-para-count,
count($variable-list-paras-with-phrase-identifier
| $variable-list-paras-without-phrase-identifier)),
' text:',normalize-space($list)"></xsl:message>
</xsl:if>-->
<xsl:sequence select="(
exists($first-paras) (: we don’t require that every listitem needs a para
– there may be complete tables in listitem, for ex. :)
and
(
hub:get-list-type(
for $first-para-in-listitem in $first-paras
return $first-para-in-listitem
//phrase[hub:is-identifier(.)][hub:same-scope(., $first-para-in-listitem)][1]
) eq 'other'
and
hub:is-above-variable-list-threshold($first-para-count,
count($variable-list-paras-with-phrase-identifier
| $variable-list-paras-without-phrase-identifier))
or
hub:is-above-variable-list-threshold($first-para-count, count($variable-list-paras-without-phrase-identifier))
)
and
(every $p in $first-paras (: http://svn.le-tex.de/svn/ltxbase/Difftestdata/evolve-hub-lists/idml/VDE-S.idml,
's. dazu Beispiel im Anhang A 1.3' :)
satisfies (empty($p/@hub:tab-stop)))
)
or hub:is-variable-list-because-we-know-better($list)"/>
</xsl:function>
<!-- the function below can be used to extend the current
behaviour of hub:is-variable-list() -->
<xsl:function name="hub:is-variable-list-because-we-know-better" as="xs:boolean">
<xsl:param name="list" as="element(*)"/>
<xsl:sequence select="false()"/>
</xsl:function>
<xsl:function name="hub:is-variable-list-listitem-with-phrase-identifier" as="xs:boolean">
<xsl:param name="para" as="element(para)?"/>
<xsl:sequence select="exists(
$para//tab[not(@role = 'underline')][not(parent::tabs)][hub:same-scope(., $para)][1][
exists(
preceding::node()[self::phrase][hub:is-identifier(.)]
[hub:same-scope(., $para)]
)
]
)"/>
</xsl:function>
<xsl:function name="hub:is-variable-list-listitem-without-phrase-identifier" as="xs:boolean">
<xsl:param name="para" as="element(para)?"/>
<xsl:sequence select="not(
$para
//phrase[hub:is-identifier(.)][hub:same-scope(., $para)][1]
)
and exists(
($para//tab[not(parent::tabs)]
[not(@role = 'underline')]
[following-sibling::node()[normalize-space()]]
[hub:same-scope(., $para)])[1]/preceding::node()[not(
self::anchor |
self::text()[not(fn:normalize-space())]
)]
[. >> $para]
)"/>
</xsl:function>
<xsl:function name="hub:is-equation-para" as="xs:boolean">
<xsl:param name="para" as="element(*)"/>
<xsl:sequence select=" $para/@role = $hub:equation-roles
or (count($para/node()) = 1 and $para/inlineequation)"/>
</xsl:function>
<xsl:function name="hub:get-list-type-with-warning" as="xs:string">
<xsl:param name="marks" as="node()*"/>
<xsl:variable name="true-marks" select="for $x in $marks return replace($x, $hub:orderedlist-mark-regex, '$1')" as="xs:string*"/>
<xsl:variable name="mark" select="hub:get-list-type($marks)" as="xs:string" />
<xsl:choose>
<xsl:when test="$mark ne 'other'">
<xsl:value-of select="$mark" />
</xsl:when>
<xsl:otherwise>
<xsl:message>
Cannot determine type of ordered list. Markers (separator is ','): <xsl:value-of select="string-join($true-marks, ',')"/>
</xsl:message>
<xsl:sequence select="$mark" />
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:variable name="hub:known-ordered-list-types" as="xs:string*"
select="('lowerroman', 'upperroman', 'loweralpha', 'upperalpha')"/>
<xsl:function name="hub:get-list-type" as="xs:string">
<xsl:param name="marks" as="node()*"/>
<xsl:variable name="true-marks" as="xs:string*">
<xsl:apply-templates select="$marks" mode="hub:list-true-marks"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="exists($true-marks) and (every $x in $true-marks satisfies matches($x, '^[ivx]+$'))">lowerroman</xsl:when>
<xsl:when test="exists($true-marks) and (every $x in $true-marks satisfies matches($x, '^[IVX]+$'))">upperroman</xsl:when>
<xsl:when test="exists($true-marks)
and
(every $x in $true-marks satisfies matches($x, '^[a-z][a-z]?$'))
and
hub:is-incrementing-alpha-sequence($true-marks)">loweralpha</xsl:when>
<xsl:when test="exists($true-marks)
and
(every $x in $true-marks satisfies matches($x, '^[A-Z][A-Z]?$'))
and
hub:is-incrementing-alpha-sequence($true-marks)">upperalpha</xsl:when>
<xsl:when test="exists($true-marks) and
(every $x in $true-marks
satisfies matches($x, concat('^\p{Zs}*', $hub:orderedlist-mark-open-quote-regex, '[0-9]+$')))">arabic</xsl:when>
<xsl:when test="exists($true-marks) and (every $x in $true-marks satisfies matches($x, '^•$'))">bullet</xsl:when>
<xsl:when test="exists($true-marks) and (every $x in $true-marks satisfies matches($x, '^·$'))">bullet</xsl:when>
<xsl:when test="exists($true-marks) and (every $x in $true-marks satisfies matches($x, $hub:itemizedlist-mark-chars-regex))">
<xsl:value-of select="$marks" />
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="'other'" />
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:template match="node()" mode="hub:list-true-marks" as="xs:string" priority="10">
<!-- If someone changed …|[a-z]|… to …|[a-z][.:\)]|… in $hub:orderedlist-mark-regex, we need the double replace
because $1 then contains the punctuation. You might need to customize this template if you customized the regex further. -->
<xsl:sequence select="replace(replace(normalize-space(.), $hub:orderedlist-mark-regex, '$1'), '[.:\)\)]', '', 'i')"/>
</xsl:template>
<xsl:function name="hub:is-identifier" as="xs:boolean">
<xsl:param name="phrase" as="element(*)" />
<xsl:sequence select="exists($phrase/self::phrase)
and
$phrase/@role = 'hub:identifier'
and
not($phrase/ancestor::footnote)
and
not($phrase/ancestor::remark[@role eq 'endnote'])" />
</xsl:function>
</xsl:stylesheet>