File: xref.xsl

package info (click to toggle)
appstream 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,448 kB
  • sloc: ansic: 51,878; xml: 10,459; cpp: 4,721; python: 538; sh: 264; makefile: 24
file content (256 lines) | stat: -rw-r--r-- 9,970 bytes parent folder | download | duplicates (5)
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
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Purpose:
    Collect common linking templates, independant of any target format

  Author(s):  Stefan Knorr <sknorr@suse.de>
              Thomas Schraitle <toms@opensuse.org>

  Copyright:  2015 Thomas Schraitle

-->

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  exclude-result-prefixes="xlink fo">


<xsl:template match="*" mode="intra.title.markup">
  <xsl:param name="linkend"/>
  <xsl:param name="first" select="0"/>
  <xsl:message>WARNING: Element <xsl:value-of select="local-name(.)"/> cannot be used for intra xref linking.
  - affected ID: <xsl:value-of select="(./@id|./@xml:id)[last()]"/>
  - linkend: <xsl:value-of select="$linkend"/></xsl:message>
</xsl:template>


<xsl:template name="generate.intra.separator">
 <xsl:param name="lang"/>
  <xsl:variable name="comma">
   <xsl:call-template name="gentext.template">
    <xsl:with-param name="context" select="'xref'"/>
    <xsl:with-param name="name"  select="'intra-separator'"/>
    <xsl:with-param name="lang" select="$lang"/>
   </xsl:call-template>
  </xsl:variable>

  <xsl:choose>
   <xsl:when test="$comma != ''"><xsl:value-of select="$comma"/></xsl:when>
   <xsl:otherwise><xsl:text>, </xsl:text></xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="create.linkto.other.book">
  <xsl:param name="target"/>
  <!-- It seems we can't get any useful value here anyway, so lets trust the
       caller to get it right... -->
  <xsl:param name="lang" select="'en'"/>
  <!-- Make sure that we transform zh-TW to zh_tw etc. -->
  <xsl:param name="lang-normalized" select="translate($lang, '-ABCDEFGHIJKLMNOPQRSTUVWXYZ', '_abcdefghijklmnopqrstuvwxyz')"/>
  <xsl:variable name="refelem" select="local-name($target)"/>
  <xsl:variable name="target.article" select="$target/ancestor-or-self::article"/>
  <xsl:variable name="target.book" select="$target/ancestor-or-self::book"/>
  <xsl:variable name="text">
    <xsl:apply-templates select="$target" mode="intra.title.markup">
      <xsl:with-param name="linkend" select="@linkend"/>
      <xsl:with-param name="lang" select="$lang-normalized"/>
    </xsl:apply-templates>
  </xsl:variable>
  <xsl:copy-of select="$text"/>
