1 | <?xml version="1.0" encoding="UTF-8" ?>
|
---|
2 | <!-- This file is part of the DITA Open Toolkit project hosted on
|
---|
3 | Sourceforge.net. See the accompanying license.txt file for
|
---|
4 | applicable licenses.-->
|
---|
5 | <!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->
|
---|
6 |
|
---|
7 | <!-- book.xsl
|
---|
8 | | Merge DITA topics with "validation" of topic property
|
---|
9 | *-->
|
---|
10 | <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
---|
11 |
|
---|
12 | <!-- Include error message template -->
|
---|
13 | <xsl:import href="../../../xsl/common/output-message.xsl"/>
|
---|
14 |
|
---|
15 | <!-- Set the prefix for error message numbers -->
|
---|
16 | <xsl:variable name="msgprefix">DOTX</xsl:variable>
|
---|
17 |
|
---|
18 | <xsl:variable name="xml-path"></xsl:variable>
|
---|
19 |
|
---|
20 | <xsl:output method="xml" encoding="utf-8" />
|
---|
21 |
|
---|
22 | <xsl:template match="/*">
|
---|
23 | <xsl:element name="{name()}">
|
---|
24 | <xsl:apply-templates select="@*" mode="copy-element"/>
|
---|
25 | <xsl:apply-templates select="*"/>
|
---|
26 | </xsl:element>
|
---|
27 | </xsl:template>
|
---|
28 |
|
---|
29 | <xsl:template match="/*/*[contains(@class,' map/topicmeta ')]" priority="1">
|
---|
30 | <xsl:apply-templates select="." mode="copy-element"/>
|
---|
31 | </xsl:template>
|
---|
32 |
|
---|
33 | <xsl:template match="/*[contains(@class,' map/map ')]/*[contains(@class,' topic/title ')]">
|
---|
34 | <xsl:apply-templates select="." mode="copy-element"/>
|
---|
35 | </xsl:template>
|
---|
36 |
|
---|
37 | <xsl:template match="*[contains(@class,' map/topicmeta ')]"/>
|
---|
38 | <xsl:template match="*[contains(@class,' map/navref ')]"/>
|
---|
39 | <xsl:template match="*[contains(@class,' map/reltable ')]"/>
|
---|
40 | <xsl:template match="*[contains(@class,' map/anchor ')]"/>
|
---|
41 |
|
---|
42 | <xsl:template match="*[contains(@class,' map/topicref ')][@href][not(@href='')][not(@print='no')]">
|
---|
43 | <xsl:variable name="topicrefClass"><xsl:value-of select="@class"/></xsl:variable>
|
---|
44 | <xsl:comment>Start of imbed for <xsl:value-of select="@href"/></xsl:comment>
|
---|
45 | <xsl:choose>
|
---|
46 | <xsl:when test="@format and not(@format='dita')">
|
---|
47 | <!-- Topicref to non-dita files will be ingored in PDF transformation -->
|
---|
48 | <xsl:call-template name="output-message">
|
---|
49 | <xsl:with-param name="msgnum">049</xsl:with-param>
|
---|
50 | <xsl:with-param name="msgsev">I</xsl:with-param>
|
---|
51 | </xsl:call-template>
|
---|
52 | </xsl:when>
|
---|
53 | <xsl:when test="contains(@href,'#')">
|
---|
54 | <xsl:variable name="sourcefile"><xsl:value-of select="substring-before(@href,'#')"/></xsl:variable>
|
---|
55 | <xsl:variable name="sourcetopic"><xsl:value-of select="substring-after(@href,'#')"/></xsl:variable>
|
---|
56 | <xsl:variable name="targetName"><xsl:value-of select="name(document($sourcefile,/)//*[@id=$sourcetopic][contains(@class,' topic/topic ')][1])"/></xsl:variable>
|
---|
57 | <xsl:if test="$targetName and not($targetName='')">
|
---|
58 | <xsl:element name="{$targetName}">
|
---|
59 | <xsl:apply-templates select="document($sourcefile,/)//*[@id=$sourcetopic][contains(@class,' topic/topic ')][1]/@*" mode="copy-element"/>
|
---|
60 | <xsl:attribute name="refclass"><xsl:value-of select="$topicrefClass"/></xsl:attribute>
|
---|
61 | <xsl:apply-templates select="document($sourcefile,/)//*[@id=$sourcetopic][contains(@class,' topic/topic ')][1]/*" mode="copy-element">
|
---|
62 | <xsl:with-param name="src-file"><xsl:value-of select="$sourcefile"/></xsl:with-param>
|
---|
63 | </xsl:apply-templates>
|
---|
64 | <xsl:apply-templates/>
|
---|
65 | </xsl:element>
|
---|
66 | </xsl:if>
|
---|
67 | </xsl:when>
|
---|
68 | <!-- If the target is a topic, as opposed to a ditabase mixed file -->
|
---|
69 | <xsl:when test="document(@href,/)/*[contains(@class,' topic/topic ')]">
|
---|
70 | <xsl:variable name="targetName"><xsl:value-of select="name(document(@href,/)/*)"/></xsl:variable>
|
---|
71 | <xsl:if test="$targetName and not($targetName='')">
|
---|
72 | <xsl:element name="{$targetName}">
|
---|
73 | <xsl:apply-templates select="document(@href,/)/*/@*" mode="copy-element"/>
|
---|
74 | <xsl:attribute name="refclass"><xsl:value-of select="$topicrefClass"/></xsl:attribute>
|
---|
75 | <!-- If the root element of the topic does not contain an id attribute, then generate one.
|
---|
76 | Later, we will use these id attributes as anchors for PDF bookmarks. -->
|
---|
77 | <xsl:if test="not(document(@href,/)/*/@id)">
|
---|
78 | <xsl:attribute name="id"><xsl:value-of select="generate-id()"/></xsl:attribute>
|
---|
79 | </xsl:if>
|
---|
80 | <xsl:apply-templates select="document(@href,/)/*/*" mode="copy-element">
|
---|
81 | <xsl:with-param name="src-file"><xsl:value-of select="@href"/></xsl:with-param>
|
---|
82 | </xsl:apply-templates>
|
---|
83 | <xsl:apply-templates/>
|
---|
84 | </xsl:element>
|
---|
85 | </xsl:if>
|
---|
86 | </xsl:when>
|
---|
87 | <!-- Otherwise: pointing to ditabase container; output each topic in the ditabase file.
|
---|
88 | The refclass value is copied to each of the main topics.
|
---|
89 | If this topicref has children, they will be treated as children of the <dita> wrapper.
|
---|
90 | This is the same as saving them as peers of the topics in the ditabase file. -->
|
---|
91 | <xsl:otherwise>
|
---|
92 | <xsl:for-each select="document(@href,/)/*/*">
|
---|
93 | <xsl:element name="{name()}">
|
---|
94 | <xsl:apply-templates select="@*" mode="copy-element"/>
|
---|
95 | <xsl:attribute name="refclass"><xsl:value-of select="$topicrefClass"/></xsl:attribute>
|
---|
96 | <xsl:apply-templates select="*" mode="copy-element"/>
|
---|
97 | </xsl:element>
|
---|
98 | </xsl:for-each>
|
---|
99 | <xsl:apply-templates/>
|
---|
100 | </xsl:otherwise>
|
---|
101 | </xsl:choose>
|
---|
102 | </xsl:template>
|
---|
103 |
|
---|
104 | <xsl:template match="*[contains(@class,' map/topicref ')][not(@href)]">
|
---|
105 | <xsl:element name="{name()}">
|
---|
106 | <xsl:apply-templates select="@*" mode="copy-element"/>
|
---|
107 | <xsl:apply-templates/>
|
---|
108 | </xsl:element>
|
---|
109 | </xsl:template>
|
---|
110 |
|
---|
111 | <xsl:template match="*|@*|comment()|processing-instruction()|text()" mode="copy-element">
|
---|
112 | <xsl:param name="src-file"></xsl:param>
|
---|
113 | <xsl:copy>
|
---|
114 | <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="copy-element">
|
---|
115 | <xsl:with-param name="src-file"><xsl:value-of select="$src-file"/></xsl:with-param>
|
---|
116 | </xsl:apply-templates>
|
---|
117 | </xsl:copy>
|
---|
118 | </xsl:template>
|
---|
119 |
|
---|
120 | <xsl:template match="@id" mode="copy-element">
|
---|
121 | <xsl:attribute name="id"><xsl:value-of select="generate-id(.)"/></xsl:attribute>
|
---|
122 | </xsl:template>
|
---|
123 |
|
---|
124 | <xsl:template match="@href" mode="copy-element" priority="1">
|
---|
125 | <xsl:param name="src-file"></xsl:param>
|
---|
126 |
|
---|
127 | <xsl:variable name="file-path">
|
---|
128 | <xsl:call-template name="get-file-path">
|
---|
129 | <xsl:with-param name="src-file">
|
---|
130 | <xsl:value-of select="$src-file"/>
|
---|
131 | </xsl:with-param>
|
---|
132 | </xsl:call-template>
|
---|
133 | <xsl:value-of select="."/>
|
---|
134 | </xsl:variable>
|
---|
135 |
|
---|
136 | <xsl:variable name="file-path-new">
|
---|
137 | <xsl:call-template name="normalize-path">
|
---|
138 | <xsl:with-param name="file-path">
|
---|
139 | <xsl:value-of select="translate($file-path,'\','/')"/>
|
---|
140 | </xsl:with-param>
|
---|
141 | </xsl:call-template>
|
---|
142 | </xsl:variable>
|
---|
143 |
|
---|
144 | <xsl:choose>
|
---|
145 | <xsl:when test="contains(.,'://') or ../@scope='external' or ../@scope='peer'">
|
---|
146 | <xsl:copy/>
|
---|
147 | </xsl:when>
|
---|
148 | <xsl:when test="(parent::*[contains(@class,' topic/xref ')] or parent::*[contains(@class,' topic/link ')]) and (not(../@format) or ../@format='dita' or ../@format='DITA')">
|
---|
149 | <xsl:choose>
|
---|
150 | <xsl:when test="starts-with(.,'#')">
|
---|
151 | <xsl:variable name="refer-path" select="substring-after(.,'#')"/>
|
---|
152 | <xsl:choose>
|
---|
153 | <xsl:when test="contains($refer-path,'/')">
|
---|
154 | <xsl:variable name="topic-id" select="substring-before($refer-path,'/')"/>
|
---|
155 | <xsl:variable name="target-id" select="substring-after($refer-path,'/')"/>
|
---|
156 | <xsl:variable name="href-value">
|
---|
157 | <xsl:value-of select="generate-id(//*[contains(@class,' topic/topic ')][@id=$topic-id]//*[@id=$target-id]/@id)"/>
|
---|
158 | </xsl:variable>
|
---|
159 | <xsl:if test="not($href-value='')">
|
---|
160 | <xsl:attribute name="href"><xsl:text>#</xsl:text><xsl:value-of select="$href-value"/></xsl:attribute>
|
---|
161 | </xsl:if>
|
---|
162 | </xsl:when>
|
---|
163 | <xsl:otherwise>
|
---|
164 | <xsl:variable name="href-value">
|
---|
165 | <xsl:value-of select="generate-id(//*[contains(@class,' topic/topic ')][@id=$refer-path]/@id)"/>
|
---|
166 | </xsl:variable>
|
---|
167 | <xsl:if test="not($href-value='')">
|
---|
168 | <xsl:attribute name="href"><xsl:text>#</xsl:text><xsl:value-of select="$href-value"/></xsl:attribute>
|
---|
169 | </xsl:if>
|
---|
170 | </xsl:otherwise>
|
---|
171 | </xsl:choose>
|
---|
172 | </xsl:when>
|
---|
173 | <xsl:when test="contains(.,'#')">
|
---|
174 | <xsl:variable name="file-name" select="substring-before(.,'#')"/>
|
---|
175 | <xsl:variable name="refer-path" select="substring-after(.,'#')"/>
|
---|
176 | <xsl:variable name="file-name-doc" select="document($file-name,/)"/>
|
---|
177 | <xsl:if test="$file-name-doc and not($file-name-doc='')">
|
---|
178 | <xsl:choose>
|
---|
179 | <xsl:when test="contains($refer-path,'/')">
|
---|
180 | <xsl:variable name="topic-id" select="substring-before($refer-path,'/')"/>
|
---|
181 | <xsl:variable name="target-id" select="substring-after($refer-path,'/')"/>
|
---|
182 | <xsl:variable name="href-value">
|
---|
183 | <xsl:value-of select="generate-id($file-name-doc//*[contains(@class,' topic/topic ')][@id=$topic-id]//*[@id=$target-id]/@id)"/>
|
---|
184 | </xsl:variable>
|
---|
185 | <xsl:if test="not($href-value='')">
|
---|
186 | <xsl:attribute name="href"><xsl:text>#</xsl:text><xsl:value-of select="$href-value"/></xsl:attribute>
|
---|
187 | </xsl:if>
|
---|
188 | </xsl:when>
|
---|
189 | <xsl:otherwise>
|
---|
190 | <xsl:variable name="href-value">
|
---|
191 | <xsl:value-of select="generate-id($file-name-doc//*[contains(@class,' topic/topic ')][@id=$refer-path]/@id)"/>
|
---|
192 | </xsl:variable>
|
---|
193 | <xsl:if test="not($href-value='')">
|
---|
194 | <xsl:attribute name="href"><xsl:text>#</xsl:text><xsl:value-of select="$href-value"/></xsl:attribute>
|
---|
195 | </xsl:if>
|
---|
196 | </xsl:otherwise>
|
---|
197 | </xsl:choose>
|
---|
198 | </xsl:if>
|
---|
199 | </xsl:when>
|
---|
200 | <xsl:otherwise>
|
---|
201 | <xsl:variable name="current-doc" select="document(.,/)"/>
|
---|
202 | <xsl:if test="$current-doc and not($current-doc='')">
|
---|
203 | <xsl:choose>
|
---|
204 | <xsl:when test="$current-doc//*[contains(@class,' topic/topic ')]/@id">
|
---|
205 | <xsl:attribute name="href"><xsl:text>#</xsl:text><xsl:value-of select="generate-id($current-doc//*[contains(@class,' topic/topic ')][1]/@id)"/></xsl:attribute>
|
---|
206 | </xsl:when>
|
---|
207 | <xsl:otherwise><xsl:text>#</xsl:text><xsl:value-of select="generate-id($current-doc//*[contains(@class,' topic/topic ')][1])"/></xsl:otherwise>
|
---|
208 | </xsl:choose>
|
---|
209 | </xsl:if>
|
---|
210 | </xsl:otherwise>
|
---|
211 | </xsl:choose>
|
---|
212 |
|
---|
213 | </xsl:when>
|
---|
214 | <xsl:otherwise>
|
---|
215 | <xsl:attribute name="href">
|
---|
216 | <xsl:value-of select="$file-path-new"/>
|
---|
217 | </xsl:attribute>
|
---|
218 | </xsl:otherwise>
|
---|
219 | </xsl:choose>
|
---|
220 | </xsl:template>
|
---|
221 |
|
---|
222 | <xsl:template name="get-file-path">
|
---|
223 | <xsl:param name="src-file"/>
|
---|
224 | <xsl:if test="contains($src-file,'/')">
|
---|
225 | <xsl:value-of select="substring-before($src-file,'/')"/>
|
---|
226 | <xsl:text>/</xsl:text>
|
---|
227 | <xsl:call-template name="get-file-path">
|
---|
228 | <xsl:with-param name="src-file">
|
---|
229 | <xsl:value-of select="substring-after($src-file,'/')"/>
|
---|
230 | </xsl:with-param>
|
---|
231 | </xsl:call-template>
|
---|
232 | </xsl:if>
|
---|
233 | </xsl:template>
|
---|
234 |
|
---|
235 | <xsl:template name="normalize-path">
|
---|
236 | <xsl:param name="file-path" />
|
---|
237 | <xsl:choose>
|
---|
238 | <xsl:when test="contains($file-path,'..')">
|
---|
239 | <xsl:variable name="firstdir" select="substring-before($file-path, '/')" />
|
---|
240 | <xsl:variable name="newpath" select="substring-after($file-path,'/')" />
|
---|
241 | <xsl:choose>
|
---|
242 | <xsl:when test="$firstdir='..'">
|
---|
243 | <xsl:text>../</xsl:text>
|
---|
244 | <xsl:call-template name="normalize-path">
|
---|
245 | <xsl:with-param name="file-path">
|
---|
246 | <xsl:value-of select="$newpath"/>
|
---|
247 | </xsl:with-param>
|
---|
248 | </xsl:call-template>
|
---|
249 | </xsl:when>
|
---|
250 | <xsl:otherwise>
|
---|
251 | <xsl:variable name="beforedotdot" select="substring-before($file-path,'/..')"></xsl:variable>
|
---|
252 | <xsl:variable name="beforedotdotparent" >
|
---|
253 | <xsl:call-template name="parent-path">
|
---|
254 | <xsl:with-param name="pathname" select="$beforedotdot" />
|
---|
255 | </xsl:call-template>
|
---|
256 | </xsl:variable>
|
---|
257 | <xsl:variable name="afterdotdot" select="substring-after($file-path,'../')"></xsl:variable>
|
---|
258 | <xsl:call-template name="normalize-path">
|
---|
259 | <xsl:with-param name="file-path">
|
---|
260 | <xsl:value-of select="concat($beforedotdotparent,$afterdotdot)"/>
|
---|
261 | </xsl:with-param>
|
---|
262 | </xsl:call-template>
|
---|
263 | </xsl:otherwise>
|
---|
264 | </xsl:choose>
|
---|
265 | </xsl:when>
|
---|
266 | <xsl:otherwise>
|
---|
267 | <xsl:value-of select="$file-path"></xsl:value-of>
|
---|
268 | </xsl:otherwise>
|
---|
269 | </xsl:choose>
|
---|
270 | </xsl:template>
|
---|
271 |
|
---|
272 | <xsl:template name="parent-path">
|
---|
273 | <xsl:param name="pathname" />
|
---|
274 | <xsl:choose>
|
---|
275 | <xsl:when test="contains($pathname, '/')">
|
---|
276 | <xsl:value-of select="substring-before($pathname, '/')"/>
|
---|
277 | <xsl:text>/</xsl:text>
|
---|
278 | <xsl:call-template name="parent-path">
|
---|
279 | <xsl:with-param name="pathname" select="substring-after($pathname,'/')"/>
|
---|
280 | </xsl:call-template>
|
---|
281 | </xsl:when>
|
---|
282 | </xsl:choose>
|
---|
283 | </xsl:template>
|
---|
284 |
|
---|
285 | <xsl:template match="processing-instruction()">
|
---|
286 | <xsl:copy></xsl:copy>
|
---|
287 | </xsl:template>
|
---|
288 |
|
---|
289 | </xsl:stylesheet>
|
---|