Debian Codegraph @

xslt/dita/common/dita-ref.xsl

raw
1 <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
2 <!--
3 This program is free software; you can redistribute it and/or modify it under
4 the terms of the GNU Lesser General Public License as published by the Free
5 Software Foundation; either version 2 of the License, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 details.
12
13 You should have received a copy of the GNU Lesser General Public License
14 along with this program; see the file COPYING.LGPL. If not, see <http://www.gnu.org/licenses/>.
15 -->
16 <!DOCTYPE xsl:stylesheet [
17 <!ENTITY % selectors SYSTEM "dita-selectors.mod">
18 %selectors;
19 ]>
20
21 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22 xmlns:func="http://exslt.org/functions"
23 xmlns:yelp="http://projects.gnome.org/yelp/"
24 extension-element-prefixes="func"
25 exclude-result-prefixes="yelp"
26 version="1.0">
27
28 <!--!!==========================================================================
29 DITA References
30
31 REMARK: Describe this module
32 -->
33
34
35 <!--@@==========================================================================
36 dita.ref.extension
37 The filename extension for output files.
38 @revision[version=3.8 date=2012-10-08 status=final]
39
40 When link targets are constructed by {dita.ref.href.target.custom} from `href`
41 attributes, this string is appended. This is used to specify the file extension
42 when creating output files from DITA topics.
43 -->
44 <xsl:param name="dita.ref.extension"/>
45
46
47 <xsl:key name="dita.id.key" match="&topic_topic_all;[@id]" use="@id"/>
48 <xsl:key name="dita.id.key" match="*[@id][not(self::&topic_topic_all;)]"
49 use="concat(ancestor-or-self::&topic_topic_all;[1]/@id, '/', @id)"/>
50
51
52 <xsl:template mode="dita.ref.content.mode" match="* | text()">
53 <xsl:value-of select="."/>
54 </xsl:template>
55
56 <xsl:template name="dita.id">
57 <xsl:param name="node" select="."/>
58 <xsl:choose>
59 <xsl:when test="$node/self::&topic_topic;">
60 <xsl:copy-of select="$node/@id"/>
61 </xsl:when>
62 <xsl:when test="$node/@id">
63 <xsl:attribute name="id">
64 <xsl:value-of select="concat($node/ancestor::&topic_topic;[@id][1]/@id, '::', $node/@id)"/>
65 </xsl:attribute>
66 </xsl:when>
67 </xsl:choose>
68 </xsl:template>
69
70 <xsl:template name="dita.ref.conref.attr">
71 <xsl:param name="attr"/>
72 <xsl:param name="node"/>
73 <xsl:param name="conref" select="yelp:dita.ref.conref($node)"/>
74 <xsl:variable name="val" select="$node/attribute::*[name(.) = $attr]"/>
75 <xsl:choose>
76 <xsl:when test="$val = '-dita-use-conref-target'">
77 <xsl:value-of select="$conref/attribute::*[name(.) = $attr]"/>
78 </xsl:when>
79 <xsl:otherwise>
80 <xsl:value-of select="$val"/>
81 </xsl:otherwise>
82 </xsl:choose>
83 </xsl:template>
84
85 <func:function name="yelp:dita.ref.conref">
86 <xsl:param name="node" select="."/>
87 <xsl:choose>
88 <xsl:when test="not($node/@conref)">
89 <func:result select="$node"/>
90 </xsl:when>
91 <xsl:when test="starts-with($node/@conref, '#')">
92 <func:result select="key('dita.id.key', substring-after($node/@conref, '#'))"/>
93 </xsl:when>
94 <xsl:otherwise>
95 <xsl:variable name="uri">
96 <xsl:choose>
97 <xsl:when test="contains($node/@conref, '#')">
98 <xsl:value-of select="substring-before($node/@conref, '#')"/>
99 </xsl:when>
100 <xsl:otherwise>
101 <xsl:value-of select="$node/@conref"/>
102 </xsl:otherwise>
103 </xsl:choose>
104 </xsl:variable>
105 <xsl:for-each select="document($uri, $node)">
106 <xsl:choose>
107 <xsl:when test="contains($node/@conref, '#')">
108 <func:result select="key('dita.id.key', substring-after($node/@conref, '#'))"/>
109 </xsl:when>
110 <xsl:otherwise>
111 <func:result select="/*"/>
112 </xsl:otherwise>
113 </xsl:choose>
114 </xsl:for-each>
115 </xsl:otherwise>
116 </xsl:choose>
117 </func:function>
118
119 <xsl:template name="dita.ref.href.target">
120 <xsl:param name="node" select="."/>
121 <xsl:param name="conref" select="yelp:dita.ref.conref($node)"/>
122 <xsl:param name="href">
123 <xsl:call-template name="dita.ref.conref.attr">
124 <xsl:with-param name="attr" select="'href'"/>
125 <xsl:with-param name="node" select="$node"/>
126 <xsl:with-param name="conref" select="$conref"/>
127 </xsl:call-template>
128 </xsl:param>
129 <xsl:variable name="format">
130 <xsl:call-template name="dita.ref.conref.attr">
131 <xsl:with-param name="attr" select="'format'"/>
132 <xsl:with-param name="node" select="$node"/>
133 <xsl:with-param name="conref" select="$conref"/>
134 </xsl:call-template>
135 </xsl:variable>
136 <xsl:variable name="scope">
137 <xsl:call-template name="dita.ref.conref.attr">
138 <xsl:with-param name="attr" select="'scope'"/>
139 <xsl:with-param name="node" select="$node"/>
140 <xsl:with-param name="conref" select="$conref"/>
141 </xsl:call-template>
142 </xsl:variable>
143 <xsl:variable name="type">
144 <xsl:call-template name="dita.ref.conref.attr">
145 <xsl:with-param name="attr" select="'type'"/>
146 <xsl:with-param name="node" select="$node"/>
147 <xsl:with-param name="conref" select="$conref"/>
148 </xsl:call-template>
149 </xsl:variable>
150 <xsl:variable name="custom">
151 <xsl:call-template name="dita.ref.href.target.custom">
152 <xsl:with-param name="node" select="$node"/>
153 <xsl:with-param name="href" select="$href"/>
154 </xsl:call-template>
155 </xsl:variable>
156 <xsl:choose>
157 <xsl:when test="$custom != ''">
158 <xsl:value-of select="$custom"/>
159 </xsl:when>
160 <xsl:when test="$scope = 'external' or ($format != '' and $format != 'dita')">
161 <xsl:value-of select="$href"/>
162 </xsl:when>
163 <xsl:otherwise>
164 <xsl:variable name="uri">
165 <xsl:choose>
166 <xsl:when test="contains($href, '#')">
167 <xsl:value-of select="substring-before($href, '#')"/>
168 </xsl:when>
169 <xsl:otherwise>
170 <xsl:value-of select="$href"/>
171 </xsl:otherwise>
172 </xsl:choose>
173 </xsl:variable>
174 <xsl:variable name="frag">
175 <xsl:if test="contains($href, '#')">
176 <xsl:value-of select="substring-after($href, '#')"/>
177 </xsl:if>
178 </xsl:variable>
179 <xsl:if test="$uri != ''">
180 <xsl:choose>
181 <xsl:when test="substring($uri, string-length($uri) - 4) = '.dita'">
182 <xsl:value-of select="substring($uri, 1, string-length($uri) - 5)"/>
183 </xsl:when>
184 <xsl:when test="substring($uri, string-length($uri) - 3) = '.xml'">
185 <xsl:value-of select="substring($uri, 1, string-length($uri) - 4)"/>
186 </xsl:when>
187 <xsl:otherwise>
188 <xsl:value-of select="$uri"/>
189 </xsl:otherwise>
190 </xsl:choose>
191 <xsl:value-of select="$dita.ref.extension"/>
192 </xsl:if>
193 <xsl:if test="$frag != ''">
194 <xsl:text>#</xsl:text>
195 <xsl:choose>
196 <xsl:when test="contains($frag, '/')">
197 <xsl:value-of select="substring-before($frag, '/')"/>
198 <xsl:text>::</xsl:text>
199 <xsl:value-of select="substring-after($frag, '/')"/>
200 </xsl:when>
201 <xsl:otherwise>
202 <xsl:value-of select="$frag"/>
203 </xsl:otherwise>
204 </xsl:choose>
205 </xsl:if>
206 </xsl:otherwise>
207 </xsl:choose>
208 </xsl:template>
209
210 <xsl:template name="dita.ref.href.target.custom">
211 <xsl:param name="node" select="."/>
212 <xsl:param name="conref" select="yelp:dita.ref.conref($node)"/>
213 <xsl:param name="href">
214 <xsl:call-template name="dita.ref.conref.attr">
215 <xsl:with-param name="attr" select="'href'"/>
216 <xsl:with-param name="node" select="$node"/>
217 <xsl:with-param name="conref" select="$conref"/>
218 </xsl:call-template>
219 </xsl:param>
220 </xsl:template>
221
222 <xsl:template name="dita.ref.href.content">
223 <xsl:param name="node" select="."/>
224 <xsl:param name="conref" select="yelp:dita.ref.conref($node)"/>
225 <xsl:param name="href">
226 <xsl:call-template name="dita.ref.conref.attr">
227 <xsl:with-param name="attr" select="'href'"/>
228 <xsl:with-param name="node" select="$node"/>
229 <xsl:with-param name="conref" select="$conref"/>
230 </xsl:call-template>
231 </xsl:param>
232 <xsl:variable name="format">
233 <xsl:call-template name="dita.ref.conref.attr">
234 <xsl:with-param name="attr" select="'format'"/>
235 <xsl:with-param name="node" select="$node"/>
236 <xsl:with-param name="conref" select="$conref"/>
237 </xsl:call-template>
238 </xsl:variable>
239 <xsl:variable name="scope">
240 <xsl:call-template name="dita.ref.conref.attr">
241 <xsl:with-param name="attr" select="'scope'"/>
242 <xsl:with-param name="node" select="$node"/>
243 <xsl:with-param name="conref" select="$conref"/>
244 </xsl:call-template>
245 </xsl:variable>
246 <xsl:choose>
247 <xsl:when test="$conref/node()[not(self::&topic_desc;)]">
248 <xsl:apply-templates mode="dita2html.topic.mode"
249 select="$conref/node()[not(self::&topic_desc;)]"/>
250 </xsl:when>
251 <xsl:when test="$scope = 'external' or ($format != '' and $format != 'dita')">
252 <xsl:value-of select="@href"/>
253 </xsl:when>
254 <xsl:otherwise>
255 <xsl:variable name="uri">
256 <xsl:choose>
257 <xsl:when test="contains($href, '#')">
258 <xsl:value-of select="substring-before($href, '#')"/>
259 </xsl:when>
260 <xsl:otherwise>
261 <xsl:value-of select="$href"/>
262 </xsl:otherwise>
263 </xsl:choose>
264 </xsl:variable>
265 <xsl:for-each select="document($uri, .)">
266 <xsl:variable name="frag">
267 <xsl:choose>
268 <xsl:when test="contains($href, '#')">
269 <xsl:value-of select="substring-after($href, '#')"/>
270 </xsl:when>
271 <xsl:otherwise>
272 <xsl:value-of select="/*/@id"/>
273 </xsl:otherwise>
274 </xsl:choose>
275 </xsl:variable>
276 <xsl:variable name="tnode" select="key('dita.id.key', $frag)"/>
277 <xsl:choose>
278 <xsl:when test="$tnode/&topic_titlealts;/&topic_navtitle;">
279 <xsl:apply-templates mode="dita.ref.content.mode"
280 select="$tnode/&topic_titlealts;/&topic_navtitle;/node()"/>
281 </xsl:when>
282 <xsl:otherwise>
283 <xsl:apply-templates mode="dita.ref.content.mode"
284 select="$tnode/&topic_title_all;/node()"/>
285 </xsl:otherwise>
286 </xsl:choose>
287 </xsl:for-each>
288 </xsl:otherwise>
289 </xsl:choose>
290 </xsl:template>
291
292 <xsl:template name="dita.ref.topicref.navtitle">
293 <xsl:param name="node" select="."/>
294 <xsl:param name="href" select="$node/@href"/>
295 <xsl:param name="base" select="$dita.map.base"/>
296 <xsl:choose>
297 <xsl:when test="$node[self::&map_map;]/&topic_booktitle;/&topic_mainbooktitle;">
298 <xsl:apply-templates mode="dita.ref.content.mode"
299 select="$node/&topic_booktitle;/&topic_mainbooktitle;/node()"/>
300 </xsl:when>
301 <xsl:when test="$node[self::&map_map;]">
302 <xsl:apply-templates mode="dita.ref.content.mode" select="$node/&topic_title;/node()"/>
303 </xsl:when>
304 <xsl:when test="$node/&map_topicmeta;/&topic_navtitle;">
305 <xsl:apply-templates mode="dita.ref.content.mode"
306 select="$node/&map_topicmeta;/&topic_navtitle;/node()"/>
307 </xsl:when>
308 <xsl:when test="$node/@navtitle">
309 <xsl:value-of select="$node/@navtitle"/>
310 </xsl:when>
311 <xsl:when test="$href != ''">
312 <xsl:variable name="topic" select="document($href, $base)/&topic_topic_all;"/>
313 <xsl:choose>
314 <xsl:when test="$topic/&topic_titlealts;/&topic_navtitle;">
315 <xsl:apply-templates mode="dita.ref.content.mode"
316 select="$topic/&topic_titlealts;/&topic_navtitle;/node()"/>
317 </xsl:when>
318 <xsl:otherwise>
319 <xsl:apply-templates mode="dita.ref.content.mode"
320 select="$topic/&topic_title_all;/node()"/>
321 </xsl:otherwise>
322 </xsl:choose>
323 </xsl:when>
324 </xsl:choose>
325 </xsl:template>
326
327 <xsl:template name="dita.ref.topicref.shortdesc">
328 <xsl:param name="node" select="."/>
329 <xsl:param name="href" select="$node/@href"/>
330 <xsl:param name="base" select="$dita.map.base"/>
331 <xsl:choose>
332 <xsl:when test="$node/&map_topicmeta;/&topic_shortdesc;">
333 <xsl:apply-templates mode="dita.ref.content.mode"
334 select="$node/&map_topicmeta;/&topic_shortdesc;/node()"/>
335 </xsl:when>
336 <xsl:when test="$href != ''">
337 <xsl:variable name="topic" select="document($href, $base)/&topic_topic_all;"/>
338 <xsl:if test="$topic/&topic_shortdesc;">
339 <xsl:apply-templates mode="dita.ref.content.mode"
340 select="$topic/&topic_shortdesc;/node()"/>
341 </xsl:if>
342 </xsl:when>
343 </xsl:choose>
344 </xsl:template>
345
346 </xsl:stylesheet>