Debian Codegraph @

texmf-dist/source/generic/tex4ht/tex4ht-docbook-xtpipes.tex

raw
1 % $Id: tex4ht-docbook-xtpipes.tex 740 2020-06-13 22:35:32Z karl $
2 % htlatex tex4ht-docbook-xtpipes "xhtml,next,3" "" "-d./"
3 %
4 % Copyright 2009-2020 TeX Users Group
5 % Copyright 2000-2009 Eitan M. Gurari
6 % Released under LPPL 1.3c+.
7 % See tex4ht-cpright.tex for license text.
8
9 \documentclass{article}
10 \Configure{ProTex}{log,<<<>>>,title,list,`,[[]]}
11 \begin{document}
12
13 \input{common}
14 \input{tex4ht-cpright}
15 \input{tex4ht-dir}
16
17
18
19 %%%%%%%%%%%%%%%%%%
20 \part{Post Processing for DocBook Output Mode}
21 %%%%%%%%%%%%%%%%%%
22
23
24 %%%%%%%%%%%%%%%%%%
25 \section{Outline}
26 %%%%%%%%%%%%%%%%%%
27
28 \AtEndDocument{\OutputCodE\<docbook.4xt\>}
29
30 \Needs{"xmllint --valid --noout docbook.4xt"}
31
32 \<docbook.4xt\><<<
33 <?xml version="1.0" encoding="UTF-8" ?>
34 <!DOCTYPE xtpipes SYSTEM "xtpipes.dtd" >
35 <!-- docbook.4xt (`version), generated from `jobname.tex
36 Copyright (C) 2009-2010 TeX Users Group
37 Copyright (C) `CopyYear.2008. Eitan M. Gurari
38 `<TeX4ht copyright`> -->
39 <xtpipes preamble="yes" signature="docbook.4xt (`version)">
40 <sax content-handler="xtpipes.util.ScriptsManager"
41 lexical-handler="xtpipes.util.ScriptsManagerLH" >
42 `<db links`>
43 `<tabular hor lines`>
44 `<trim() para`>
45 </sax>
46 </xtpipes>
47 >>>
48
49
50 \AtEndDocument{\OutputCodE\<DbUtilities.java\>}
51
52 \ifdojava
53 \Needs{"
54 javac DbUtilities.java -d \XTPIPES
55 "}
56 \fi
57
58 \<DbUtilities.java\><<<
59 package tex4ht;
60 /* DbUtilities.java (`version), generated from `jobname.tex
61 Copyright (C) 2009-2010 TeX Users Group
62 Copyright (C) `CopyYear.2008. Eitan M. Gurari
63 `<TeX4ht copyright`> */
64
65 import org.w3c.dom.*;
66 public class DbUtilities {
67 `<static void cline(dom)`>
68 `<static void para(dom)`>
69 }
70 >>>
71
72
73 %%%%%%%%%%%%%%%%%%
74 \section{Trim Spaces of Paragraphs}
75 %%%%%%%%%%%%%%%%%%
76
77 \<trim() para\><<<
78 <script element="para" >
79 <dom name="." xml="." method="para" class="tex4ht.DbUtilities" />
80 </script>
81 >>>
82
83
84 \<static void para(dom)\><<<
85 public static void para(Node dom) {
86 Node pNode = dom.getFirstChild();
87 if( pNode.hasChildNodes() ){
88 Node child = pNode.getFirstChild();
89 if( child != null ){
90 if( (child.getNodeType() == Node.TEXT_NODE)
91 &&
92 ((Text) child).getWholeText().trim().equals("")
93 ){
94 pNode.removeChild( child );
95 } } }
96 if( pNode.hasChildNodes() ){
97 Node child = pNode.getLastChild();
98 if( child != null ){
99 if( (child.getNodeType() == Node.TEXT_NODE)
100 &&
101 ((Text) child).getWholeText().trim().equals("")
102 ){
103 pNode.removeChild( child );
104 } } }
105 if( pNode.hasChildNodes() ){
106 Node child = pNode.getFirstChild();
107 if( (child != null)
108 && (child.getNextSibling() == null)
109 && (child.getNodeType() == Node.TEXT_NODE)
110 ){
111 String txt = ((Text) child).getWholeText();
112 String trm = txt.trim();
113 if( !trm.equals(txt) ){
114 ((Text)child).replaceWholeText(trm);
115 } } }
116 }
117 >>>
118
119
120
121 %%%%%%%%%%%%%%%%%%
122 \section{Title Elements}
123 %%%%%%%%%%%%%%%%%%
124
125
126
127 %%%%%%%%%%%%%%%%%%
128 \section{Internal Links}
129 %%%%%%%%%%%%%%%%%%
130
131
132 Anchor within the document should use
133
134 \begin{center}
135 \verb+<link linkend="Ortsflaechen">...</link>+
136 \end{center}
137
138 without the `\verb+#+' character.
139 The ulink element is used for URLs.
140
141 \begin{center}
142 \verb+<ulink url="http://...">...</ulink>+
143 \end{center}
144
145 \<db links\><<<
146 <script element="ulink" >
147 <set name="ulink" >
148 `<open xslt script`>
149 `<ulink templates`>
150 `<close xslt script`>
151 </set>
152 <xslt name="." xml="." xsl="ulink" />
153 </script>
154 >>>
155
156
157 \<ulink templates\><<<
158 <xsl:template match=" ulink[
159 @url and starts-with( @url, '#')
160 ]" >
161 <link>
162 <xsl:attribute name="linkend">
163 <xsl:value-of select=" substring( @url, 2 )" />
164 </xsl:attribute>
165 <xsl:apply-templates select="*|text()|comment()" />
166 </link>
167 </xsl:template>
168 >>>
169
170 %%%%%%%%%%%%%%%%%%
171 \section{tabular hor lines}
172 %%%%%%%%%%%%%%%%%%
173
174 %%%%%%%%%%%%%
175 \subsection{Outline}
176 %%%%%%%%%%%%%
177
178
179 \<tabular hor lines\><<<
180 <script element="tbody" >
181 <set name="dirt" >
182 `<open xslt script`>
183 `<tbody dirt templates`>
184 `<close xslt script`>
185 </set>
186 <set name="tbody" >
187 `<open xslt script`>
188 `<tbody templates`>
189 `<close xslt script`>
190 </set>
191 <xslt name="." xml="." xsl="tbody" />
192 <xslt name="." xml="." xsl="dirt" />
193 <dom name="." xml="." method="cline" class="tex4ht.DbUtilities" />
194 </script>
195 >>>
196
197
198
199
200
201
202 \<static void cline(dom)\><<<
203 public static void cline(Node dom) {
204 Node row, entry, para, nextrow;
205 Node node = dom.getFirstChild();
206 if( node != null ){
207 `<remove empty trailing rows`>
208 `<merge cline rows into non-line rows`>
209 }
210 }
211 >>>
212
213
214 \<remove empty trailing rows\><<<
215 row = node.getLastChild();
216 while( (row != null)
217 && ( (entry = row.getLastChild()) != null)
218 && ( (para = entry.getFirstChild()) != null)
219 && ( para.getNextSibling() == null)
220 && ( para.getFirstChild() == null)
221 ){
222 node.removeChild(row);
223 row = node.getLastChild();
224 }
225 >>>
226
227 The merging of rows deal with cases similar to the following one.
228
229
230 \begin{verbatim}
231 <row>
232 <entry align="left">
233 <para> 1</para>
234 </entry>
235 <entry align="left" nameend="3" namest="2">
236 <para>2 to 3</para>
237 </entry>
238 </row>
239 <row role="cline">
240 <entry rowsep="0"/>
241 <entry rowsep="1"/>
242 <entry rowsep="1"/>
243 </row>
244 \end{verbatim}
245
246 \<merge cline rows into non-line rows\><<<
247 row = node.getFirstChild();
248 while( row != null ){
249 if( (row.getNodeType() == Node.ELEMENT_NODE)
250 && ((Element) row).getAttribute("rowsep").equals("")
251 && !((Element) row).getAttribute("role" ).equals("cline")
252 && ((nextrow = row.getNextSibling()) != null)
253 && (nextrow.getNodeType() == Node.ELEMENT_NODE)
254 && ((Element) nextrow).getAttribute("role" ).equals("cline")
255 ){
256 `<boolean compatible = ...`>
257 if( compatible ){
258 `<row += nextrow`>
259 node.removeChild(nextrow);
260 }
261 }
262 row = row.getNextSibling();
263 }
264 >>>
265
266 \<boolean compatible = ...\><<<
267 boolean compatible = true;
268 Node entry1 = row.getFirstChild();
269 Node entry2 = nextrow.getFirstChild();
270 while( true ){
271 if( (entry1 == null) || (entry2 == null) ){ break; }
272 int range;
273 try{
274 range =
275 Integer.parseInt( ((Element) entry1).getAttribute("nameend") )
276 -
277 Integer.parseInt( ((Element) entry1).getAttribute("namest") )
278 +
279 1;
280 } catch( Exception e){ range = 1;}
281 if( range > 1 ){
282 String rowsep = ((Element) entry2).getAttribute("rowsep");
283 while( --range > 0 ){
284 entry2 = entry2.getNextSibling();
285 if( entry2 == null ){
286 compatible = false;
287 break;
288 }
289 String value = ((Element) entry2).getAttribute("rowsep");
290 if( !value.equals( rowsep ) ){
291 compatible = false;
292 break;
293 }
294 }
295 }
296 if( !compatible ){ break; }
297 entry1 = entry1.getNextSibling();
298 entry2 = entry2.getNextSibling();
299 }
300 >>>
301
302 \<row += nextrow\><<<
303 entry1 = row.getFirstChild();
304 entry2 = nextrow.getFirstChild();
305 while( true ){
306 if( (entry1 == null) || (entry2 == null) ){ break; }
307 int range;
308 try{
309 range =
310 Integer.parseInt( ((Element) entry1).getAttribute("nameend") )
311 -
312 Integer.parseInt( ((Element) entry1).getAttribute("namest") )
313 +
314 1;
315 } catch( Exception e){ range = 1;}
316 ((Element) entry1).setAttribute(
317 "rowsep",
318 ((Element) entry2).getAttribute("rowsep") );
319 while( --range > 0 ){
320 entry2 = entry2.getNextSibling();
321 }
322 entry1 = entry1.getNextSibling();
323 entry2 = entry2.getNextSibling();
324 }
325 >>>
326
327
328
329 %%%%%%%%%%%%%
330 \subsection{Dirt Lines}
331 %%%%%%%%%%%%%
332
333 Can they be removed earlier at the latex pass?
334
335
336 \<tbody dirt templates\><<<
337 <xsl:template match=" row[
338 (count(child::entry) = 1)
339 and
340 ( normalize-space(child::entry[1]/child::para[1]/child::comment())
341 = 'dirt'
342 )
343 ]">
344 </xsl:template>
345 >>>
346
347
348
349
350
351 %%%%%%%%%%%%%
352 \subsection{hline}
353 %%%%%%%%%%%%%
354
355
356
357 \<tbody templates\><<<
358 <xsl:template match=" row[ @role = 'hline' ]" />
359 >>>
360
361 \<tbody templates\><<<
362 <xsl:template match=" row[ @role = 'hline' ]" />
363 <xsl:template match=" row[
364 following-sibling::*[1][ self::row[@role = 'hline'] ]
365 ] ">
366 <xsl:copy>
367 <xsl:attribute name="rowsep">
368 <xsl:text>1</xsl:text>
369 </xsl:attribute>
370 <xsl:apply-templates select="*|@*|text()|comment()" />
371 </xsl:copy>
372 </xsl:template>
373 >>>
374
375 %%%%%%%%%%%%%
376 \subsection{cline}
377 %%%%%%%%%%%%%
378
379
380
381
382 \<tbody templates\><<<
383 <xsl:template match=" row[
384 (@role = 'cline')
385 and
386 preceding-sibling::*[1]
387 [ self::row[ not(@role) ] ]
388 and
389 ( count(child::entry)
390 = count(preceding-sibling::*[1]/child::entry))
391 ]" />
392 <xsl:template match=" row[
393 not(@role)
394 and
395 following-sibling::*[1][ self::row[@role = 'cline'] ]
396 and
397 ( count(child::entry)
398 = count(following-sibling::*[1]/child::entry))
399 ] ">
400 <xsl:copy>
401 <xsl:apply-templates select="@*" />
402 <xsl:apply-templates select="*|text()|comment()" mode="cline" />
403 </xsl:copy>
404 </xsl:template>
405 >>>
406
407 \<tbody templates\><<<
408 <xsl:template match=" text()|comment() " mode="cline">
409 <xsl:copy>
410 <xsl:apply-templates select="*|@*|text()|comment()" />
411 </xsl:copy>
412 </xsl:template>
413 >>>
414
415
416
417
418 \<tbody templates\><<<
419 <xsl:template match="*" mode="cline">
420 <xsl:copy>
421 <xsl:if test="self::entry">
422 <xsl:attribute name="rowsep">
423 <xsl:variable name="pos">
424 <xsl:value-of select="position()" />
425 </xsl:variable>
426 <xsl:value-of select="parent::row
427 / following-sibling::*[1]
428 / child::entry[position()=$pos]
429 / @rowsep
430 " />
431 </xsl:attribute>
432 </xsl:if>
433 <xsl:apply-templates select="*|@*|text()|comment()" />
434 </xsl:copy>
435 </xsl:template>
436 >>>
437
438
439
440
441
442
443
444
445
446 %%%%%%%%%%%%%%%%%%
447 \section{Shared}
448 %%%%%%%%%%%%%%%%%%
449
450
451
452 \<open xslt script\><<<
453 <![CDATA[
454 <xsl:stylesheet version="1.0"
455 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
456 xmlns:db="http://docbook.org/ns/docbook"
457 >
458 <xsl:output omit-xml-declaration = "yes" />
459 >>>
460
461 \<close xslt script\><<<
462 <xsl:template match="*|@*|text()|comment()" >
463 <xsl:copy>
464 <xsl:apply-templates select="*|@*|text()|comment()" />
465 </xsl:copy>
466 </xsl:template>
467 </xsl:stylesheet>
468 ]]>
469 >>>
470
471
472 \<get content template\><<<
473 <xsl:template match="*" mode="content" >
474 <xsl:choose>
475 <xsl:when test=" @class = 'char' " >
476 <xsl:text>x</xsl:text>
477 </xsl:when>
478 <xsl:when test=" not(
479 (@title = 'speech-extra') or (@class = 'accent-char')
480 ) " >
481 <xsl:apply-templates select="*|text()" mode="content" />
482 </xsl:when>
483 </xsl:choose>
484 </xsl:template>
485 >>>
486
487
488
489
490
491 %%%%%%%%%%%%%%%%%%
492 \section{Copyright}
493 %%%%%%%%%%%%%%%%%%
494
495 \let\newfilename=\relax
496
497 \<copy right\><<<
498 /**********************************************************/ >>>
499
500
501
502 \<cont copy right\><<<
503 /* */
504 /* This work may be distributed and/or modified under the */
505 /* conditions of the LaTeX Project Public License, either */
506 /* version 1.3 of this license or (at your option) any */
507 /* later version. The latest version of this license is */
508 /* in */
509 /* http://www.latex-project.org/lppl.txt */
510 /* and version 1.3 or later is part of all distributions */
511 /* of LaTeX version 2003/12/01 or later. */
512 /* */
513 /* This work has the LPPL maintenance status "maintained".*/
514 /* */
515 /* The Current Maintainer of this work */
516 /* is the TeX4ht Project <http://tug.org/tex4ht>. */
517 >>>
518
519 \ifdojava
520 \AtEndDocument{\Needs{%
521 "pushd \XTPIPES || exit 1
522 ;
523 jar cf tex4ht.jar *
524 ;
525 popd
526 ;
527 mv \XTPIPES tex4ht.jar \TEXMFTEXivBIN
528 ;
529 cp \XTPIPES xtpipes/lib/*
530 \TEXMFTEXivXTPIPES
531 "}}
532 \fi
533
534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
535 \end{document}
536 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
537