source: stylesheets/pdf/lfs-xref.xsl@ 5cfc38e

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