Debian Codegraph @

demo/fo/xsl/common/topicmergeImpl.xsl

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" ?>
2
3 <!--
4 Copyright © 2004-2005 by Idiom Technologies, Inc. All rights reserved.
5 IDIOM is a registered trademark of Idiom Technologies, Inc. and WORLDSERVER
6 and WORLDSTART are trademarks of Idiom Technologies, Inc. All other
7 trademarks are the property of their respective owners.
8
9 IDIOM TECHNOLOGIES, INC. IS DELIVERING THE SOFTWARE "AS IS," WITH
10 ABSOLUTELY NO WARRANTIES WHATSOEVER, WHETHER EXPRESS OR IMPLIED, AND IDIOM
11 TECHNOLOGIES, INC. DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
12 BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
13 PURPOSE AND WARRANTY OF NON-INFRINGEMENT. IDIOM TECHNOLOGIES, INC. SHALL NOT
14 BE LIABLE FOR INDIRECT, INCIDENTAL, SPECIAL, COVER, PUNITIVE, EXEMPLARY,
15 RELIANCE, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF
16 ANTICIPATED PROFIT), ARISING FROM ANY CAUSE UNDER OR RELATED TO OR ARISING
17 OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, EVEN IF IDIOM
18 TECHNOLOGIES, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
19
20 Idiom Technologies, Inc. and its licensors shall not be liable for any
21 damages suffered by any person as a result of using and/or modifying the
22 Software or its derivatives. In no event shall Idiom Technologies, Inc.'s
23 liability for any damages hereunder exceed the amounts received by Idiom
24 Technologies, Inc. as a result of this transaction.
25
26 These terms and conditions supersede the terms and conditions in any
27 licensing agreement to the extent that such terms and conditions conflict
28 with those set forth herein.
29
30 This file is part of the DITA Open Toolkit project hosted on Sourceforge.net.
31 See the accompanying license.txt file for applicable licenses.
32 -->
33
34 <!-- An adaptation of the Toolkit topicmerge.xsl for FO plugin use. -->
35
36 <xsl:stylesheet version="2.0"
37 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
38 xmlns:exsl="http://exslt.org/common"
39 xmlns:ot-placeholder="http://suite-sol.com/namespaces/ot-placeholder"
40 extension-element-prefixes="exsl">
41
42 <xsl:output indent="no"/>
43
44 <xsl:key name="topic" match="dita-merge/*[contains(@class,' topic/topic ')]" use="concat('#',@id)"/>
45 <xsl:key name="topic" match="dita-merge/dita" use="concat('#',*[contains(@class, ' topic/topic ')][1]/@id)"/>
46 <xsl:key name="topicref" match="//*[contains(@class,' map/topicref ')]" use="generate-id()"/>
47
48 <!--
49 <xsl:template match="/">
50 <xsl:copy-of select="."/>
51 </xsl:template>
52 -->
53
54 <xsl:template match="dita-merge">
55 <xsl:element name="{name(*[contains(@class,' map/map ')])}">
56 <xsl:copy-of select="*[contains(@class,' map/map ')]/@*"/>
57 <xsl:apply-templates select="*[contains(@class,' map/map ')]" mode="build-tree"/>
58 </xsl:element>
59 </xsl:template>
60
61 <xsl:template match="dita-merge/*[contains(@class,' map/map ')]" mode="build-tree">
62 <opentopic:map xmlns:opentopic="http://www.idiominc.com/opentopic">
63 <xsl:apply-templates/>
64 </opentopic:map>
65 <xsl:apply-templates mode="build-tree"/>
66 </xsl:template>
67
68 <xsl:template match="*[contains(@class,' map/topicref ')]" mode="build-tree">
69 <xsl:choose>
70 <xsl:when test="not(normalize-space(@first_topic_id) = '')">
71 <xsl:apply-templates select="key('topic',@first_topic_id)">
72 <xsl:with-param name="parentId" select="generate-id()"/>
73 </xsl:apply-templates>
74 <xsl:if test="@first_topic_id != @href">
75 <xsl:apply-templates select="key('topic',@href)">
76 <xsl:with-param name="parentId" select="generate-id()"/>
77 </xsl:apply-templates>
78 </xsl:if>
79 </xsl:when>
80 <xsl:when test="not(normalize-space(@href) = '')">
81 <xsl:apply-templates select="key('topic',@href)">
82 <xsl:with-param name="parentId" select="generate-id()"/>
83 </xsl:apply-templates>
84 </xsl:when>
85 <xsl:when test="(normalize-space(@href) = '') and
86 (normalize-space(@navtitle) != '' or *[contains(@class,' map/topicmeta ')]/*[contains(@class,' topic/navtitle ')])">
87 <xsl:variable name="isNotTopicRef">
88 <xsl:call-template name="isNotTopicRef">
89 <xsl:with-param name="class" select="@class"/>
90 </xsl:call-template>
91 </xsl:variable>
92 <xsl:if test="contains($isNotTopicRef,'false')">
93 <topic id="{generate-id()}" class="- topic/topic ">
94 <title class=" topic/title ">
95 <xsl:choose>
96 <xsl:when test="*[contains(@class,' map/topicmeta ')]/*[contains(@class,' topic/navtitle ')]">
97 <xsl:copy-of select="*[contains(@class,' map/topicmeta ')]/*[contains(@class,' topic/navtitle ')]/node()"/>
98 </xsl:when>
99 <xsl:otherwise>
100 <xsl:value-of select="@navtitle"/>
101 </xsl:otherwise>
102 </xsl:choose>
103 </title>
104 <!--body class=" topic/body "/-->
105 <xsl:apply-templates mode="build-tree"/>
106 </topic>
107 </xsl:if>
108 </xsl:when>
109 <xsl:otherwise>
110 <xsl:apply-templates mode="build-tree"/>
111 </xsl:otherwise>
112 </xsl:choose>
113 </xsl:template>
114
115 <xsl:template match="*[@print = 'no']" priority="5" mode="build-tree"/>
116
117 <xsl:template match="*[contains(@class,' bookmap/backmatter ')] |
118 *[contains(@class,' bookmap/booklists ')] |
119 *[contains(@class,' bookmap/frontmatter ')]" priority="2" mode="build-tree">
120 <xsl:apply-templates mode="build-tree"/>
121 </xsl:template>
122
123 <xsl:template match="*[contains(@class,' bookmap/toc ')][not(@href)]" priority="2" mode="build-tree">
124 <ot-placeholder:toc id="{generate-id()}">
125 <xsl:apply-templates mode="build-tree"/>
126 </ot-placeholder:toc>
127 </xsl:template>
128
129 <xsl:template match="*[contains(@class,' bookmap/indexlist ')]" priority="2" mode="build-tree">
130 <ot-placeholder:indexlist id="{generate-id()}">
131 <xsl:apply-templates mode="build-tree"/>
132 </ot-placeholder:indexlist>
133 </xsl:template>
134
135 <xsl:template match="*[contains(@class,' bookmap/glossarylist ')]" priority="2" mode="build-tree">
136 <ot-placeholder:glossarylist id="{generate-id()}">
137 <xsl:apply-templates mode="build-tree"/>
138 </ot-placeholder:glossarylist>
139 </xsl:template>
140
141 <xsl:template match="*[contains(@class,' bookmap/tablelist ')]" priority="2" mode="build-tree">
142 <ot-placeholder:tablelist id="{generate-id()}">
143 <xsl:apply-templates mode="build-tree"/>
144 </ot-placeholder:tablelist>
145 </xsl:template>
146
147 <xsl:template match="*[contains(@class,' bookmap/figurelist ')]" priority="2" mode="build-tree">
148 <ot-placeholder:figurelist id="{generate-id()}">
149 <xsl:apply-templates mode="build-tree"/>
150 </ot-placeholder:figurelist>
151 </xsl:template>
152
153 <xsl:template match="*[contains(@class, ' map/topicref ') and @print='no']" priority="6"/>
154 <xsl:template match="*[contains(@class,' topic/topic ')] | dita-merge/dita">
155
156 <xsl:param name="parentId"/>
157 <xsl:variable name="idcount">
158 <!--for-each is used to change context. There's only one entry with a key of $parentId-->
159 <xsl:for-each select="key('topicref',$parentId)">
160 <xsl:value-of select="count(preceding::*[@href = current()/@href][not(ancestor::*[contains(@class, ' map/reltable ')])]) + count(ancestor::*[@href = current()/@href])"/>
161 </xsl:for-each>
162 </xsl:variable>
163 <xsl:copy>
164 <xsl:apply-templates select="@*[name() != 'id']"/>
165 <xsl:variable name="new_id">
166 <xsl:choose>
167 <xsl:when test="number($idcount) &gt; 0">
168 <xsl:value-of select="concat(@id,'_ssol',$idcount)"/>
169 </xsl:when>
170 <xsl:otherwise>
171 <xsl:value-of select="@id"/>
172 </xsl:otherwise>
173 </xsl:choose>
174 </xsl:variable>
175 <xsl:attribute name="id">
176 <xsl:value-of select="$new_id"/>
177 </xsl:attribute>
178 <xsl:apply-templates>
179 <xsl:with-param name="newid" select="$new_id"/>
180 </xsl:apply-templates>
181 <xsl:apply-templates select="key('topicref',$parentId)/*" mode="build-tree"/>
182 </xsl:copy>
183 </xsl:template>
184
185 <!-- Linkless topicref or topichead -->
186 <xsl:template match="*[contains(@class,' map/topicref ')][not(@href)]" priority="5">
187 <xsl:param name="newid"/>
188 <xsl:copy>
189 <xsl:attribute name="id">
190 <xsl:value-of select="generate-id()"/>
191 </xsl:attribute>
192 <xsl:apply-templates select="@*">
193 <xsl:with-param name="newid" select="$newid"/>
194 </xsl:apply-templates>
195 <xsl:apply-templates select="*|text()|processing-instruction()">
196 <xsl:with-param name="newid" select="$newid"/>
197 </xsl:apply-templates>
198 </xsl:copy>
199 </xsl:template>
200
201 <xsl:template match="*[contains(@class,' map/topicref ')]/@id" priority="5"/>
202
203 <xsl:template match="@href">
204 <xsl:param name="newid"/>
205 <xsl:variable name="topic-rest">
206 <xsl:value-of select="substring-after(., '#')"/>
207 </xsl:variable>
208
209 <xsl:variable name="topic-id">
210 <xsl:value-of select="substring-before($topic-rest, '/')"/>
211 </xsl:variable>
212
213 <xsl:variable name="element-id">
214 <xsl:value-of select="substring-after($topic-rest, '/')"/>
215 </xsl:variable>
216
217 <xsl:attribute name="href">
218 <xsl:choose>
219 <xsl:when test="$element-id = '' or not(starts-with(., '#unique'))">
220 <xsl:value-of select="."/>
221 </xsl:when>
222 <xsl:when test="ancestor::*[contains(@class, ' topic/topic ')][1]/@id = $topic-id">
223 <xsl:text>#</xsl:text>
224 <xsl:value-of select="$newid"/>
225 <xsl:text>/</xsl:text>
226 <xsl:value-of select="$newid"/>
227 <xsl:text>_Connect_42_</xsl:text>
228 <xsl:value-of select="$element-id"/>
229 </xsl:when>
230 <xsl:otherwise>
231 <xsl:value-of select="concat('#',$topic-id,'/',$topic-id,'_Connect_42_',$element-id)"/>
232 </xsl:otherwise>
233 </xsl:choose>
234
235
236 </xsl:attribute>
237 </xsl:template>
238
239 <xsl:template match="*[contains(@class,' map/topicref ')]/@href">
240 <xsl:copy-of select="."/>
241 <xsl:attribute name="id">
242 <xsl:variable name="fragmentId">
243 <xsl:value-of select="substring-after(.,'#')"/>
244 </xsl:variable>
245 <xsl:variable name="idcount">
246 <xsl:value-of select="count(../preceding::*[@href = current()][not(ancestor::*[contains(@class, ' map/reltable ')])]) + count(../ancestor::*[@href = current()])"/>
247 </xsl:variable>
248 <xsl:choose>
249 <xsl:when test="$idcount &gt; 0">
250 <xsl:value-of select="concat($fragmentId,'_ssol',$idcount)"/>
251 </xsl:when>
252 <xsl:otherwise>
253 <xsl:value-of select="$fragmentId"/>
254 </xsl:otherwise>
255 </xsl:choose>
256 </xsl:attribute>
257 </xsl:template>
258
259
260 <xsl:template match="*" mode="build-tree" priority="-1">
261 <xsl:apply-templates mode="build-tree"/>
262 </xsl:template>
263
264 <xsl:template match="text()" mode="build-tree" priority="-1"/>
265
266 <xsl:template match="*" priority="-1">
267 <xsl:param name="newid"/>
268 <xsl:copy>
269 <xsl:apply-templates select="@*">
270 <xsl:with-param name="newid" select="$newid"/>
271 </xsl:apply-templates>
272 <xsl:apply-templates select="*|text()|processing-instruction()">
273 <xsl:with-param name="newid" select="$newid"/>
274 </xsl:apply-templates>
275 </xsl:copy>
276 </xsl:template>
277
278 <xsl:template match="@*" priority="-1">
279 <xsl:copy-of select="."/>
280 </xsl:template>
281
282 <xsl:template match="processing-instruction()" priority="-1">
283 <xsl:copy-of select="."/>
284 </xsl:template>
285
286 <xsl:key name="duplicate-id"
287 match="*[not(contains(@class, ' topic/topic '))]/@id"
288 use="concat(ancestor::*[contains(@class, ' topic/topic ')][1]/@id, '|', .)"/>
289
290 <xsl:template match="@id[not(parent::*[contains(@class, ' topic/topic ')])]">
291 <xsl:param name="newid"/>
292 <xsl:attribute name="id">
293 <xsl:value-of select="$newid"/>
294 <xsl:text>_Connect_42_</xsl:text>
295 <xsl:value-of select="."/>
296 <xsl:variable name="current-id" select="concat(ancestor::*[contains(@class, ' topic/topic ')][1]/@id, '|', .)"/>
297 <xsl:if test="not(generate-id(.) = generate-id(key('duplicate-id', $current-id)[1]))">
298 <xsl:text>_</xsl:text>
299 <xsl:value-of select="generate-id()"/>
300 </xsl:if>
301 </xsl:attribute>
302 </xsl:template>
303
304 <xsl:template name="isNotTopicRef">
305 <xsl:param name="class"/>
306 <xsl:choose>
307 <xsl:when test="contains($class,' bookmap/abbrevlist ')"/>
308 <xsl:when test="contains($class,' bookmap/amendments ')"/>
309
310 <xsl:when test="contains($class,' bookmap/bookabstract ')"/>
311 <xsl:when test="contains($class,' bookmap/booklist ')"/>
312
313 <xsl:when test="contains($class,' bookmap/colophon ')"/>
314 <xsl:when test="contains($class,' bookmap/dedication ')"/>
315 <xsl:when test="contains($class,' bookmap/tablelist ')"/>
316 <xsl:when test="contains($class,' bookmap/trademarklist ')"/>
317 <xsl:when test="contains($class,' bookmap/figurelist ')"/>
318
319 <xsl:otherwise>
320 <xsl:value-of select="'false'"/>
321 </xsl:otherwise>
322 </xsl:choose>
323 </xsl:template>
324
325 <xsl:template match="*[contains(@class, ' map/reltable ')]" mode="build-tree"/>
326
327 </xsl:stylesheet>