verbatim.xsl coverage = 160/468 (34.19%)

  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
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>

<!--############################################################################
    XSLT Stylesheet DocBook -> LaTeX 
    ############################################################################ -->

<!-- Literal parameters -->
<xsl:param name="literal.width.ignore">0</xsl:param>
<xsl:param name="literal.layout.options"/>
<xsl:param name="literal.lines.showall">1</xsl:param>
<xsl:param name="literal.role"/>
<xsl:param name="literal.class">monospaced</xsl:param>
<xsl:param name="literal.extensions"/>
<xsl:param name="linenumbering.scope"/>
<xsl:param name="linenumbering.default"/>
<xsl:param name="linenumbering.everyNth"/>
<!-- Use scalable dblatex listing if the feature is required -->
<xsl:param name="literal.environment">
  <xsl:choose>
  <xsl:when test="contains($literal.extensions,'scale')">
    <xsl:text>lstcode</xsl:text>
  </xsl:when>
  <xsl:otherwise>
    <xsl:text>lstlisting</xsl:text>
  </xsl:otherwise>
  </xsl:choose>
</xsl:param>


<xsl:template name="verbatim.setup">
  <!-- dblatex requires that a listing environment starts with 'lst' -->
  <xsl:if test="substring($literal.environment,1,3) != 'lst'">
    <xsl:message terminate="yes">
      <xsl:text>Error: </xsl:text>
      <xsl:value-of select="$literal.environment"/>
      <xsl:text>: a listing environment must start with 'lst'</xsl:text>
    </xsl:message>
  </xsl:if>
  <xsl:apply-templates select="//screen|//programlisting"
                       mode="save.verbatim.preamble"/>
</xsl:template>

<xsl:template name="verbatim.setup2">
  <xsl:text>\lstsetup&#10;</xsl:text>
</xsl:template>


<xsl:template match="address">
  <xsl:call-template name="output.verbatim"/>
</xsl:template>

<xsl:template match="text()" mode="save.verbatim"/>

<xsl:template match="address"
              mode="save.verbatim">
  <xsl:call-template name="save.verbatim"/>
</xsl:template>

<xsl:template name="save.verbatim">
  <xsl:param name="content">
    <xsl:apply-templates mode="latex.verbatim"/>
  </xsl:param>
  <xsl:text>&#10;\begin{SaveVerbatim}{</xsl:text>
  <xsl:value-of select="generate-id()"/>
  <xsl:text>}&#10;</xsl:text>
  <xsl:value-of select="$content"/>
  <xsl:text>&#10;\end{SaveVerbatim}&#10;</xsl:text>
</xsl:template>

<xsl:template name="output.verbatim">
  <xsl:param name="content">
    <xsl:apply-templates mode="latex.verbatim"/>
  </xsl:param>
  <!-- In tables just use the data previously saved -->
  <xsl:choose>
  <xsl:when test="ancestor::entry|
                  ancestor::legalnotice">
    <xsl:text>\UseVerbatim{</xsl:text>
    <xsl:value-of select="generate-id(.)"/>
    <xsl:text>}</xsl:text>
  </xsl:when>
  <xsl:otherwise>
    <xsl:text>&#10;\begin{verbatim}</xsl:text>
    <xsl:value-of select="$content"/>
    <xsl:text>\end{verbatim}&#10;</xsl:text>
  </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- Special cases where nothing to output in verbatim mode -->
<xsl:template match="alt" mode="latex.verbatim"/>

<!-- Returns the filename from @fileref or @entityref attribute -->
<xsl:template match="*" mode="filename.get">
  <xsl:choose>
  <xsl:when test="@entityref">
    <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="@fileref"/>
  </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- ==================================================================== -->

<!-- Template that must be called by elements that want to be escaped in a
     programlisting environment. It escapes the tex sequence, *but* prints
     out the sequence only if probing is not required (i.e. = 0).
     
     Probing is used by a parent that wants to know if it contains some
     element that needs some tex escaping.
     -->

<xsl:template name="verbatim.embed">
  <xsl:param name="co-tagin" select="'&lt;'"/>
  <xsl:param name="rnode" select="/"/>
  <xsl:param name="probe" select="0"/>
  <xsl:param name="content"/>

  <xsl:value-of select="concat($co-tagin, 't&gt;')"/>
  <xsl:if test="$probe = 0">
    <xsl:choose>
      <xsl:when test="$content != ''">
        <xsl:value-of select="$content"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="."/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:if>
  <xsl:value-of select="'&lt;/t&gt;'"/>
</xsl:template>