</xsl:template>

 <xsl:template match="section" mode="intra.title.markup">
    <xsl:param name="linkend"/>
    <xsl:param name="first" select="0"/>
    <xsl:param name="lang" select="'en'"/>
    <xsl:variable name="level" select="count(ancestor-or-self::section)"/>

   <!--<xsl:message>######## section <xsl:value-of select="$linkend"/></xsl:message>-->
   <xsl:apply-templates select="parent::*" mode="intra.title.markup">
      <xsl:with-param name="lang" select="$lang"/>
   </xsl:apply-templates>
   <xsl:call-template name="generate.intra.separator">
     <xsl:with-param name="lang" select="$lang"/>
   </xsl:call-template>
   <xsl:call-template name="substitute-markup">
      <xsl:with-param name="template">
        <xsl:call-template name="gentext.template">
          <xsl:with-param name="context" select="'xref'"/>
          <xsl:with-param name="name"  select="concat('intra-', local-name())"/>
          <xsl:with-param name="lang" select="$lang"/>
        </xsl:call-template>
      </xsl:with-param>
   </xsl:call-template>
 </xsl:template>

  <xsl:template match="sect1" mode="intra.title.markup">
    <xsl:param name="linkend"/>
    <xsl:param name="first" select="0"/>
    <xsl:param name="lang" select="'en'"/>
    <xsl:apply-templates select="parent::*" mode="intra.title.markup">
      <xsl:with-param name="lang" select="$lang"/>
    </xsl:apply-templates>
    <xsl:call-template name="generate.intra.separator">
     <xsl:with-param name="lang" select="$lang"/>
    </xsl:call-template>
    <xsl:call-template name="substitute-markup">
      <xsl:with-param name="template">
        <xsl:call-template name="gentext.template">
          <xsl:with-param name="context" select="'xref'"/>
          <xsl:with-param name="name"  select="concat('intra-', local-name())"/>
          <xsl:with-param name="lang" select="$lang"/>
        </xsl:call-template>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>


  <xsl:template match="sect2|sect3|sect4|sect5" mode="intra.title.markup">
    <xsl:param name="linkend"/>
    <xsl:param name="first" select="0"/>
    <xsl:param name="lang" select="'en'"/>
    <xsl:apply-templates
      select="ancestor::appendix|ancestor::article|
      ancestor::chapter|ancestor::glossary|ancestor::preface"
      mode="intra.title.markup">
      <xsl:with-param name="lang" select="$lang"/>
    </xsl:apply-templates>
    <xsl:call-template name="generate.intra.separator">
     <xsl:with-param name="lang" select="$lang"/>
    </xsl:call-template>
    <xsl:call-template name="substitute-markup">
      <xsl:with-param name="template">
        <xsl:call-template name="gentext.template">
          <xsl:with-param name="context" select="'xref'"/>
          <xsl:with-param name="name"  select="concat('intra-', local-name())"/>
          <xsl:with-param name="lang" select="$lang"/>
        </xsl:call-template>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>


  <xsl:template match="appendix|chapter" mode="intra.title.markup">
    <xsl:param name="linkend"/>
    <xsl:param name="first" select="0"/>
    <xsl:param name="lang" select="'en'"/>
    <!-- We don't want parts -->
    <xsl:apply-templates select="ancestor::book" mode="intra.title.markup">
      <xsl:with-param name="lang" select="$lang"/>
    </xsl:apply-templates>
    <xsl:call-template name="generate.intra.separator">
     <xsl:with-param name="lang" select="$lang"/>
    </xsl:call-template>
    <xsl:call-template name="substitute-markup">
      <xsl:with-param name="template">
        <xsl:call-template name="gentext.template">
          <xsl:with-param name="context" select="'xref'"/>
          <xsl:with-param name="name"  select="concat('intra-', local-name())"/>
          <xsl:with-param name="lang" select="$lang"/>
        </xsl:call-template>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>


  <xsl:template match="preface" mode="intra.title.markup">
    <xsl:param name="linkend"/>
    <xsl:param name="first" select="0"/>
    <xsl:param name="lang" select="'en'"/>
    <xsl:apply-templates select="parent::*" mode="intra.title.markup">
      <xsl:with-param name="lang" select="$lang"/>
    </xsl:apply-templates>

    <xsl:call-template name="generate.intra.separator">
     <xsl:with-param name="lang" select="$lang"/>
    </xsl:call-template>
    <xsl:call-template name="substitute-markup">
      <xsl:with-param name="template">
        <xsl:call-template name="gentext.template">
          <xsl:with-param name="context" select="'xref'"/>
          <xsl:with-param name="name"  select="concat('intra-', local-name())"/>
          <xsl:with-param name="lang" select="$lang"/>
        </xsl:call-template>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>


  <xsl:template match="part" mode="intra.title.markup">
    <xsl:param name="linkend"/>
    <xsl:param name="first" select="0"/>
    <xsl:param name="lang" select="'en'"/>
    <!-- We don't want parts, so skip them -->
    <xsl:apply-templates select="parent::*" mode="intra.title.markup">
      <xsl:with-param name="lang" select="$lang"/>
    </xsl:apply-templates>
  </xsl:template>


  <xsl:template match="article|book" mode="intra.title.markup">
    <xsl:param name="linkend"/>
    <xsl:param name="first" select="0"/>
    <xsl:param name="lang" select="'en'"/>
    <xsl:call-template name="substitute-markup">
      <xsl:with-param name="template">
        <xsl:call-template name="gentext.template">
          <xsl:with-param name="context" select="'xref'"/>
          <xsl:with-param name="name"  select="concat('intra-', local-name())"/>
          <xsl:with-param name="lang" select="$lang"/>
        </xsl:call-template>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>


  <xsl:template
   match="variablelist|orderedlist|itemizedlist|procedure|table|figure|equation|
          caution|warning|important|note|tip"
   mode="intra.title.markup">
    <xsl:param name="linkend"/>
    <xsl:param name="first" select="0"/>
    <xsl:param name="lang" select="'en'"/>

    <xsl:apply-templates select="parent::*" mode="intra.title.markup">
      <xsl:with-param name="lang" select="$lang"/>
    </xsl:apply-templates>
    <xsl:choose>
      <xsl:when test="title">
        <xsl:call-template name="generate.intra.separator">
         <xsl:with-param name="lang" select="$lang"/>
        </xsl:call-template>
        <xsl:apply-templates select="." mode="title.markup">
          <xsl:with-param name="lang" select="$lang"/>
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message>WARNING: Element <xsl:value-of select="local-name(.)"/> without title used for intra xref linking.</xsl:message>
        <xsl:message>- affected ID: <xsl:value-of select="(./@id|./@xml:id)[last()]"/></xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="step" mode="intra.title.markup">
    <xsl:param name="linkend"/>
    <xsl:param name="first" select="0"/>
    <xsl:param name="lang" select="'en'"/>

    <xsl:apply-templates select="." mode="xref-to"/>
  </xsl:template>

  <xsl:template match="varlistentry" mode="intra.title.markup">
    <xsl:param name="linkend"/>
    <xsl:param name="first" select="0"/>
    <xsl:param name="lang" select="'en'"/>

    <xsl:apply-templates select="ancestor::appendix|ancestor::article|
      ancestor::chapter|ancestor::glossary|ancestor::preface"
      mode="intra.title.markup">
      <xsl:with-param name="lang" select="$lang"/>
    </xsl:apply-templates>
    <xsl:value-of select="concat(' ', term[1])"/>
  </xsl:template>

</xsl:stylesheet>