File: preprocess_xhtml.xsl

package info (click to toggle)
css2xslfo 1.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,836 kB
  • sloc: java: 18,393; xml: 214; makefile: 9
file content (126 lines) | stat: -rw-r--r-- 3,682 bytes parent folder | download | duplicates (3)
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
<?xml version='1.0'?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:xh="http://www.w3.org/1999/xhtml" version="1.0" exclude-result-prefixes="xh">

  <xsl:output method="xml" indent="no" version="1.0" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" omit-xml-declaration="no" />

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
  </xsl:template>



  <xsl:template match="xh:caption" mode="tot">
    <div class="tot-line">
      <xsl:call-template name="toc-link" />
    </div>
  </xsl:template>



  <xsl:template match="xh:div[@class = 'toc' and not(node())]">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
      <h1 />
      <div class="toc-main">
        <xsl:apply-templates select="//xh:div[@class = 'main']//xh:h1 |             //xh:div[@class = 'main']//xh:h2 |             //xh:div[@class = 'main']//xh:h3" mode="toc" />
      </div>
      <div class="toc-back">
        <xsl:apply-templates select="//xh:div[@class = 'back']//xh:h1 |             //xh:div[@class = 'back']//xh:h2 |             //xh:div[@class = 'back']//xh:h3" mode="toc" />
      </div>
    </xsl:copy>
  </xsl:template>



  <xsl:template match="xh:div[@class = 'tof' and not(node())]">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
      <h1 />
      <div class="tof-main">
        <xsl:apply-templates select="//xh:div[@class = 'main']//xh:div[@class = 'img-caption']" mode="tof" />
      </div>
      <div class="tof-back">
        <xsl:apply-templates select="//xh:div[@class = 'back']//xh:div[@class = 'img-caption']" mode="tof" />
      </div>
    </xsl:copy>
  </xsl:template>



  <xsl:template match="xh:div[@class = 'tot' and not(node())]">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
      <h1 />
      <div class="tot-main">
        <xsl:apply-templates select="//xh:div[@class = 'main']//xh:caption" mode="tot" />
      </div>
      <div class="tot-back">
        <xsl:apply-templates select="//xh:div[@class = 'back']//xh:caption" mode="tot" />
      </div>
    </xsl:copy>
  </xsl:template>



  <xsl:template match="xh:caption | xh:h1 | xh:h2 | xh:h3 | xh:div[@class = 'img-caption']">
    <xsl:copy>
      <xsl:attribute name="id">
        <xsl:value-of select="generate-id()" />
      </xsl:attribute>
      <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
  </xsl:template>



  <xsl:template match="xh:h1 | xh:h2 | xh:h3" mode="toc">
    <div class="{concat('toc-', name())}">
      <xsl:call-template name="toc-link" />
    </div>
  </xsl:template>



  <xsl:template match="xh:div[@class = 'img-caption']" mode="tof">
    <div class="tof-line">
      <xsl:call-template name="toc-link" />
    </div>
  </xsl:template>



  <xsl:template match="@id | @xml:id" mode="href">
    <xsl:attribute name="href">
      <xsl:text>#</xsl:text>
      <xsl:value-of select="." />
    </xsl:attribute>
  </xsl:template>



  <xsl:template match="@id | @xml:id" mode="class">
    <xsl:attribute name="class">
      <xsl:value-of select="." />
    </xsl:attribute>
  </xsl:template>



  <!-- Named templates. -->

  <xsl:template name="toc-link">
    <a href="{concat('#', generate-id())}">
      <xsl:apply-templates select="@id | @xml:id" mode="href" />
      <xsl:apply-templates select="node()" />
    </a>
    <span class="leader" />
    <span class="page-ref">
      <span class="{generate-id()}">
        <xsl:apply-templates select="@id | @xml:id" mode="class" />
      </span>
    </span>
  </xsl:template>

</xsl:transform>