<!-- Template to format (bold, italic) the calling element. The format is
     specified by the <style> that drives the corresponding delimiter
     sequence. Styles can be nested, so apply the same template mode to
     children.
     -->

<xsl:template name="verbatim.format">
  <xsl:param name="co-tagin" select="'&lt;'"/>
  <xsl:param name="rnode" select="/"/>
  <xsl:param name="probe" select="0"/>
  <xsl:param name="style" select="'b'"/>
  <xsl:param name="content"/>

  <xsl:value-of select="concat($co-tagin, $style, '&gt;')"/>
  <xsl:if test="$probe = 0">
    <xsl:choose>
      <xsl:when test="$content != ''">
        <xsl:value-of select="$content"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates mode="latex.programlisting">
          <xsl:with-param name="co-tagin" select="$co-tagin"/>
          <xsl:with-param name="rnode" select="$rnode"/>
          <xsl:with-param name="probe" select="$probe"/>
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:if>
  <xsl:value-of select="concat('&lt;/', $style, '&gt;')"/>
</xsl:template>

<!-- A latex Processing-Instruction in verbatim is meaningfull, so
     process it.
     -->

<xsl:template match="processing-instruction('latex')"
              mode="latex.programlisting">
  <xsl:param name="co-tagin" select="'&lt;'"/>
  <xsl:param name="rnode" select="/"/>
  <xsl:param name="probe" select="0"/>

  <xsl:value-of select="concat($co-tagin, 't', '&gt;')"/>
  <xsl:value-of select="."/>
  <xsl:value-of select="concat('&lt;/', 't', '&gt;')"/>
</xsl:template>

<!-- ==================================================================== -->

<!-- By default an element in a programlisting environment just prints out its
     text() adapted to this environment, and apply to its children the same
     template. -->

<xsl:template match="*" mode="latex.programlisting">
  <xsl:param name="co-tagin" select="'&lt;'"/>
  <xsl:param name="rnode" select="/"/>
  <xsl:param name="probe" select="0"/>

  <xsl:if test="$output.quietly = 0">
    <xsl:message>
      <xsl:value-of select="local-name(.)"/>
      <xsl:text>: default template used in programlisting or screen</xsl:text>
    </xsl:message>
  </xsl:if>

  <xsl:apply-templates mode="latex.programlisting">
    <xsl:with-param name="co-tagin" select="$co-tagin"/>
    <xsl:with-param name="rnode" select="$rnode"/>
    <xsl:with-param name="probe" select="$probe"/>
  </xsl:apply-templates>
</xsl:template>


<!-- ==================================================================== -->

<!-- The following templates now works only with the listings package -->

<!-- The listing content is internal to the element, and is not a reference
     to an external file -->

<xsl:template match="programlisting|screen|literallayout" mode="internal">
  <xsl:param name="opt"/>
  <xsl:param name="co-tagin"/>
  <xsl:param name="rnode" select="/"/>
  <xsl:param name="env" select="'lstlisting'"/>


  <xsl:text>&#10;\begin{</xsl:text>
  <xsl:value-of select="$env"/>
  <xsl:text>}</xsl:text>
  <xsl:if test="$opt!=''">
    <xsl:text>[</xsl:text>
    <xsl:value-of select="$opt"/>
    <xsl:text>]</xsl:text>
  </xsl:if>
  <!-- some text just after the open tag must be put on a new line -->
  <xsl:if test="not(contains(.,'&#10;')) or
                string-length(normalize-space(
                  substring-before(.,'&#10;')))&gt;0">
    <xsl:text>&#10;</xsl:text>
  </xsl:if>
  <xsl:apply-templates mode="latex.programlisting">
    <xsl:with-param name="co-tagin" select="$co-tagin"/>
    <xsl:with-param name="rnode" select="$rnode"/>
  </xsl:apply-templates>
  <!-- ensure to have the end on a separate line -->
  <xsl:if test="substring(.,string-length(.))!='&#10;' and
                substring(translate(.,' &#09;',''),
                  string-length(translate(.,' &#09;','')))!='&#10;'">
    <xsl:text>&#10;</xsl:text>
  </xsl:if>
  <xsl:text>\end{</xsl:text>
  <xsl:value-of select="$env"/>
  <xsl:text>}&#10;</xsl:text>
</xsl:template>

<!-- ==================================================================== -->

