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
|
% $Id: tex4ht-docbook-xtpipes.tex 740 2020-06-13 22:35:32Z karl $
% htlatex tex4ht-docbook-xtpipes "xhtml,next,3" "" "-d./"
%
% Copyright 2009-2020 TeX Users Group
% Copyright 2000-2009 Eitan M. Gurari
% Released under LPPL 1.3c+.
% See tex4ht-cpright.tex for license text.
\documentclass{article}
\Configure{ProTex}{log,<<<>>>,title,list,`,[[]]}
\begin{document}
\input{common}
\input{tex4ht-cpright}
\input{tex4ht-dir}
%%%%%%%%%%%%%%%%%%
\part{Post Processing for DocBook Output Mode}
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
\section{Outline}
%%%%%%%%%%%%%%%%%%
\AtEndDocument{\OutputCodE\<docbook.4xt\>}
\Needs{"xmllint --valid --noout docbook.4xt"}
\<docbook.4xt\><<<
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xtpipes SYSTEM "xtpipes.dtd" >
<!-- docbook.4xt (`version), generated from `jobname.tex
Copyright (C) 2009-2010 TeX Users Group
Copyright (C) `CopyYear.2008. Eitan M. Gurari
`<TeX4ht copyright`> -->
<xtpipes preamble="yes" signature="docbook.4xt (`version)">
<sax content-handler="xtpipes.util.ScriptsManager"
lexical-handler="xtpipes.util.ScriptsManagerLH" >
`<db links`>
`<tabular hor lines`>
`<trim() para`>
</sax>
</xtpipes>
>>>
\AtEndDocument{\OutputCodE\<DbUtilities.java\>}
\ifdojava
\Needs{"
javac DbUtilities.java -d \XTPIPES
"}
\fi
\<DbUtilities.java\><<<
package tex4ht;
/* DbUtilities.java (`version), generated from `jobname.tex
Copyright (C) 2009-2010 TeX Users Group
Copyright (C) `CopyYear.2008. Eitan M. Gurari
`<TeX4ht copyright`> */
import org.w3c.dom.*;
public class DbUtilities {
`<static void cline(dom)`>
`<static void para(dom)`>
}
>>>
%%%%%%%%%%%%%%%%%%
\section{Trim Spaces of Paragraphs}
%%%%%%%%%%%%%%%%%%
\<trim() para\><<<
<script element="para" >
<dom name="." xml="." method="para" class="tex4ht.DbUtilities" />
</script>
>>>
\<static void para(dom)\><<<
public static void para(Node dom) {
Node pNode = dom.getFirstChild();
if( pNode.hasChildNodes() ){
Node child = pNode.getFirstChild();
if( child != null ){
if( (child.getNodeType() == Node.TEXT_NODE)
&&
((Text) child).getWholeText().trim().equals("")
){
pNode.removeChild( child );
} } }
if( pNode.hasChildNodes() ){
Node child = pNode.getLastChild();
if( child != null ){
if( (child.getNodeType() == Node.TEXT_NODE)
&&
((Text) child).getWholeText().trim().equals("")
){
pNode.removeChild( child );
} } }
if( pNode.hasChildNodes() ){
Node child = pNode.getFirstChild();
if( (child != null)
&& (child.getNextSibling() == null)
&& (child.getNodeType() == Node.TEXT_NODE)
){
String txt = ((Text) child).getWholeText();
String trm = txt.trim();
if( !trm.equals(txt) ){
((Text)child).replaceWholeText(trm);
} } }
}
>>>
%%%%%%%%%%%%%%%%%%
\section{Title Elements}
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
\section{Internal Links}
%%%%%%%%%%%%%%%%%%
Anchor within the document should use
\begin{center}
\verb+<link linkend="Ortsflaechen">...</link>+
\end{center}
without the `\verb+#+' character.
The ulink element is used for URLs.
\begin{center}
\verb+<ulink url="http://...">...</ulink>+
\end{center}
\<db links\><<<
<script element="ulink" >
<set name="ulink" >
`<open xslt script`>
`<ulink templates`>
`<close xslt script`>
</set>
<xslt name="." xml="." xsl="ulink" />
</script>
>>>
\<ulink templates\><<<
<xsl:template match=" ulink[
@url and starts-with( @url, '#')
]" >
<link>
<xsl:attribute name="linkend">
<xsl:value-of select=" substring( @url, 2 )" />
</xsl:attribute>
<xsl:apply-templates select="*|text()|comment()" />
</link>
</xsl:template>
>>>
%%%%%%%%%%%%%%%%%%
\section{tabular hor lines}
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%
\subsection{Outline}
%%%%%%%%%%%%%
\<tabular hor lines\><<<
<script element="tbody" >
<set name="dirt" >
`<open xslt script`>
`<tbody dirt templates`>
`<close xslt script`>
</set>
<set name="tbody" >
`<open xslt script`>
`<tbody templates`>
`<close xslt script`>
</set>
<xslt name="." xml="." xsl="tbody" />
<xslt name="." xml="." xsl="dirt" />
<dom name="." xml="." method="cline" class="tex4ht.DbUtilities" />
</script>
>>>
\<static void cline(dom)\><<<
public static void cline(Node dom) {
Node row, entry, para, nextrow;
Node node = dom.getFirstChild();
if( node != null ){
`<remove empty trailing rows`>
`<merge cline rows into non-line rows`>
}
}
>>>
\<remove empty trailing rows\><<<
row = node.getLastChild();
while( (row != null)
&& ( (entry = row.getLastChild()) != null)
&& ( (para = entry.getFirstChild()) != null)
&& ( para.getNextSibling() == null)
&& ( para.getFirstChild() == null)
){
node.removeChild(row);
row = node.getLastChild();
}
>>>
The merging of rows deal with cases similar to the following one.
\begin{verbatim}
<row>
<entry align="left">
<para> 1</para>
</entry>
<entry align="left" nameend="3" namest="2">
<para>2 to 3</para>
</entry>
</row>
<row role="cline">
<entry rowsep="0"/>
<entry rowsep="1"/>
<entry rowsep="1"/>
</row>
\end{verbatim}
\<merge cline rows into non-line rows\><<<
row = node.getFirstChild();
while( row != null ){
if( (row.getNodeType() == Node.ELEMENT_NODE)
&& ((Element) row).getAttribute("rowsep").equals("")
&& !((Element) row).getAttribute("role" ).equals("cline")
&& ((nextrow = row.getNextSibling()) != null)
&& (nextrow.getNodeType() == Node.ELEMENT_NODE)
&& ((Element) nextrow).getAttribute("role" ).equals("cline")
){
`<boolean compatible = ...`>
if( compatible ){
`<row += nextrow`>
node.removeChild(nextrow);
}
}
row = row.getNextSibling();
}
>>>
\<boolean compatible = ...\><<<
boolean compatible = true;
Node entry1 = row.getFirstChild();
Node entry2 = nextrow.getFirstChild();
while( true ){
if( (entry1 == null) || (entry2 == null) ){ break; }
int range;
try{
range =
Integer.parseInt( ((Element) entry1).getAttribute("nameend") )
-
Integer.parseInt( ((Element) entry1).getAttribute("namest") )
+
1;
} catch( Exception e){ range = 1;}
if( range > 1 ){
String rowsep = ((Element) entry2).getAttribute("rowsep");
while( --range > 0 ){
entry2 = entry2.getNextSibling();
if( entry2 == null ){
compatible = false;
break;
}
String value = ((Element) entry2).getAttribute("rowsep");
if( !value.equals( rowsep ) ){
compatible = false;
break;
}
}
}
if( !compatible ){ break; }
entry1 = entry1.getNextSibling();
entry2 = entry2.getNextSibling();
}
>>>
\<row += nextrow\><<<
entry1 = row.getFirstChild();
entry2 = nextrow.getFirstChild();
while( true ){
if( (entry1 == null) || (entry2 == null) ){ break; }
int range;
try{
range =
Integer.parseInt( ((Element) entry1).getAttribute("nameend") )
-
Integer.parseInt( ((Element) entry1).getAttribute("namest") )
+
1;
} catch( Exception e){ range = 1;}
((Element) entry1).setAttribute(
"rowsep",
((Element) entry2).getAttribute("rowsep") );
while( --range > 0 ){
entry2 = entry2.getNextSibling();
}
entry1 = entry1.getNextSibling();
entry2 = entry2.getNextSibling();
}
>>>
%%%%%%%%%%%%%
\subsection{Dirt Lines}
%%%%%%%%%%%%%
Can they be removed earlier at the latex pass?
\<tbody dirt templates\><<<
<xsl:template match=" row[
(count(child::entry) = 1)
and
( normalize-space(child::entry[1]/child::para[1]/child::comment())
= 'dirt'
)
]">
</xsl:template>
>>>
%%%%%%%%%%%%%
\subsection{hline}
%%%%%%%%%%%%%
\<tbody templates\><<<
<xsl:template match=" row[ @role = 'hline' ]" />
>>>
\<tbody templates\><<<
<xsl:template match=" row[ @role = 'hline' ]" />
<xsl:template match=" row[
following-sibling::*[1][ self::row[@role = 'hline'] ]
] ">
<xsl:copy>
<xsl:attribute name="rowsep">
<xsl:text>1</xsl:text>
</xsl:attribute>
<xsl:apply-templates select="*|@*|text()|comment()" />
</xsl:copy>
</xsl:template>
>>>
%%%%%%%%%%%%%
\subsection{cline}
%%%%%%%%%%%%%
\<tbody templates\><<<
<xsl:template match=" row[
(@role = 'cline')
and
preceding-sibling::*[1]
[ self::row[ not(@role) ] ]
and
( count(child::entry)
= count(preceding-sibling::*[1]/child::entry))
]" />
<xsl:template match=" row[
not(@role)
and
following-sibling::*[1][ self::row[@role = 'cline'] ]
and
( count(child::entry)
= count(following-sibling::*[1]/child::entry))
] ">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="*|text()|comment()" mode="cline" />
</xsl:copy>
</xsl:template>
>>>
\<tbody templates\><<<
<xsl:template match=" text()|comment() " mode="cline">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()|comment()" />
</xsl:copy>
</xsl:template>
>>>
\<tbody templates\><<<
<xsl:template match="*" mode="cline">
<xsl:copy>
<xsl:if test="self::entry">
<xsl:attribute name="rowsep">
<xsl:variable name="pos">
<xsl:value-of select="position()" />
</xsl:variable>
<xsl:value-of select="parent::row
/ following-sibling::*[1]
/ child::entry[position()=$pos]
/ @rowsep
" />
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="*|@*|text()|comment()" />
</xsl:copy>
</xsl:template>
>>>
%%%%%%%%%%%%%%%%%%
\section{Shared}
%%%%%%%%%%%%%%%%%%
\<open xslt script\><<<
<![CDATA[
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:db="http://docbook.org/ns/docbook"
>
<xsl:output omit-xml-declaration = "yes" />
>>>
\<close xslt script\><<<
<xsl:template match="*|@*|text()|comment()" >
<xsl:copy>
<xsl:apply-templates select="*|@*|text()|comment()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
]]>
>>>
\<get content template\><<<
<xsl:template match="*" mode="content" >
<xsl:choose>
<xsl:when test=" @class = 'char' " >
<xsl:text>x</xsl:text>
</xsl:when>
<xsl:when test=" not(
(@title = 'speech-extra') or (@class = 'accent-char')
) " >
<xsl:apply-templates select="*|text()" mode="content" />
</xsl:when>
</xsl:choose>
</xsl:template>
>>>
%%%%%%%%%%%%%%%%%%
\section{Copyright}
%%%%%%%%%%%%%%%%%%
\let\newfilename=\relax
\<copy right\><<<
/**********************************************************/ >>>
\<cont copy right\><<<
/* */
/* This work may be distributed and/or modified under the */
/* conditions of the LaTeX Project Public License, either */
/* version 1.3 of this license or (at your option) any */
/* later version. The latest version of this license is */
/* in */
/* http://www.latex-project.org/lppl.txt */
/* and version 1.3 or later is part of all distributions */
/* of LaTeX version 2003/12/01 or later. */
/* */
/* This work has the LPPL maintenance status "maintained".*/
/* */
/* The Current Maintainer of this work */
/* is the TeX4ht Project <http://tug.org/tex4ht>. */
>>>
\ifdojava
\AtEndDocument{\Needs{%
"pushd \XTPIPES || exit 1
;
jar cf tex4ht.jar *
;
popd
;
mv \XTPIPES tex4ht.jar \TEXMFTEXivBIN
;
cp \XTPIPES xtpipes/lib/*
\TEXMFTEXivXTPIPES
"}}
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|