source: BOOK/stylesheets/xhtml/lfs-xref.xsl@ 7a6a0d8

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 7a6a0d8 was 3f8be484, checked in by Jim Gifford <clfs@…>, 19 years ago

r627@server (orig r625): jim | 2005-10-31 12:59:34 -0800
Import of Cross-LFS Book

  • Property mode set to 100644
File size: 11.5 KB
RevLine 
[3f8be484]1<?xml version='1.0' encoding='ISO-8859-1'?>
2
3<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns="http://www.w3.org/1999/xhtml"
5 version="1.0">
6
7 <!-- Making a proper punctuation in xref (only for English language).-->
8 <xsl:template match="xref" name="xref">
9 <xsl:variable name="targets" select="key('id',@linkend)"/>
10 <xsl:variable name="target" select="$targets[1]"/>
11 <xsl:variable name="refelem" select="local-name($target)"/>
12 <xsl:variable name="role" select="@role"/>
13 <xsl:call-template name="check.id.unique">
14 <xsl:with-param name="linkend" select="@linkend"/>
15 </xsl:call-template>
16 <xsl:call-template name="anchor"/>
17 <xsl:choose>
18 <xsl:when test="count($target) = 0">
19 <xsl:message>
20 <xsl:text>XRef to nonexistent id: </xsl:text>
21 <xsl:value-of select="@linkend"/>
22 </xsl:message>
23 <xsl:text>???</xsl:text>
24 </xsl:when>
25 <xsl:when test="$target/@xreflabel">
26 <a>
27 <xsl:attribute name="href">
28 <xsl:call-template name="href.target">
29 <xsl:with-param name="object" select="$target"/>
30 </xsl:call-template>
31 </xsl:attribute>
32 <xsl:call-template name="xref.xreflabel">
33 <xsl:with-param name="target" select="$target"/>
34 </xsl:call-template>
35 </a>
36 </xsl:when>
37 <xsl:otherwise>
38 <xsl:variable name="href">
39 <xsl:call-template name="href.target">
40 <xsl:with-param name="object" select="$target"/>
41 </xsl:call-template>
42 </xsl:variable>
43 <xsl:apply-templates select="$target" mode="xref-to-prefix"/>
44 <a href="{$href}">
45 <xsl:if test="$target/title or $target/*/title">
46 <xsl:attribute name="title">
47 <xsl:apply-templates select="$target" mode="xref-title"/>
48 </xsl:attribute>
49 </xsl:if>
50 <xsl:apply-templates select="$target" mode="xref-to">
51 <xsl:with-param name="referrer" select="."/>
52 <xsl:with-param name="role" select="$role"/>
53 <xsl:with-param name="xrefstyle">
54 <xsl:value-of select="@xrefstyle"/>
55 </xsl:with-param>
56 </xsl:apply-templates>
57 </a>
58 <xsl:apply-templates select="$target" mode="xref-to-suffix"/>
59 </xsl:otherwise>
60 </xsl:choose>
61 </xsl:template>
62
63 <xsl:template match="section|simplesect|sect1|sect2|sect3|sect4|sect5|refsect1
64 |refsect2|refsect3|refsection" mode="xref-to">
65 <xsl:param name="referrer"/>
66 <xsl:param name="xrefstyle"/>
67 <xsl:param name="role"/>
68 <xsl:apply-templates select="." mode="object.xref.markup">
69 <xsl:with-param name="purpose" select="'xref'"/>
70 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
71 <xsl:with-param name="referrer" select="$referrer"/>
72 <xsl:with-param name="role" select="$role"/>
73 </xsl:apply-templates>
74 </xsl:template>
75
76
77 <xsl:template match="*" mode="object.xref.markup">
78 <xsl:param name="purpose"/>
79 <xsl:param name="xrefstyle"/>
80 <xsl:param name="referrer"/>
81 <xsl:param name="role"/>
82 <xsl:variable name="template">
83 <xsl:choose>
84 <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')">
85 <xsl:call-template name="make.gentext.template">
86 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
87 <xsl:with-param name="purpose" select="$purpose"/>
88 <xsl:with-param name="referrer" select="$referrer"/>
89 </xsl:call-template>
90 </xsl:when>
91 <xsl:when test="starts-with(normalize-space($xrefstyle), 'template:')">
92 <xsl:value-of select="substring-after(normalize-space($xrefstyle), 'template:')"/>
93 </xsl:when>
94 <xsl:otherwise>
95 <xsl:apply-templates select="." mode="object.xref.template">
96 <xsl:with-param name="purpose" select="$purpose"/>
97 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
98 <xsl:with-param name="referrer" select="$referrer"/>
99 </xsl:apply-templates>
100 </xsl:otherwise>
101 </xsl:choose>
102 </xsl:variable>
103 <xsl:if test="$template = ''">
104 <xsl:message>
105 <xsl:text>object.xref.markup: empty xref template</xsl:text>
106 <xsl:text> for linkend="</xsl:text>
107 <xsl:value-of select="@id"/>
108 <xsl:text>" and @xrefstyle="</xsl:text>
109 <xsl:value-of select="$xrefstyle"/>
110 <xsl:text>"</xsl:text>
111 </xsl:message>
112 </xsl:if>
113 <xsl:call-template name="substitute-markup">
114 <xsl:with-param name="purpose" select="$purpose"/>
115 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
116 <xsl:with-param name="referrer" select="$referrer"/>
117 <xsl:with-param name="template" select="$template"/>
118 <xsl:with-param name="role" select="$role"/>
119 </xsl:call-template>
120 </xsl:template>
121
122 <xsl:template name="substitute-markup">
123 <xsl:param name="template" select="''"/>
124 <xsl:param name="allow-anchors" select="'0'"/>
125 <xsl:param name="title" select="''"/>
126 <xsl:param name="subtitle" select="''"/>
127 <xsl:param name="label" select="''"/>
128 <xsl:param name="pagenumber" select="''"/>
129 <xsl:param name="purpose"/>
130 <xsl:param name="xrefstyle"/>
131 <xsl:param name="referrer"/>
132 <xsl:param name="role"/>
133 <xsl:choose>
134 <xsl:when test="contains($template, '%')">
135 <xsl:value-of select="substring-before($template, '%')"/>
136 <xsl:variable name="candidate"
137 select="substring(substring-after($template, '%'), 1, 1)"/>
138 <xsl:choose>
139 <xsl:when test="$candidate = 't'">
140 <xsl:apply-templates select="." mode="insert.title.markup">
141 <xsl:with-param name="purpose" select="$purpose"/>
142 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
143 <xsl:with-param name="role" select="$role"/>
144 <xsl:with-param name="title">
145 <xsl:choose>
146 <xsl:when test="$title != ''">
147 <xsl:copy-of select="$title"/>
148 </xsl:when>
149 <xsl:otherwise>
150 <xsl:apply-templates select="." mode="title.markup">
151 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
152 </xsl:apply-templates>
153 </xsl:otherwise>
154 </xsl:choose>
155 </xsl:with-param>
156 </xsl:apply-templates>
157 </xsl:when>
158 <xsl:when test="$candidate = 's'">
159 <xsl:apply-templates select="." mode="insert.subtitle.markup">
160 <xsl:with-param name="purpose" select="$purpose"/>
161 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
162 <xsl:with-param name="subtitle">
163 <xsl:choose>
164 <xsl:when test="$subtitle != ''">
165 <xsl:copy-of select="$subtitle"/>
166 </xsl:when>
167 <xsl:otherwise>
168 <xsl:apply-templates select="." mode="subtitle.markup">
169 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
170 </xsl:apply-templates>
171 </xsl:otherwise>
172 </xsl:choose>
173 </xsl:with-param>
174 </xsl:apply-templates>
175 </xsl:when>
176 <xsl:when test="$candidate = 'n'">
177 <xsl:apply-templates select="." mode="insert.label.markup">
178 <xsl:with-param name="purpose" select="$purpose"/>
179 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
180 <xsl:with-param name="label">
181 <xsl:choose>
182 <xsl:when test="$label != ''">
183 <xsl:copy-of select="$label"/>
184 </xsl:when>
185 <xsl:otherwise>
186 <xsl:apply-templates select="." mode="label.markup"/>
187 </xsl:otherwise>
188 </xsl:choose>
189 </xsl:with-param>
190 </xsl:apply-templates>
191 </xsl:when>
192 <xsl:when test="$candidate = 'p'">
193 <xsl:apply-templates select="." mode="insert.pagenumber.markup">
194 <xsl:with-param name="purpose" select="$purpose"/>
195 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
196 <xsl:with-param name="pagenumber">
197 <xsl:choose>
198 <xsl:when test="$pagenumber != ''">
199 <xsl:copy-of select="$pagenumber"/>
200 </xsl:when>
201 <xsl:otherwise>
202 <xsl:apply-templates select="." mode="pagenumber.markup"/>
203 </xsl:otherwise>
204 </xsl:choose>
205 </xsl:with-param>
206 </xsl:apply-templates>
207 </xsl:when>
208 <xsl:when test="$candidate = 'd'">
209 <xsl:apply-templates select="." mode="insert.direction.markup">
210 <xsl:with-param name="purpose" select="$purpose"/>
211 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
212 <xsl:with-param name="direction">
213 <xsl:choose>
214 <xsl:when test="$referrer">
215 <xsl:variable name="referent-is-below">
216 <xsl:for-each select="preceding::xref">
217 <xsl:if test="generate-id(.) = generate-id($referrer)">1</xsl:if>
218 </xsl:for-each>
219 </xsl:variable>
220 <xsl:choose>
221 <xsl:when test="$referent-is-below = ''">
222 <xsl:call-template name="gentext">
223 <xsl:with-param name="key" select="'above'"/>
224 </xsl:call-template>
225 </xsl:when>
226 <xsl:otherwise>
227 <xsl:call-template name="gentext">
228 <xsl:with-param name="key" select="'below'"/>
229 </xsl:call-template>
230 </xsl:otherwise>
231 </xsl:choose>
232 </xsl:when>
233 <xsl:otherwise>
234 <xsl:message>Attempt to use %d in gentext with no referrer!</xsl:message>
235 </xsl:otherwise>
236 </xsl:choose>
237 </xsl:with-param>
238 </xsl:apply-templates>
239 </xsl:when>
240 <xsl:when test="$candidate = '%' ">
241 <xsl:text>%</xsl:text>
242 </xsl:when>
243 <xsl:otherwise>
244 <xsl:text>%</xsl:text><xsl:value-of select="$candidate"/>
245 </xsl:otherwise>
246 </xsl:choose>
247 <!-- recurse with the rest of the template string -->
248 <xsl:variable name="rest"
249 select="substring($template,
250 string-length(substring-before($template, '%'))+3)"/>
251 <xsl:call-template name="substitute-markup">
252 <xsl:with-param name="template" select="$rest"/>
253 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
254 <xsl:with-param name="title" select="$title"/>
255 <xsl:with-param name="subtitle" select="$subtitle"/>
256 <xsl:with-param name="label" select="$label"/>
257 <xsl:with-param name="pagenumber" select="$pagenumber"/>
258 <xsl:with-param name="purpose" select="$purpose"/>
259 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
260 <xsl:with-param name="referrer" select="$referrer"/>
261 <xsl:with-param name="role" select="$role"/>
262 </xsl:call-template>
263 </xsl:when>
264 <xsl:otherwise>
265 <xsl:value-of select="$template"/>
266 </xsl:otherwise>
267 </xsl:choose>
268 </xsl:template>
269
270</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.