<xsl:template name="linenumbering">
  <xsl:choose>
    <xsl:when test="@linenumbering='numbered'">1</xsl:when>
    <xsl:when test="@linenumbering and @linenumbering!='numbered'">0</xsl:when>
    <xsl:when test="$linenumbering.default='numbered' and 
                   (contains(concat(' ',$linenumbering.scope,' '),
                             concat(' ',local-name(.),' ')))">1</xsl:when>
    <xsl:otherwise>0</xsl:otherwise>
  </xsl:choose>
</xsl:template>
 
<xsl:template match="programlisting|screen|literallayout">
  <xsl:param name="rnode" select="/"/>

  <!-- formula to compute the listing width -->
  <xsl:variable name="width">
    <xsl:if test="$literal.width.ignore='0' and
                  @width and string(number(@width))!='NaN'">
      <xsl:text>\setlength{\lstwidth}{</xsl:text>
      <xsl:value-of select="@width"/>
      <xsl:text>\lstcharwidth+2\lstframesep}</xsl:text>
    </xsl:if>
  </xsl:variable>

  <!-- is there some elements needing escaping? -->
  <xsl:variable name="escaped">
    <xsl:apply-templates mode="latex.programlisting">
      <xsl:with-param name="probe" select="1"/>
    </xsl:apply-templates>
  </xsl:variable>

  <!-- get the listing escape sequence if needed -->
  <xsl:variable name="co-tagin">
    <xsl:if test="descendant::co or $escaped != ''">
      <xsl:call-template name="co-tagin-gen"/>
    </xsl:if>
  </xsl:variable>

  <xsl:variable name="linenumbered">
    <xsl:call-template name="linenumbering"/>
  </xsl:variable>

  <xsl:variable name="role">
    <xsl:choose>
    <xsl:when test="@role">
      <xsl:value-of select="@role"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$literal.role"/>
    </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="opt">
    <!-- skip empty endlines -->
    <xsl:if test="$literal.lines.showall='0'">
      <xsl:text>showlines=false,</xsl:text>
    </xsl:if>
    <!-- Remove wrap mode if required -->
    <xsl:if test="$role='overflow'">
      <xsl:text>breaklines=false,</xsl:text>
    </xsl:if>
    <!-- The scaling feature is not available with standard listings -->
    <xsl:if test="contains($literal.extensions, 'scale')">
      <xsl:choose>
      <xsl:when test="$role='scale' or 
          ($role='' and $literal.extensions='scale.by.width' and $width!='')">
        <xsl:text>scale=true,</xsl:text>
        <!-- don't wrap to scale to the longest line if no width specified -->
        <xsl:if test="$width=''">
          <xsl:text>breaklines=false,</xsl:text>
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>scale=false,</xsl:text>
      </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
    <!-- language option is only for programlisting -->
    <xsl:if test="@language">
      <xsl:text>language={</xsl:text>
      <xsl:value-of select="@language"/>
      <xsl:text>},</xsl:text>
    </xsl:if>
    <!-- listing width -->
    <xsl:if test="$width!=''">
      <xsl:text>linewidth=\lstwidth,</xsl:text>
    </xsl:if>
    <!-- print line numbers -->
    <xsl:if test="$linenumbered=1">
      <xsl:text>numbers=left,</xsl:text>
      <xsl:if test="number($linenumbering.everyNth) &gt; 1">
        <xsl:text>stepnumber=</xsl:text>
        <xsl:value-of select="number($linenumbering.everyNth)"/>
        <xsl:text>,</xsl:text>
      </xsl:if>
    </xsl:if>
    <!-- find the fist line number to print -->
    <xsl:choose>
    <xsl:when test="@startinglinenumber">
      <xsl:text>firstnumber=</xsl:text>
      <xsl:value-of select="@startinglinenumber"/>
      <xsl:text>,</xsl:text>
    </xsl:when>
    <xsl:when test="@continuation and (@continuation='continues')">
      <!-- ask for continuation -->
      <xsl:text>firstnumber=last</xsl:text>
      <xsl:text>,</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <!-- explicit restart numbering -->
      <xsl:text>firstnumber=1</xsl:text>
      <xsl:text>,</xsl:text>
    </xsl:otherwise>
    </xsl:choose>
    <!-- In literallayout no specific background, nor monospaced font -->
    <xsl:if test="self::literallayout">
      <xsl:text>backgroundcolor={},</xsl:text>
      <xsl:choose>
      <xsl:when test="@class='monospaced' or
                      $literal.class='monospaced'">
        <xsl:text>basicstyle=\ttfamily,</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>basicstyle=\normalfont,flexiblecolumns,</xsl:text>
      </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
    <!-- TeX/verb delimiters if tex or formatting is embedded (like <co>s) -->
    <xsl:if test="$co-tagin!=''">
      <xsl:call-template name="listing-delim">
        <xsl:with-param name="tagin" select="$co-tagin"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:variable>

  <!-- put the listing with formula here -->
  <xsl:if test="$width!=''">
    <xsl:text>&#10;</xsl:text>
    <xsl:value-of select="$width"/>
  </xsl:if>
  <xsl:choose>
  <xsl:when test="descendant::imagedata[@format='linespecific']|
                  descendant::inlinegraphic[@format='linespecific']|
                  descendant::textdata">
    <!-- the listing content is in an external file -->
    <xsl:text>&#10;\lstinputlisting</xsl:text>
    <xsl:if test="$opt!=''">
      <xsl:text>[</xsl:text>
      <xsl:value-of select="$opt"/>
      <xsl:text>]</xsl:text>
    </xsl:if>
    <xsl:text>{</xsl:text>
    <xsl:apply-templates
        select="descendant::imagedata|descendant::inlinegraphic|
                descendant::textdata"
        mode="filename.get"/>
    <xsl:text>}&#10;</xsl:text>
  </xsl:when>
  <xsl:otherwise>
    <!-- the listing content is internal -->
    <xsl:apply-templates select="." mode="internal">
      <xsl:with-param name="rnode" select="$rnode"/>
      <xsl:with-param name="co-tagin" select="$co-tagin"/>
      <xsl:with-param name="opt" select="$opt"/>
      <xsl:with-param name="env" select="$literal.environment"/>
    </xsl:apply-templates>
  </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- ==================================================================== -->

<!-- Defines the style delimiters to use, and the tex sequence delimiters -->

<xsl:template name="listing-delim">
  <xsl:param name="tagin" select="'&lt;'"/>
  <xsl:variable name="tex" select="concat($tagin, 't&gt;')"/>
  <xsl:variable name="bf" select="concat($tagin, 'b&gt;')"/>
  <xsl:variable name="it" select="concat($tagin, 'i&gt;')"/>

  <xsl:text>escapeinside={</xsl:text>
  <xsl:value-of select="$tex"/>
  <xsl:text>}{&lt;/t&gt;}</xsl:text>
  <xsl:text>,</xsl:text>
  <xsl:text>moredelim={**[is][\bfseries]{</xsl:text>
  <xsl:value-of select="$bf"/>
  <xsl:text>}{&lt;/b&gt;}},</xsl:text>
  <xsl:text>moredelim={**[is][\itshape]{</xsl:text>
  <xsl:value-of select="$it"/>
  <xsl:text>}{&lt;/i&gt;}},</xsl:text>
</xsl:template>

<!-- ==================================================================== -->

<!-- Global listing saving, for listings in footnotes, since we never know
     in which context the footnotes are used. A check is done to not cover
     the other saving points in tables. -->

<xsl:template match="programlisting|screen|literallayout"
              mode="save.verbatim.preamble">
  <xsl:if test="not(ancestor::table or ancestor::informaltable) and
                ancestor::footnote">
    <xsl:apply-templates select="." mode="save.verbatim"/>
  </xsl:if>
</xsl:template>


<!-- Listings does not work in tables, even for external files. So, we
     use the fancyvrb verbatim coupled to listings for the rendering stuff.
     This mode assumes that all the verbatim data is in an external
     file. Using the save/use commands would work except for linenumbering
     stuff. -->

<xsl:template match="programlisting|screen|literallayout"
              mode="save.verbatim">
  <xsl:if test="not(descendant::imagedata[@format='linespecific']|
                    descendant::inlinegraphic[@format='linespecific']|
                    descendant::textdata)">
    <xsl:variable name="str1" select="."/>
    <xsl:variable name="str">
      <xsl:apply-templates mode="latex.programlisting"/>
    </xsl:variable>

    <xsl:text>\begin{VerbatimOut}{tmplst-</xsl:text>
    <xsl:value-of select="generate-id()"/>
    <xsl:text>}</xsl:text>
    <!-- some text just after the open tag must be put on a new line -->
    <xsl:if test="not(contains($str1,'&#10;')) or
           string-length(
             normalize-space(substring-before($str1,'&#10;')))&gt;0">
      <xsl:text>&#10;</xsl:text>
    </xsl:if>
    <xsl:value-of select="$str"/>
    <!-- put a \n only if needed -->
    <xsl:if test="substring($str1,string-length($str1))!='&#10;' and
                  substring(translate($str1,' &#09;',''),
                    string-length(translate($str1,' &#09;','')))!='&#10;'">
      <xsl:text>&#10;</xsl:text>
    </xsl:if>
    <xsl:text>\end{VerbatimOut}&#10;</xsl:text>
  </xsl:if>
</xsl:template>


<!-- Special case for literal blocks in tables or foonotes -->
<xsl:template match="*[self::entry or
                       self::entrytbl or
                       self::footnote]//
                     *[self::programlisting or
                       self::screen or
                       self::literallayout]">

  <xsl:variable name="lsopt">
    <!-- language option is only for programlisting -->
    <xsl:if test="@language">
      <xsl:text>language=</xsl:text>
      <xsl:value-of select="@language"/>
      <xsl:text>,</xsl:text>
    </xsl:if>
  </xsl:variable>

  <xsl:variable name="linenumbered">
    <xsl:call-template name="linenumbering"/>
  </xsl:variable>

  <xsl:variable name="fvopt">
    <!-- print line numbers -->
    <xsl:if test="$linenumbered=1">
      <xsl:text>numbers=left,</xsl:text>
      <xsl:if test="number($linenumbering.everyNth) &gt; 1">
        <xsl:text>stepnumber=</xsl:text>
        <xsl:value-of select="number($linenumbering.everyNth)"/>
        <xsl:text>,</xsl:text>
      </xsl:if>
      <!-- find the fist line number to print -->
      <xsl:choose>
      <xsl:when test="@startinglinenumber">
        <xsl:text>firstnumber=</xsl:text>
        <xsl:value-of select="@startinglinenumber"/>
        <xsl:text>,</xsl:text>
      </xsl:when>
      <xsl:when test="@continuation and (@continuation='continues')">
        <!-- ask for continuation -->
        <xsl:text>firstnumber=last</xsl:text>
        <xsl:text>,</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <!-- explicit restart numbering -->
        <xsl:text>firstnumber=1</xsl:text>
        <xsl:text>,</xsl:text>
      </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
    <!-- In literallayout no specific background, nor monospaced font -->
    <xsl:if test="self::literallayout">
      <xsl:choose>
      <xsl:when test="@class='monospaced' or
                      $literal.class='monospaced'">
        <xsl:text>fontfamily=tt,</xsl:text>
      </xsl:when>
      <!-- FIXME: don't know how to force to use normal text font -->
      </xsl:choose>
    </xsl:if>
    
    <!-- TODO: TeX delimiters if <co>s are embedded. Use commandchars -->
  </xsl:variable>

  <xsl:text>\begin{fvlisting}</xsl:text>
  <xsl:if test="$lsopt!=''">
    <xsl:text>[</xsl:text>
    <xsl:value-of select="$lsopt"/>
    <xsl:text>]</xsl:text>
  </xsl:if>
  <xsl:text>&#10;</xsl:text>

  <xsl:text>\VerbatimInput</xsl:text>
  <xsl:if test="$fvopt!=''">
    <xsl:text>[</xsl:text>
    <xsl:value-of select="$fvopt"/>
    <xsl:text>]</xsl:text>
  </xsl:if>

  <xsl:text>{</xsl:text>
  <xsl:choose>
  <xsl:when test="descendant::imagedata[@format='linespecific']|
                  descendant::inlinegraphic[@format='linespecific']|
                  descendant::textdata">
    <!-- the listing content is in a (real) external file -->
    <xsl:apply-templates
        select="descendant::imagedata|descendant::inlinegraphic|
                descendant::textdata"
        mode="filename.abs.get"/>
  </xsl:when>
  <xsl:otherwise>
    <!-- the listing is outputed in a temporary file -->
    <xsl:text>tmplst-</xsl:text>
    <xsl:value-of select="generate-id(.)"/>
  </xsl:otherwise>
  </xsl:choose>
  <xsl:text>}&#10;</xsl:text>

  <xsl:text>\end{fvlisting}&#10;</xsl:text>

</xsl:template>

<!-- ==================================================================== -->

<xsl:template match="*" mode="filename.abs.get">
  <xsl:choose>
  <xsl:when test="@entityref">
    <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  </xsl:when>
  <xsl:when test="contains(@fileref, ':')">
    <!-- absolute uri scheme -->
    <xsl:value-of select="substring-after(@fileref, ':')"/>
  </xsl:when>
  <xsl:when test="starts-with(@fileref, '/')">
    <!-- absolute unix like path -->
    <xsl:value-of select="@fileref"/>
  </xsl:when>
  <xsl:otherwise>
    <!-- relative to the doc directory -->
    <xsl:value-of select="$current.dir"/>
    <xsl:text>/</xsl:text>
    <xsl:value-of select="@fileref"/>
  </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>