blob: 5a97f6bf47f88549781483bc325a2907942d530f [file] [log] [blame]
Marc Kupietz0014c5c2024-09-30 09:12:33 +02001<?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<!-- h2d.xsl
6 | Migrate XHTML content into DITA topics
7 |
8 | (C) Copyright IBM Corporation 2001, 2002, 2003, 2004, 2005, 2006. All Rights Reserved.
9 +
10 | Udates:
11 | 2002/06/11 DRD: changed BR trap from PI to comment
12 | 2003/02/13 DRD: removed xhtml: namespace prefix baggage (use tidy's -doctype omit)
13 | added support for text nodes in task content pulls
14 | added renaming of related-links extensions to ".dita" instead of ".htm(l)"
15 | if any name/content metas (except generators), open a prolog and populate metadata
16 | 2003/03/27 DRD: extended meta trap to include "GENERATOR" (uc)
17 | added default xml:lang="en-us"
18 | added genidattribute to provide single place to generate topic id (needs work)
19 | 2003/03/28 RDA: Place <title> into <searchtitle> instead of <shortdesc>
20 | Do not create an XREF for <a> without @href
21 | Only create "Collected links" when links exist
22 | Do not add links to "Collected links" if they are within this file
23 | Add support for @format, @scope, and <desc> inside link
24 | Add variables to check for first heading level, to make sections later
25 | 2003/04/04 RDA: Add FILENAME parameter to determine more unique file IDs
26 | 2003/04/05 RDA: Add support for multi-column tables, and for spanned rows (not yet spanned columns)
27 | 2003/05/07 RDA: Add support for thead, tbody, and caption within tables
28 | 2003/07/17 RDA: Allow underscores to appear in the topic ID, also period and dash if not
29 | the first character
30 | 2003/08/21 RDA: Allow spanned columns within tables
31 | Allow single paragraphs in table entries, to ignore the <p> tag
32 | 2003/10/07 RDA: Process span classes that were moved by tidy (like class=c1)
33 | 2003/10/13 RDA: Pre-process the HTML, if it contains lists that stop and start
34 | 2004/10/13 RDA: Pass through @compact, plus table/row attributes
35 | If a link starts with http:, https:, or ftp:, do not change extension
36 | 2004/11/22 RDA: Update to pass through comments
37 | 2005/01/08 RDA: Revised for external publication
38 | 2006/01/04 RDA: Added various bug fixes, mostly for tables and class attributes
39 | Updated public IDs to use the OASIS standard
40 +-->
41
42
43<!-- If you wish to set the doctype manually, you will need to comment out the
44 following 5 lines, and uncomment the xsl:stylesheet lines below. See the
45 comments before that section for details. -->
46<!--<xsl:stylesheet version="1.0"
47 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
48>
49<xsl:output method="xml" indent="no" encoding="utf-8" />
50<xsl:param name="infotype">topic</xsl:param>-->
51
52<!-- If you wish to set the doctype dynamically, you will need to uncomment
53 the following section. The section sets the XSLT version as 1.1, which
54 allows some engines to use variables for system and public IDs.
55 Those variables are set here based on the infotype parameter, or they
56 can be passed in directly from the command line. -->
57<xsl:stylesheet version="1.1"
58 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
59 xmlns:saxon="http://icl.com/saxon"
60 extension-element-prefixes="saxon">
61<xsl:param name="infotype">topic</xsl:param>
62 <!-- Output XSLT messages warning various conversion problems + add XML comments in places where the conversion
63 is not perfect-->
64 <xsl:param name="verbose" select="false()"/>
65 <!-- Generate required cleanup elements -->
66 <xsl:param name="generateRequiredCleanup" select="false()"/>
67 <!-- Generate related links at the end of the topic -->
68 <xsl:param name="generateRelatedLinks" select="false()"/>
69 <!-- Convert XHTML metadata to DITA metadata -->
70 <xsl:param name="preserveMetadata" select="false()"/>
71
72<xsl:variable name="systemid">
73 <xsl:choose>
74 <xsl:when test="$infotype='concept'">concept.dtd</xsl:when>
75 <xsl:when test="$infotype='task'">task.dtd</xsl:when>
76 <xsl:when test="$infotype='reference'">reference.dtd</xsl:when>
77 <xsl:otherwise>topic.dtd</xsl:otherwise>
78 </xsl:choose>
79</xsl:variable>
80<xsl:variable name="publicid">
81 <xsl:choose>
82 <xsl:when test="$infotype='concept'">-//OASIS//DTD DITA Concept//EN</xsl:when>
83 <xsl:when test="$infotype='task'">-//OASIS//DTD DITA Task//EN</xsl:when>
84 <xsl:when test="$infotype='reference'">-//OASIS//DTD DITA Reference//EN</xsl:when>
85 <xsl:otherwise>-//OASIS//DTD DITA Topic//EN</xsl:otherwise>
86 </xsl:choose>
87</xsl:variable>
88
89<xsl:output method="xml" indent="yes" encoding="UTF-8" />
90
91<!-- ========== PARAMETERS ============== -->
92
93<!-- what kind of topic to generate? set up default of 'topic' but allow external override -->
94<!-- sample call:
95 saxon tasktest.html h2d.xsl infotype=task > tasktest.dita
96 -->
97
98<!-- What extension should be used for links that go to other DITA topics?
99 Assumption is that local HTML targets will be converted to DITA. -->
100<xsl:param name="dita-extension">.dita</xsl:param>
101
102<!-- Create a parameter for the defualt language -->
103<xsl:param name="default-lang">en-us</xsl:param>
104
105<!-- Take the filename as an input parameter to determine the main topic's ID -->
106<xsl:param name="FILENAME">
107 <xsl:choose>
108 <xsl:when test="$infotype='concept' or $infotype='reference' or $infotype='task' or $infotype='topic'">
109 <xsl:value-of select="$infotype"/>
110 </xsl:when>
111 <xsl:otherwise>
112 <xsl:value-of select="'topic'"/>
113 </xsl:otherwise>
114 </xsl:choose>
115 <xsl:value-of select="string-length()"/>
116 <xsl:value-of select="'.htm'"/>
117</xsl:param>
118
119<!-- Use the FILENAME to determine the ID for the output topic. Invalid ID characters
120 must be removed (replaced with generic D character). If a filename starts with
121 a number, which cannot start an ID, all numbers will be replaced with letters. -->
122<xsl:variable name="filename-id">
123 <xsl:choose>
124 <xsl:when test="starts-with($FILENAME,'0') or starts-with($FILENAME,'1') or
125 starts-with($FILENAME,'2') or starts-with($FILENAME,'3') or
126 starts-with($FILENAME,'4') or starts-with($FILENAME,'5') or
127 starts-with($FILENAME,'6') or starts-with($FILENAME,'7') or
128 starts-with($FILENAME,'8') or starts-with($FILENAME,'9') or
129 starts-with($FILENAME,'.') or starts-with($FILENAME,'-')">
130 <xsl:value-of select="translate(substring-before($FILENAME,'.htm'),
131 '0123456789.-,!@#$%^()=+[]{}/\;&amp;',
132 'ABCDEFGHIJDDDDDDDDDDDDDDDDDDDDDD')"/>
133 </xsl:when>
134 <xsl:otherwise>
135 <xsl:value-of select="translate(substring-before($FILENAME,'.htm'),
136 ',!@#$%^()=+[]{}/\;&amp;',
137 'DDDDDDDDDDDDDDDDDDDDDD')"/>
138 </xsl:otherwise>
139 </xsl:choose>
140</xsl:variable>
141
142<!-- eliminate whitespace in body as a migration concern -->
143<xsl:strip-space elements="body"/>
144
145<!-- RDA: use the 2 variables below, instead of the 6 starter files -->
146<xsl:variable name="main-head-level">
147 <xsl:choose>
148 <xsl:when test="/html/body/descendant::h1[1][not(preceding::h2|preceding::h3|preceding::h4|preceding::h5|preceding::h6)]">h1</xsl:when>
149 <xsl:when test="/html/body/descendant::h2[1][not(preceding::h3|preceding::h4|preceding::h5|preceding::h6)]">h2</xsl:when>
150 <xsl:when test="/html/body/descendant::h3[1][not(preceding::h4|preceding::h5|preceding::h6)]">h3</xsl:when>
151 <xsl:when test="/html/body/descendant::h4[1][not(preceding::h5|preceding::h6)]">h4</xsl:when>
152 <xsl:when test="/html/body/descendant::h5[1][not(preceding::h6)]">h5</xsl:when>
153 <xsl:when test="/html/body/descendant::h6[1]">h6</xsl:when>
154 <xsl:otherwise>h1</xsl:otherwise>
155 </xsl:choose>
156</xsl:variable>
157
158<xsl:template name="output-message">
159 <xsl:param name="msg" select="***"/>
160 <xsl:if test="$verbose">
161 <xsl:message><xsl:value-of select="$msg"/></xsl:message>
162 </xsl:if>
163</xsl:template>
164
165<!-- if needed, add the dita wrapper here -->
166<xsl:template match="/">
167
168 <!-- oXygen patch -->
169 <xsl:text disable-output-escaping="yes" xml:space="preserve">
170&lt;!DOCTYPE </xsl:text> <xsl:value-of select="$infotype"/>
171 PUBLIC "<xsl:value-of select="$publicid"/>" "<xsl:value-of select="$systemid"/>" <xsl:text disable-output-escaping="yes">&gt;</xsl:text>
172 <!-- end oXygen patch -->
173
174 <xsl:call-template name="validate-parameters"/>
175<!-- Some HTML editors store ordered lists as sequential lists, with all but the first
176 using @start to resume numbering. If a topic uses this, the lists will be pulled together.
177 They are placed in a variable that contains a cleaned up version of the original HTML. The
178 standard templates are then used to format the modified HTML. Templates for pre-processing
179 the HTML Are all at the bottom of the file.
180 If there are no lists with abnormal numbering, just start processing. -->
181 <xsl:choose>
182 <xsl:when test="not(//ol[@start])"><xsl:apply-templates select="*|comment()|text()|processing-instruction()"/></xsl:when>
183 <xsl:otherwise>
184 <!-- Process the entire file. Most elements are copied straight into the variable; ordered
185 lists and elements between them are modified slightly. -->
186 <xsl:variable name="shift-lists">
187 <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="shift-lists"/>
188 </xsl:variable>
189 <!-- For some reason, if I do this without a mode, I get a Java overflow error. -->
190 <xsl:apply-templates select="html/preceding-sibling::comment()"/>
191 <xsl:apply-templates select="$shift-lists" mode="redirect"/>
192 <xsl:apply-templates select="html/following-sibling::comment()"/>
193 </xsl:otherwise>
194 </xsl:choose>
195</xsl:template>
196
197<!-- Process the HTML file that was placed in a variable using normal routines. -->
198<xsl:template match="*" mode="redirect">
199 <xsl:apply-templates select="."/>
200</xsl:template>
201
202<!-- general the overall topic container and pull content for it -->
203
204<xsl:template match="*[local-name()='html']">
205 <xsl:choose>
206 <xsl:when test="$infotype='topic'"><xsl:call-template name="gen-topic"/></xsl:when>
207 <xsl:when test="$infotype='concept'"><xsl:call-template name="gen-concept"/></xsl:when>
208 <xsl:when test="$infotype='task'"><xsl:call-template name="gen-task"/></xsl:when>
209 <xsl:when test="$infotype='reference'"><xsl:call-template name="gen-reference"/></xsl:when>
210 <xsl:otherwise><xsl:call-template name="gen-topic"/></xsl:otherwise>
211 </xsl:choose>
212</xsl:template>
213
214
215<!-- named templates for various infotyped topic shells -->
216
217<!-- Generic topic template -->
218
219<xsl:template name="gen-topic">
220 <topic xml:lang="{$default-lang}">
221 <xsl:call-template name="genidattribute"/>
222 <xsl:call-template name="gentitle"/>
223 <xsl:call-template name="gentitlealts"/>
224 <xsl:call-template name="genprolog"/>
225 <body>
226 <xsl:apply-templates select="(body/*|body/text()|body/comment())[1]" mode="creating-content-before-section"/>
227 <xsl:choose>
228 <xsl:when test="$main-head-level='h1'">
229 <xsl:apply-templates select="body/h1[preceding-sibling::h1]|body/h2|body/h3|body/h4|body/h5|body/h6|body/h7" mode="create-section-with-following-content"/>
230 </xsl:when>
231 <xsl:when test="$main-head-level='h2'">
232 <xsl:apply-templates select="body/h1|body/h2[preceding-sibling::h2]|body/h3|body/h4|body/h5|body/h6|body/h7" mode="create-section-with-following-content"/>
233 </xsl:when>
234 <xsl:when test="$main-head-level='h3'">
235 <xsl:apply-templates select="body/h1|body/h2|body/h3[preceding-sibling::h3]|body/h4|body/h5|body/h6|body/h7" mode="create-section-with-following-content"/>
236 </xsl:when>
237 <xsl:when test="$main-head-level='h4'">
238 <xsl:apply-templates select="body/h1|body/h2|body/h3|body/h4[preceding-sibling::h4]|body/h5|body/h6|body/h7" mode="create-section-with-following-content"/>
239 </xsl:when>
240 <xsl:when test="$main-head-level='h5'">
241 <xsl:apply-templates select="body/h1|body/h2|body/h3|body/h4|body/h5[preceding-sibling::h5]|body/h6|body/h7" mode="create-section-with-following-content"/>
242 </xsl:when>
243 <xsl:otherwise> <!-- Otherwise, level is h6 -->
244 <xsl:apply-templates select="body/h1|body/h2|body/h3|body/h4|body/h5|body/h6[preceding-sibling::h6]|body/h7" mode="create-section-with-following-content"/>
245 </xsl:otherwise>
246 </xsl:choose>
247 </body>
248 <xsl:call-template name="genrellinks"/>
249 </topic>
250</xsl:template>
251
252
253<!-- Implementation note: except for topic, DITA infotypes have content models with strong
254 containment rules. These implementations try to separate allowed body content from
255 contexts required by the target formats. This may need additional work. With XHTML 2.0,
256 the tests for contextually introduced containment are eased and these templates can be
257 generalized and possibly made more robust. -->
258
259<!-- Concept topic template -->
260
261<!-- See task for ideas implemented here for separating regular body content from a first heading, which
262 ordinarily denotes one or more sections with NO following text. We put EVERYTHING after the
263 first h2 into a section as a strong-arm way to enforce the concept model, but users will have
264 to check for intended scoping afterwards. -->
265
266<xsl:template name="gen-concept">
267 <concept xml:lang="{$default-lang}">
268 <xsl:call-template name="genidattribute"/>
269 <xsl:if test="@id"><xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute></xsl:if>
270 <xsl:call-template name="gentitle"/>
271 <xsl:call-template name="gentitlealts"/>
272 <xsl:call-template name="genprolog"/>
273
274 <conbody>
275 <!-- Anything up to the first heading (except for whatever heading was pulled into <title>) will
276 be processed as it would for a topic. After a heading is encountered, a section will be created
277 for that and all following headings. Content up to the next heading will go into the section. -->
278 <xsl:apply-templates select="(body/*|body/text()|body/comment())[1]" mode="creating-content-before-section"/>
279 <xsl:choose>
280 <xsl:when test="$main-head-level='h1'">
281 <xsl:apply-templates select="body/h1[preceding-sibling::h1]|body/h2|body/h3|body/h4|body/h5|body/h6|body/h7" mode="create-section-with-following-content"/>
282 </xsl:when>
283 <xsl:when test="$main-head-level='h2'">
284 <xsl:apply-templates select="body/h1|body/h2[preceding-sibling::h2]|body/h3|body/h4|body/h5|body/h6|body/h7" mode="create-section-with-following-content"/>
285 </xsl:when>
286 <xsl:when test="$main-head-level='h3'">
287 <xsl:apply-templates select="body/h1|body/h2|body/h3[preceding-sibling::h3]|body/h4|body/h5|body/h6|body/h7" mode="create-section-with-following-content"/>
288 </xsl:when>
289 <xsl:when test="$main-head-level='h4'">
290 <xsl:apply-templates select="body/h1|body/h2|body/h3|body/h4[preceding-sibling::h4]|body/h5|body/h6|body/h7" mode="create-section-with-following-content"/>
291 </xsl:when>
292 <xsl:when test="$main-head-level='h5'">
293 <xsl:apply-templates select="body/h1|body/h2|body/h3|body/h4|body/h5[preceding-sibling::h5]|body/h6|body/h7" mode="create-section-with-following-content"/>
294 </xsl:when>
295 <xsl:otherwise> <!-- Otherwise, level is h6 -->
296 <xsl:apply-templates select="body/h1|body/h2|body/h3|body/h4|body/h5|body/h6[preceding-sibling::h6]|body/h7" mode="create-section-with-following-content"/>
297 </xsl:otherwise>
298 </xsl:choose>
299
300 </conbody>
301 <xsl:call-template name="genrellinks"/>
302 </concept>
303</xsl:template>
304
305<xsl:template match="*|text()|comment()" mode="creating-content-before-section">
306 <xsl:apply-templates select="."/>
307 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="creating-content-before-section"/>
308</xsl:template>
309<xsl:template match="h1|h2|h3|h4|h5|h6" mode="creating-content-before-section">
310 <xsl:choose>
311 <xsl:when test="$main-head-level='h1' and self::h1 and not(preceding::h1)">
312 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="creating-content-before-section"/>
313 </xsl:when>
314 <xsl:when test="$main-head-level='h2' and self::h2 and not(preceding::h2)">
315 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="creating-content-before-section"/>
316 </xsl:when>
317 <xsl:when test="$main-head-level='h3' and self::h3 and not(preceding::h3)">
318 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="creating-content-before-section"/>
319 </xsl:when>
320 <xsl:when test="$main-head-level='h4' and self::h4 and not(preceding::h4)">
321 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="creating-content-before-section"/>
322 </xsl:when>
323 <xsl:when test="$main-head-level='h5' and self::h5 and not(preceding::h5)">
324 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="creating-content-before-section"/>
325 </xsl:when>
326 <xsl:when test="$main-head-level='h6' and self::h6 and not(preceding::h6)">
327 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="creating-content-before-section"/>
328 </xsl:when>
329 </xsl:choose>
330</xsl:template>
331
332<!-- Reference topic template -->
333
334<xsl:template name="gen-reference">
335 <reference xml:lang="{$default-lang}">
336 <xsl:call-template name="genidattribute"/>
337 <xsl:call-template name="gentitle"/>
338 <xsl:call-template name="gentitlealts"/>
339 <xsl:call-template name="genprolog"/>
340 <refbody>
341 <!-- Processing is similar to concept, except that everything before the second heading must also be
342 placed into a section. Also, any tables can be outside of the section. -->
343 <xsl:choose>
344 <xsl:when test="$main-head-level='h1'">
345 <!-- First process anything that comes before any subheadings, or a second h1 -->
346 <xsl:if test="body/text()[not(preceding::table or preceding::h1[2] or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6)]|
347 body/comment()[not(preceding::table or preceding::h1[2] or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6)]|
348 body/*[not(self::table or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or
349 preceding::table or preceding::h1[2] or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6)]">
350 <section>
351 <xsl:apply-templates select="body/text()[not(preceding::table or preceding::h1[2] or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6)]|
352 body/comment()[not(preceding::table or preceding::h1[2] or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6)]|
353 body/*[not(self::table or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or
354 preceding::table[parent::body] or preceding::h1[2] or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6)]"/>
355 </section>
356 </xsl:if>
357 <!-- Now turn any other headings into sections, with following stuff -->
358 <xsl:apply-templates select="body/table|body/h1[preceding-sibling::h1]|body/h2|body/h3|body/h4|body/h5|body/h6|body/h7" mode="create-section-with-following-content"/>
359 </xsl:when>
360 <xsl:when test="$main-head-level='h2'">
361 <!-- First process anything that comes before any subheadings, or a second h2 -->
362 <xsl:if test="body/text()[not(preceding::table or preceding::h1 or preceding::h2[2] or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6)]|
363 body/comment()[not(preceding::table or preceding::h1 or preceding::h2[2] or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6)]|
364 body/*[not(self::table or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or
365 preceding::table or preceding::h1 or preceding::h2[2] or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6)]">
366 <section>
367 <xsl:apply-templates select="body/text()[not(preceding::table or preceding::h1 or preceding::h2[2] or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6)]|
368 body/comment()[not(preceding::table or preceding::h1 or preceding::h2[2] or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6)]|
369 body/*[not(self::table or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or
370 preceding::table[parent::body] or preceding::h1 or preceding::h2[2] or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6)]"/>
371 </section>
372 </xsl:if>
373 <!-- Now turn any other headings into sections, with following stuff -->
374 <xsl:apply-templates select="body/table|body/h1|body/h2[preceding-sibling::h2]|body/h3|body/h4|body/h5|body/h6|body/h7" mode="create-section-with-following-content"/>
375 </xsl:when>
376 <xsl:when test="$main-head-level='h3'">
377 <!-- First process anything that comes before any subheadings, or a second h3 -->
378 <xsl:if test="body/text()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3[2] or preceding::h4 or preceding::h5 or preceding::h6)]|
379 body/comment()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3[2] or preceding::h4 or preceding::h5 or preceding::h6)]|
380 body/*[not(self::table or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or
381 preceding::table or preceding::h1 or preceding::h2 or preceding::h3[2] or preceding::h4 or preceding::h5 or preceding::h6)]">
382 <section>
383 <xsl:apply-templates select="body/text()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3[2] or preceding::h4 or preceding::h5 or preceding::h6)]|
384 body/comment()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3[2] or preceding::h4 or preceding::h5 or preceding::h6)]|
385 body/*[not(self::table or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or
386 preceding::table[parent::body] or preceding::h1 or preceding::h2 or preceding::h3[2] or preceding::h4 or preceding::h5 or preceding::h6)]"/>
387 </section>
388 </xsl:if>
389 <!-- Now turn any other headings into sections, with following stuff -->
390 <xsl:apply-templates select="body/table|body/h1|body/h2|body/h3[preceding-sibling::h3]|body/h4|body/h5|body/h6|body/h7" mode="create-section-with-following-content"/>
391 </xsl:when>
392 <xsl:when test="$main-head-level='h4'">
393 <!-- First process anything that comes before any subheadings, or a second h4 -->
394 <xsl:if test="body/text()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4[2] or preceding::h5 or preceding::h6)]|
395 body/text()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4[2] or preceding::h5 or preceding::h6)]|
396 body/*[not(self::table or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or
397 preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4[2] or preceding::h5 or preceding::h6)]">
398 <section>
399 <xsl:apply-templates select="body/text()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4[2] or preceding::h5 or preceding::h6)]|
400 body/comment()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4[2] or preceding::h5 or preceding::h6)]|
401 body/*[not(self::table or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or
402 preceding::table[parent::body] or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4[2] or preceding::h5 or preceding::h6)]"/>
403 </section>
404 </xsl:if>
405 <!-- Now turn any other headings into sections, with following stuff -->
406 <xsl:apply-templates select="body/table|body/h1|body/h2|body/h3|body/h4[preceding-sibling::h4]|body/h5|body/h6|body/h7" mode="create-section-with-following-content"/>
407 </xsl:when>
408 <xsl:when test="$main-head-level='h5'">
409 <!-- First process anything that comes before any subheadings, or a second h5 -->
410 <xsl:if test="body/text()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5[2] or preceding::h6)]|
411 body/comment()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5[2] or preceding::h6)]|
412 body/*[not(self::table or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or
413 preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5[2] or preceding::h6)]">
414 <section>
415 <xsl:apply-templates select="body/text()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5[2] or preceding::h6)]|
416 body/comment()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5[2] or preceding::h6)]|
417 body/*[not(self::table or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or
418 preceding::table[parent::body] or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5[2] or preceding::h6)]"/>
419 </section>
420 </xsl:if>
421 <!-- Now turn any other headings into sections, with following stuff -->
422 <xsl:apply-templates select="body/table|body/h1|body/h2|body/h3|body/h4|body/h5[preceding-sibling::h5]|body/h6|body/h7" mode="create-section-with-following-content"/>
423 </xsl:when>
424 <xsl:otherwise>
425 <!-- First process anything that comes before any subheadings, or a second heading -->
426 <xsl:if test="body/text()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6[2])]|
427 body/comment()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6[2])]|
428 body/*[not(self::table or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or
429 preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6[2])]">
430 <section>
431 <xsl:apply-templates select="body/text()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6[2])]|
432 body/comment()[not(preceding::table or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6[2])]|
433 body/*[not(self::table or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or
434 preceding::table[parent::body] or preceding::h1 or preceding::h2 or preceding::h3 or preceding::h4 or preceding::h5 or preceding::h6[2])]"/>
435 </section>
436 </xsl:if>
437 <!-- Now turn any other headings into sections, with following stuff -->
438 <xsl:apply-templates select="body/table|body/h1|body/h2|body/h3|body/h4|body/h5|body/h6[preceding-sibling::h6]|body/h7" mode="create-section-with-following-content"/>
439 </xsl:otherwise>
440 </xsl:choose>
441 </refbody>
442 <xsl:call-template name="genrellinks"/>
443 </reference>
444</xsl:template>
445
446
447<!-- Task topic template -->
448
449<xsl:template name="gen-task">
450 <task xml:lang="{$default-lang}">
451 <xsl:call-template name="genidattribute"/>
452 <xsl:call-template name="gentitle"/>
453 <xsl:call-template name="gentitlealts"/>
454 <xsl:call-template name="genprolog"/>
455 <taskbody>
456 <!--Optional prereq section goes here-->
457
458 <!--context [any child elements with no preceding ol]-->
459 <xsl:if test="body/text()[not(preceding-sibling::ol)]|body/comment()[not(preceding-sibling::ol)]|body/*[not(preceding-sibling::ol)][not(self::ol)]">
460 <context>
461 <xsl:apply-templates select="body/text()[not(preceding-sibling::ol)]|body/comment()[not(preceding-sibling::ol)]|body/*[not(preceding-sibling::ol)][not(self::ol)]"/>
462 </context>
463 </xsl:if>
464
465 <!--steps [first ol within a body = steps!] -->
466 <xsl:if test="body/ol">
467 <steps>
468 <xsl:apply-templates select="body/ol[1]/li|body/ol[1]/comment()" mode="steps"/>
469 </steps>
470 </xsl:if>
471
472 <!--result [any children with a preceding ol]-->
473 <xsl:if test="body/text()[preceding-sibling::ol]|body/comment()[preceding-sibling::ol]|body/*[preceding-sibling::ol]">
474 <result>
475 <xsl:apply-templates select="body/text()[preceding-sibling::ol]|body/comment()[preceding-sibling::ol]|body/*[preceding-sibling::ol]"/>
476 </result>
477 </xsl:if>
478
479 <!--Optional example section-->
480 <!--Optional postreq section-->
481
482 </taskbody>
483 <xsl:call-template name="genrellinks"/>
484 </task>
485</xsl:template>
486
487<!-- this template handle ol/li processing within a task -->
488<!-- The default behavior is to put each <li> into a <step>. If this is being
489 used to create substeps, the $steptype parameter is passed in as "substep".
490 If the <li> does not contain blocklike info, put everything in <cmd>. Otherwise,
491 put everything up to the first block into <cmd>. Everything from the first block
492 on will be placed in substeps (if it is an OL) or in <info> (everything else). -->
493<xsl:template match="li" mode="steps">
494 <xsl:param name="steptype">step</xsl:param>
495 <xsl:element name="{$steptype}">
496 <xsl:apply-templates select="@class"/>
497 <xsl:choose>
498 <xsl:when test="not(p|div|ol|ul|table|dl|pre)">
499 <cmd><xsl:apply-templates select="*|comment()|text()"/></cmd>
500 </xsl:when>
501 <xsl:otherwise>
502 <cmd><xsl:apply-templates select="(./*|./text())[1]" mode="step-cmd"/></cmd>
503 <xsl:apply-templates select="(p|div|ol|ul|table|dl|pre|comment())[1]" mode="step-child"/>
504 </xsl:otherwise>
505 </xsl:choose>
506 </xsl:element>
507</xsl:template>
508<xsl:template match="comment()" mode="steps">
509 <xsl:apply-templates select="."/>
510</xsl:template>
511
512<!-- Add content to a <cmd>. If this is block like, stop iterating and return to the li.
513 Otherwise, output the current node using normal processing, and move to the next
514 text or element node. -->
515<xsl:template match="p|div|ol|ul|table|dl|pre" mode="step-cmd"/>
516<xsl:template match="text()|*" mode="step-cmd">
517 <xsl:apply-templates select="."/>
518 <xsl:apply-templates select="(following-sibling::*|following-sibling::text())[1]" mode="step-cmd"/>
519</xsl:template>
520
521<!-- If an ol is inside a step, convert it to substeps. If it is inside substeps, put it in info.
522 For any other elements, create an info, and output the current node. Also output the
523 following text or element node, which will work up to any <ol>. -->
524<xsl:template match="ol" mode="step-child">
525 <xsl:choose>
526 <!-- If already in substeps -->
527 <xsl:when test="parent::li/parent::ol/parent::li/parent::ol">
528 <info><xsl:apply-templates select="."/></info>
529 </xsl:when>
530 <xsl:otherwise>
531 <substeps>
532 <xsl:apply-templates select="li" mode="steps">
533 <xsl:with-param name="steptype">substep</xsl:with-param>
534 </xsl:apply-templates>
535 </substeps>
536 </xsl:otherwise>
537 </xsl:choose>
538 <xsl:apply-templates select="(following-sibling::*|following-sibling::text())[1]" mode="step-child"/>
539</xsl:template>
540<xsl:template match="text()|*|comment()" mode="step-child">
541 <xsl:choose>
542 <xsl:when test="self::* or string-length(normalize-space(.))>0">
543 <info>
544 <xsl:apply-templates select="."/>
545 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="add-to-info"/>
546 </info>
547 </xsl:when>
548 <xsl:otherwise>
549 <!-- Ignore empty text nodes and empty comments, move on to the next node -->
550 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="step-child"/>
551 </xsl:otherwise>
552 </xsl:choose>
553 <xsl:apply-templates select="following-sibling::ol[1]" mode="step-child"/>
554</xsl:template>
555
556<!-- When adding to <info>, if an ol is found, stop: it will become substeps, or its own info.
557 Anything else: output the element, and then output the following text or element node,
558 remaining inside <info>. -->
559<xsl:template match="ol" mode="add-to-info"/>
560<xsl:template match="*|text()|comment()" mode="add-to-info">
561 <xsl:apply-templates select="."/>
562 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="add-to-info"/>
563</xsl:template>
564
565<!-- Support for generating contextually dependent ID for topics. -->
566<!-- This will need to be improved; no HTML will have an id, so only the
567 otherwise will trigger. Better test: use the filename or first a/@name
568 +-->
569<!-- NOTE: this is only to be used for the topic element -->
570<xsl:template name="genidattribute">
571 <xsl:attribute name="id">
572 <xsl:choose>
573 <xsl:when test="string-length($filename-id)>0"><xsl:value-of select="$filename-id"/></xsl:when>
574 <xsl:when test="/html/@id"><xsl:value-of select="/html/@id"/></xsl:when>
575 <xsl:otherwise><xsl:value-of select="generate-id(/html)"/></xsl:otherwise>
576 </xsl:choose>
577</xsl:attribute>
578</xsl:template>
579
580
581
582<!-- named templates for out of line pulls -->
583
584<!-- 02/12/03 drd: mp says to leave this as linklist, not linkpool, for now -->
585<xsl:template name="genrellinks">
586 <xsl:if test="$generateRelatedLinks">
587<xsl:if test=".//a[@href][not(starts-with(@href,'#'))]">
588<related-links>
589<linklist><title>Collected links</title>
590 <xsl:for-each select=".//a[@href][not(starts-with(@href,'#'))]">
591 <link>
592 <xsl:call-template name="genlinkattrs"/>
593 <linktext><xsl:value-of select="."/></linktext>
594 <xsl:if test="@title">
595 <desc><xsl:value-of select="normalize-space(@title)"/></desc>
596 </xsl:if>
597 </link>
598 </xsl:for-each>
599</linklist>
600</related-links>
601</xsl:if>
602 </xsl:if>
603</xsl:template>
604
605<xsl:template name="genlinkattrs">
606 <xsl:variable name="newfn">
607 <xsl:value-of select="substring-before(@href,'.htm')"/>
608 </xsl:variable>
609 <xsl:choose>
610 <!-- If the target is a web site, do not change extension to .dita -->
611 <xsl:when test="starts-with(@href,'http:') or starts-with(@href,'https:') or
612 starts-with(@href,'ftp:')">
613 <xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
614 <xsl:attribute name="scope">external</xsl:attribute>
615 <xsl:attribute name="format">
616 <xsl:choose>
617 <xsl:when test="contains(@href,'.pdf') or contains(@href,'.PDF')">pdf</xsl:when>
618 <xsl:otherwise>html</xsl:otherwise>
619 </xsl:choose>
620 </xsl:attribute>
621 </xsl:when>
622 <xsl:when test="string-length($newfn)>0">
623 <xsl:attribute name="href"><xsl:value-of select="$newfn"/><xsl:value-of select="$dita-extension"/></xsl:attribute>
624 </xsl:when>
625 <xsl:when test="starts-with(@href,'#')">
626 <xsl:variable name="infile-reference">
627 <xsl:text>#</xsl:text>
628 <!-- Need to udpate this if genidattribute changes -->
629 <xsl:choose>
630 <xsl:when test="string-length($filename-id)>0"><xsl:value-of select="$filename-id"/></xsl:when>
631 <xsl:when test="/html/@id"><xsl:value-of select="/html/@id"/></xsl:when>
632 <xsl:otherwise><xsl:value-of select="generate-id(/html)"/></xsl:otherwise>
633 </xsl:choose>
634 <xsl:text>/</xsl:text>
635 <xsl:value-of select="substring-after(@href,'#')"/>
636 </xsl:variable>
637 <!-- output-message? -->
638 <xsl:attribute name="href"><xsl:value-of select="$infile-reference"/></xsl:attribute>
639 </xsl:when>
640 <xsl:otherwise>
641 <xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
642 <xsl:attribute name="format">
643 <xsl:choose>
644 <xsl:when test="contains(@href,'.pdf') or contains(@href,'.PDF')">pdf</xsl:when>
645 <xsl:otherwise>html</xsl:otherwise> <!-- Default to html -->
646 </xsl:choose>
647 </xsl:attribute>
648 </xsl:otherwise>
649 </xsl:choose>
650 <xsl:if test="@target='_blank'">
651 <xsl:attribute name="scope">external</xsl:attribute>
652 </xsl:if>
653</xsl:template>
654
655<!-- gentitle was here -->
656
657<xsl:template name="genprolog">
658 <xsl:if test="$preserveMetadata">
659 <xsl:if test=".//meta[@name][not(@name='generator' or @name='GENERATOR')]|head/comment()"><!-- produce only if qualifiend meta is extant -->
660 <prolog>
661 <!--xsl:comment>author, copyright, critdates, permissions, publisher, source</xsl:comment-->
662 <metadata>
663 <xsl:apply-templates select="head/comment()"/>
664 <xsl:apply-templates select=".//meta[not(@name='generator' or @name='GENERATOR')]" mode="outofline"/>
665 </metadata>
666 </prolog>
667 </xsl:if>
668 </xsl:if>
669</xsl:template>
670
671
672
673<!-- TBD: do anything rational with scripts or styles in the head? elsewhere? -->
674<!-- 05232002 drd: null out scripts, flat out (script in head was nulled out before,
675 but scripts in body were coming through)
676-->
677<xsl:template match="script"/>
678<xsl:template match="style"/>
679
680
681<!-- take out some other interactive, non-content gadgets that are not part of the DITA source model -->
682<!-- TBD: consider adding messages within these -->
683<xsl:template match="textarea"/>
684<xsl:template match="input"/>
685<xsl:template match="isindex"/>
686<xsl:template match="select"/>
687<xsl:template match="optgroup"/>
688<xsl:template match="option"/>
689<xsl:template match="label"/>
690<xsl:template match="fieldset"/>
691<xsl:template match="basefont"/>
692<xsl:template match="col"/>
693<xsl:template match="colgroup"/>
694
695
696
697<!-- ========== Start of heading-aware code =============== -->
698
699
700<!-- Generic treatment for all headings (1-9!). The main title and section level code -->
701<!-- have higher priorities that override getting triggered by this generic rule. -->
702
703<xsl:template name="cleanup-heading">
704 <xsl:call-template name="output-message">
705 <xsl:with-param name="msg">A <xsl:value-of select="name()"/> heading could not be converted into DITA.
706The heading has been placed in a required-cleanup element.</xsl:with-param>
707 </xsl:call-template>
708 <xsl:variable name="content">
709 <p>
710 <xsl:if test="$generateRequiredCleanup">
711 <b>[deprecated heading <xsl:value-of select="name()"/> ]: </b>
712 </xsl:if>
713 <xsl:apply-templates select="*|comment()|text()"/>
714 </p>
715 </xsl:variable>
716 <xsl:choose>
717 <xsl:when test="$generateRequiredCleanup">
718 <required-cleanup>
719 <xsl:copy-of select="$content"/>
720 </required-cleanup>
721 </xsl:when>
722 <xsl:otherwise>
723 <xsl:copy-of select="$content"/>
724 </xsl:otherwise>
725 </xsl:choose>
726</xsl:template>
727
728<xsl:template match="h1" priority="5">
729 <xsl:choose>
730 <xsl:when test="not(preceding::h1)"/>
731 <xsl:when test="$infotype='task'"><xsl:call-template name="cleanup-heading"/></xsl:when>
732 <xsl:when test="$main-head-level='h1'"><xsl:call-template name="gensection"/></xsl:when>
733 <xsl:otherwise><xsl:call-template name="cleanup-heading"/></xsl:otherwise>
734 </xsl:choose>
735</xsl:template>
736<xsl:template match="h2" priority="5">
737 <xsl:choose>
738 <xsl:when test="$main-head-level='h2' and not(preceding::h2)"/>
739 <xsl:when test="$infotype='task'"><xsl:call-template name="cleanup-heading"/></xsl:when>
740 <xsl:when test="$main-head-level='h1' or $main-head-level='h2'"><xsl:call-template name="gensection"/></xsl:when>
741 <xsl:otherwise><xsl:call-template name="cleanup-heading"/></xsl:otherwise>
742 </xsl:choose>
743</xsl:template>
744<xsl:template match="h3" priority="5">
745 <xsl:choose>
746 <xsl:when test="$main-head-level='h3' and not(preceding::h3)"/>
747 <xsl:when test="$infotype='task'"><xsl:call-template name="cleanup-heading"/></xsl:when>
748 <xsl:when test="$main-head-level='h2' or $main-head-level='h3'"><xsl:call-template name="gensection"/></xsl:when>
749 <xsl:otherwise><xsl:call-template name="cleanup-heading"/></xsl:otherwise>
750 </xsl:choose>
751</xsl:template>
752<xsl:template match="h4" priority="5">
753 <xsl:choose>
754 <xsl:when test="$main-head-level='h4' and not(preceding::h4)"/>
755 <xsl:when test="$infotype='task'"><xsl:call-template name="cleanup-heading"/></xsl:when>
756 <xsl:when test="$main-head-level='h3' or $main-head-level='h4'"><xsl:call-template name="gensection"/></xsl:when>
757 <xsl:otherwise><xsl:call-template name="cleanup-heading"/></xsl:otherwise>
758 </xsl:choose>
759</xsl:template>
760<xsl:template match="h5" priority="5">
761 <xsl:choose>
762 <xsl:when test="$main-head-level='h5' and not(preceding::h5)"/>
763 <xsl:when test="$infotype='task'"><xsl:call-template name="cleanup-heading"/></xsl:when>
764 <xsl:when test="$main-head-level='h4' or $main-head-level='h5'"><xsl:call-template name="gensection"/></xsl:when>
765 <xsl:otherwise><xsl:call-template name="cleanup-heading"/></xsl:otherwise>
766 </xsl:choose>
767</xsl:template>
768<xsl:template match="h6" priority="5">
769 <xsl:choose>
770 <xsl:when test="$main-head-level='h6' and not(preceding::h6)"/>
771 <xsl:when test="$infotype='task'"><xsl:call-template name="cleanup-heading"/></xsl:when>
772 <xsl:when test="$main-head-level='h5' or $main-head-level='h6'"><xsl:call-template name="gensection"/></xsl:when>
773 <xsl:otherwise><xsl:call-template name="cleanup-heading"/></xsl:otherwise>
774 </xsl:choose>
775</xsl:template>
776<xsl:template match="h7" priority="5">
777 <xsl:choose>
778 <xsl:when test="$main-head-level='h6'"><xsl:call-template name="gensection"/></xsl:when>
779 <xsl:otherwise><xsl:call-template name="cleanup-heading"/></xsl:otherwise>
780 </xsl:choose>
781</xsl:template>
782<xsl:template match="h8|h9">
783 <xsl:call-template name="cleanup-heading"/>
784</xsl:template>
785
786<!-- Templates used to pull content following headings into the generated section -->
787<xsl:template match="h1|h2|h3|h4|h5|h6|h7" mode="add-content-to-section"/>
788<xsl:template match="*|text()|comment()" mode="add-content-to-section">
789 <xsl:choose>
790 <!-- For reference, tables also create a section, so leave them out. Otherwise, they go inside sections. -->
791 <xsl:when test="self::table and $infotype='reference'"/>
792 <xsl:otherwise>
793 <xsl:apply-templates select="."/>
794 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="add-content-to-section"/>
795 </xsl:otherwise>
796 </xsl:choose>
797</xsl:template>
798
799<xsl:template name="convert-heading-to-section">
800 <section>
801 <title><xsl:apply-templates select="@class"/><xsl:apply-templates select="*|comment()|text()"/></title>
802 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="add-content-to-section"/>
803 </section>
804</xsl:template>
805<xsl:template match="h1|h2|h3|h4|h5|h6|h7" mode="create-section-with-following-content">
806 <xsl:choose>
807 <xsl:when test="$main-head-level='h1' and (self::h1 or self::h2)">
808 <xsl:call-template name="convert-heading-to-section"/>
809 </xsl:when>
810 <xsl:when test="$main-head-level='h2' and (self::h2 or self::h3)">
811 <xsl:call-template name="convert-heading-to-section"/>
812 </xsl:when>
813 <xsl:when test="$main-head-level='h3' and (self::h3 or self::h4)">
814 <xsl:call-template name="convert-heading-to-section"/>
815 </xsl:when>
816 <xsl:when test="$main-head-level='h4' and (self::h4 or self::h5)">
817 <xsl:call-template name="convert-heading-to-section"/>
818 </xsl:when>
819 <xsl:when test="$main-head-level='h5' and (self::h5 or self::h6)">
820 <xsl:call-template name="convert-heading-to-section"/>
821 </xsl:when>
822 <xsl:when test="$main-head-level='h6' and (self::h6 or self::h7)">
823 <xsl:call-template name="convert-heading-to-section"/>
824 </xsl:when>
825 <xsl:otherwise>
826 <xsl:call-template name="output-message">
827 <xsl:with-param name="msg">A <xsl:value-of select="name()"/> heading could not be converted into DITA.
828The heading has been placed in a required-cleanup element.</xsl:with-param>
829 </xsl:call-template>
830 <section>
831 <xsl:variable name="content">
832 <title><xsl:apply-templates select="@class"/><xsl:apply-templates select="*|text()|comment()"/></title>
833 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="add-content-to-section"/>
834 </xsl:variable>
835 <xsl:choose>
836 <xsl:when test="$generateRequiredCleanup">
837 <required-cleanup>
838 <xsl:copy-of select="$content"/>
839 </required-cleanup>
840 </xsl:when>
841 <xsl:otherwise>
842 <xsl:copy-of select="$content"/>
843 </xsl:otherwise>
844 </xsl:choose>
845 </section>
846 </xsl:otherwise>
847 </xsl:choose>
848</xsl:template>
849<!-- The next template can only be called when processing items in the reference body -->
850<xsl:template match="table" mode="create-section-with-following-content">
851 <xsl:apply-templates select="."/>
852 <xsl:if test="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1][not(self::table or self::h2 or self::h3 or self::h4 or self::h5 or self::h6 or self::h7)]">
853 <section>
854 <xsl:apply-templates select="(following-sibling::*|following-sibling::text()|following-sibling::comment())[1]" mode="add-content-to-section"/>
855 </section>
856 </xsl:if>
857</xsl:template>
858
859<!-- Special treatment for headings that occur at a section level -->
860<xsl:template name="gensection">
861 <section>
862 <xsl:variable name="hcnt"><xsl:number/></xsl:variable>
863 <!--<xsl:value-of select="$hcnt"/>-->
864 <title><xsl:apply-templates select="@class"/><xsl:apply-templates select="*|text()|comment()"/></title>
865 <!-- call recursively for subsequent chunks -->
866 <xsl:call-template name="output-message">
867 <xsl:with-param name="msg">A <xsl:value-of select="name()"/> heading was mapped to an empty section.
868Move any content that belongs with that heading into the section.</xsl:with-param>
869 </xsl:call-template>
870 </section>
871</xsl:template>
872
873
874<!-- ========== Start of overrideable heading level code =============== -->
875
876<!-- Default: h1=topic title; h2=section title; all others=bold text -->
877<!-- For plain text pull (no problems with content in headings!), use xsl:value-of -->
878<!-- (ie, if you use xsl:apply-templates select, you might get unwanted elements in title) -->
879<!-- These templates will be overridden by heading-level aware front ends -->
880<!-- Note: The generic heading processor treats all headings as priority=1;
881 priority=2 in this master transform will override the generic heading processor
882 priority=3 in the overrides will override this h1/h2 default setup
883 +-->
884
885
886<!-- === initially define the defaults for h1/h2 topic/section mappings === -->
887
888<xsl:template name="gentitle">
889 <title>
890 <xsl:choose>
891 <xsl:when test="$main-head-level='h1'"><xsl:value-of select=".//h1[1]"/></xsl:when>
892 <xsl:when test="$main-head-level='h2'"><xsl:value-of select=".//h2[1]"/></xsl:when>
893 <xsl:when test="$main-head-level='h3'"><xsl:value-of select=".//h3[1]"/></xsl:when>
894 <xsl:when test="$main-head-level='h4'"><xsl:value-of select=".//h4[1]"/></xsl:when>
895 <xsl:when test="$main-head-level='h5'"><xsl:value-of select=".//h5[1]"/></xsl:when>
896 <xsl:when test="$main-head-level='h6'"><xsl:value-of select=".//h6[1]"/></xsl:when>
897 </xsl:choose>
898 </title>
899</xsl:template>
900
901<xsl:template name="gentitlealts">
902 <xsl:variable name="create-searchtitle">
903 <xsl:choose>
904 <xsl:when test="not(/html/head/title)">NO</xsl:when>
905 <xsl:when test="$main-head-level='h1' and normalize-space(string(//h1[1]))=normalize-space(string(/html/head/title))">NO</xsl:when>
906 <xsl:when test="$main-head-level='h2' and normalize-space(string(//h2[1]))=normalize-space(string(/html/head/title))">NO</xsl:when>
907 <xsl:when test="$main-head-level='h3' and normalize-space(string(//h3[1]))=normalize-space(string(/html/head/title))">NO</xsl:when>
908 <xsl:when test="$main-head-level='h4' and normalize-space(string(//h4[1]))=normalize-space(string(/html/head/title))">NO</xsl:when>
909 <xsl:when test="$main-head-level='h5' and normalize-space(string(//h5[1]))=normalize-space(string(/html/head/title))">NO</xsl:when>
910 <xsl:when test="$main-head-level='h6' and normalize-space(string(//h6[1]))=normalize-space(string(/html/head/title))">NO</xsl:when>
911 <xsl:otherwise>YES</xsl:otherwise>
912 </xsl:choose>
913 </xsl:variable>
914 <xsl:if test="$create-searchtitle='YES'">
915 <titlealts>
916 <searchtitle>
917 <xsl:value-of select="/html/head/title"/>
918 </searchtitle>
919 </titlealts>
920 </xsl:if>
921</xsl:template>
922
923<!-- null out some things pulled later -->
924<!--<xsl:template match="h1" priority="2"/>
925
926<xsl:template match="h2" priority="2">
927 <xsl:call-template name="gensection"/>
928</xsl:template> -->
929
930<!-- ========== End of overrideable heading level code =============== -->
931
932
933
934<!-- null out some things pulled later -->
935<xsl:template match="head"/>
936<xsl:template match="title"/>
937
938<!-- Clear up faux "related-links" that are already pulled into collected links:
939 eg, template match="br-with-nothing but imgs, links, and brs after it"-->
940<!-- These rules attempt to leave behind any images or links that are part of a
941 discourse context, and use the rule "br followed by image or anchor" as what
942 to interpret as a hand-built "related links" construct. -->
943<!-- 03/28/2003: Moved <br> processing into a single "br" template -->
944<!-- 03/28/2003: Removal of <a> does not work, because body overrides; move into
945 "a" template for now, though it does not work well -->
946
947<!--eliminate a br following an img or an a element -->
948<!-- <xsl:template match="*[self::br][following-sibling::*[1][self::img|self::a]]"/> -->
949<!--eliminate an a-link preceded by a br-->
950<!-- <xsl:template match="a[@href][preceding-sibling::br]"/> -->
951<!--eliminate an img preceded by a br-->
952<!-- <xsl:template match="img[preceding-sibling::br]"/> -->
953<!--eliminate a final br in a context (usually just for vertical space)-->
954<!-- <xsl:template match="br[name(following-sibling::*)='']"/> -->
955
956<!-- body: fall through, since its contexts (refbody, conbody, etc.) will be
957 generated by templates above -->
958
959<xsl:template match="body">
960 <xsl:apply-templates/>
961</xsl:template>
962
963
964<!-- divs: if we can base transform on a class, do so. -->
965<!-- generic divs will fall through with no associated transform -->
966
967<xsl:template match="div">
968 <xsl:apply-templates select="*|text()|comment()"/>
969</xsl:template>
970
971
972<!-- some characteristics of HTML coming from DocBook tools -->
973<xsl:template match="div[@class='footnote']">
974<lq>
975 <xsl:if test="@id"><xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute></xsl:if>
976 <xsl:apply-templates select="*|text()|comment()"/>
977</lq>
978</xsl:template>
979
980<!-- this comes from IDWB XHTML output... content that replicates existing structure, therefore null out -->
981<xsl:template match="div[@class='toc']">
982</xsl:template>
983
984
985<!-- map these common elements straight through -->
986<xsl:template match="cite|p|dl|ol|ul|li|pre|sub|sup|b|u|i">
987<xsl:variable name="giname"><xsl:value-of select="name()"/></xsl:variable>
988<xsl:variable name="outgi"><xsl:value-of select="translate($giname,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/></xsl:variable>
989<xsl:element name="{$outgi}">
990 <xsl:if test="@compact and (self::ol|self::ul|self::dl)">
991 <xsl:attribute name="compact">yes</xsl:attribute>
992 </xsl:if>
993 <xsl:apply-templates select="@class"/>
994 <xsl:apply-templates select="*|text()|comment()"/>
995</xsl:element>
996</xsl:template>
997<!-- @outputclass is not allowed on these in DITA, so do not process @class-->
998<!-- @outputclass is now allowed, so move these back into the rule above -->
999<!--<xsl:template match="b|u|i">
1000<xsl:variable name="giname"><xsl:value-of select="name()"/></xsl:variable>
1001<xsl:variable name="outgi"><xsl:value-of select="translate($giname,'BITU','bitu')"/></xsl:variable>
1002<xsl:element name="{$outgi}">
1003 <xsl:apply-templates select="*|text()|comment()"/>
1004</xsl:element>
1005</xsl:template>-->
1006
1007<xsl:template match="@class">
1008 <xsl:attribute name="outputclass"><xsl:value-of select="."/></xsl:attribute>
1009</xsl:template>
1010
1011<!-- empty elements -->
1012
1013<!-- This template will return true() if there is nothing left in this topic except
1014 a series of related links. Those links will be gathered in the <related-links> section.
1015 If this is in the related links, return true(). Otherwise, return false().
1016 The tests are:
1017 If not a child of body, return false (keep this in output)
1018 If there are text nodes following, return false
1019 If there are no nodes following, return true (part of the links, so drop it)
1020 If there are following elements OTHER than br or a, return false
1021 Otherwise, this is a br or a at the end -->
1022<xsl:template name="only-related-links-remain">
1023 <xsl:choose>
1024 <xsl:when test="not(parent::body)">false</xsl:when>
1025 <xsl:when test="following-sibling::text()">false</xsl:when>
1026 <xsl:when test="not(following-sibling::*)">true</xsl:when>
1027 <xsl:when test="following-sibling::*[not(self::br or self::a)]">false</xsl:when>
1028 <xsl:otherwise>true</xsl:otherwise>
1029 </xsl:choose>
1030</xsl:template>
1031
1032<xsl:template match="br">
1033 <xsl:variable name="skip-related-links">
1034 <xsl:call-template name="only-related-links-remain"/>
1035 </xsl:variable>
1036 <xsl:choose>
1037 <xsl:when test="$skip-related-links='true'"/>
1038 <xsl:when test="following-sibling::*[1][self::img]/following-sibling::*[1][self::br]"/>
1039 <xsl:when test="preceding-sibling::*[1][self::img]/preceding-sibling::*[1][self::br]"/>
1040 <xsl:when test="following-sibling::text()|following-sibling::*[not(self::a)]">
1041 <xsl:call-template name="output-message">
1042 <xsl:with-param name="msg">CLEANUP ACTION: Determine the original intent for a BR tag.</xsl:with-param>
1043 </xsl:call-template>
1044 <xsl:comment>A BR tag was used here in the original source.</xsl:comment>
1045 </xsl:when>
1046 <xsl:otherwise/> <!-- Skip br if it ends a section, or only has links following -->
1047 </xsl:choose>
1048</xsl:template>
1049
1050
1051<xsl:template match="meta[@name]" mode="outofline">
1052 <othermeta name="{@name}" content="{@content}"/>
1053</xsl:template>
1054
1055<xsl:template match="img[@usemap][@src]">
1056 <xsl:variable name="mapid"><xsl:value-of select="substring-after(@usemap,'#')"/></xsl:variable>
1057 <imagemap>
1058 <xsl:apply-templates select="@class"/>
1059 <image href="{@src}">
1060 <xsl:apply-templates select="@alt"/>
1061 </image>
1062 <xsl:apply-templates select="//map[@id=$mapid or @name=$mapid]" mode="usemap"/>
1063 </imagemap>
1064</xsl:template>
1065
1066<xsl:template match="map"/>
1067<xsl:template match="map" mode="usemap">
1068 <xsl:apply-templates/>
1069</xsl:template>
1070<xsl:template match="area">
1071 <area>
1072 <shape><xsl:value-of select="@shape"/></shape>
1073 <coords><xsl:value-of select="@coords"/></coords>
1074 <xref>
1075 <xsl:call-template name="genlinkattrs"/>
1076 <xsl:value-of select="@alt"/>
1077 </xref>
1078 </area>
1079</xsl:template>
1080
1081<xsl:template match="img">
1082 <image href="{@src}">
1083 <!-- 03/28/2003 RDA: inline is default, so only worry about break -->
1084 <!-- <xsl:if test="name(parent::*)='p'"><xsl:attribute name="placement">inline</xsl:attribute></xsl:if>
1085 <xsl:if test="name(parent::*)='li'"><xsl:attribute name="placement">inline</xsl:attribute></xsl:if> -->
1086 <xsl:if test="preceding-sibling::*[1][self::br]|following-sibling::*[1][self::br]">
1087 <xsl:attribute name="placement">break</xsl:attribute>
1088 </xsl:if>
1089 <xsl:apply-templates select="@class"/>
1090 <xsl:apply-templates select="@alt"/>
1091 </image>
1092</xsl:template>
1093
1094<xsl:template match="img/@alt">
1095 <alt><xsl:value-of select="."/></alt>
1096</xsl:template>
1097
1098<xsl:template match="hr">
1099<xsl:comment> ===================== horizontal rule ===================== </xsl:comment>
1100</xsl:template>
1101
1102
1103<!-- renames -->
1104
1105<xsl:template match="code">
1106 <codeph><xsl:apply-templates select="@class|*|text()|comment()"/></codeph>
1107</xsl:template>
1108
1109<xsl:template match="var">
1110 <varname><xsl:apply-templates select="@class"/><xsl:value-of select="."/></varname>
1111</xsl:template>
1112
1113<xsl:template match="samp">
1114 <systemoutput><xsl:apply-templates select="@class|*|text()|comment()"/></systemoutput>
1115</xsl:template>
1116
1117<xsl:template match="kbd">
1118 <userinput><xsl:apply-templates select="@class|*|text()|comment()"/></userinput>
1119</xsl:template>
1120
1121
1122<xsl:template match="em">
1123 <i><xsl:apply-templates select="@class|*|text()|comment()"/></i>
1124</xsl:template>
1125
1126<xsl:template match="strong">
1127 <b><xsl:apply-templates select="@class|*|text()|comment()"/></b>
1128</xsl:template>
1129
1130<xsl:template match="blockquote">
1131 <lq><xsl:apply-templates select="@class|*|text()|comment()"/></lq>
1132</xsl:template>
1133
1134<!-- <lq> in <lq> is invalid in DITA, so make it valid (though it is a bit strange) -->
1135<xsl:template match="blockquote/blockquote">
1136 <p><lq><xsl:apply-templates select="@class|*|text()|comment()"/></lq></p>
1137</xsl:template>
1138
1139<xsl:template match="pre" priority="3">
1140 <codeblock><xsl:apply-templates select="@class|*|text()|comment()"/></codeblock>
1141</xsl:template>
1142
1143<!-- assume that these elements are used in tech docs with a semantic intent... -->
1144<xsl:template match="tt">
1145 <codeph><xsl:apply-templates select="@class|*|text()|comment()"/></codeph>
1146</xsl:template>
1147
1148<xsl:template match="i" priority="3">
1149 <varname><xsl:apply-templates select="@class"/><xsl:value-of select="."/></varname>
1150</xsl:template>
1151
1152
1153<!-- Linking -->
1154
1155<!-- May try to eliminate groups of related links at the end; if there is a <br>
1156 followed only by links, ignore them, and let the Collected Links get them.
1157 Doesn't work now: if a title is entirely a link, it's the last link, so it's ignored... -->
1158<xsl:template match="a">
1159 <xsl:variable name="skip-related-links">
1160 <xsl:call-template name="only-related-links-remain"/>
1161 </xsl:variable>
1162 <xsl:choose>
1163 <xsl:when test="@name and $skip-related-links!='true'">
1164 <xsl:comment>Removed anchor point <xsl:value-of select="@name"/></xsl:comment>
1165 </xsl:when>
1166 <xsl:when test="@id and $skip-related-links!='true'">
1167 <xsl:comment>Removed anchor point <xsl:value-of select="@id"/></xsl:comment>
1168 </xsl:when>
1169 </xsl:choose>
1170 <xsl:choose>
1171 <xsl:when test="$skip-related-links='true'"/>
1172 <!-- If a heading is a link, do not create an XREF or it will be out of context -->
1173 <xsl:when test="parent::h1|parent::h2|parent::h3|parent::h4|parent::h5|parent::h6|parent::h7">
1174 <xsl:apply-templates/>
1175 </xsl:when>
1176 <xsl:otherwise>
1177 <xsl:choose>
1178 <xsl:when test="@href and parent::body">
1179 <p><xref>
1180 <xsl:call-template name="genlinkattrs"/>
1181 <xsl:apply-templates select="@class"/>
1182 <xsl:apply-templates select="*|text()|comment()"/>
1183 </xref></p>
1184 </xsl:when>
1185 <xsl:when test="@href">
1186 <xref>
1187 <xsl:call-template name="genlinkattrs"/>
1188 <xsl:apply-templates select="@class"/>
1189 <xsl:apply-templates select="*|text()|comment()"/>
1190 </xref>
1191 </xsl:when>
1192 <xsl:when test="parent::body and text()">
1193 <p><xsl:apply-templates select="@class"/><xsl:apply-templates select="*|text()|comment()"/></p>
1194 </xsl:when>
1195 <xsl:otherwise>
1196 <xsl:apply-templates select="*|text()|comment()"/>
1197 </xsl:otherwise>
1198 </xsl:choose>
1199 </xsl:otherwise>
1200 </xsl:choose>
1201</xsl:template>
1202
1203
1204<!-- HTML table to CALS table -->
1205
1206<xsl:template match="td|th" mode="count-cols">
1207 <xsl:param name="current-count">1</xsl:param>
1208 <xsl:variable name="current-span">
1209 <xsl:choose>
1210 <xsl:when test="@colspan"><xsl:value-of select="@colspan"/></xsl:when>
1211 <xsl:otherwise>1</xsl:otherwise>
1212 </xsl:choose>
1213 </xsl:variable>
1214 <xsl:choose>
1215 <xsl:when test="following-sibling::th or following-sibling::td">
1216 <xsl:apply-templates select="(following-sibling::th|following-sibling::td)[1]" mode="count-cols">
1217 <xsl:with-param name="current-count"><xsl:value-of select="number($current-span) + number($current-count)"/></xsl:with-param>
1218 </xsl:apply-templates>
1219 </xsl:when>
1220 <xsl:when test="@colspan">
1221 <xsl:value-of select="number($current-span) + number($current-count) - 1"/>
1222 </xsl:when>
1223 <xsl:otherwise>
1224 <xsl:value-of select="$current-count"/>
1225 </xsl:otherwise>
1226 </xsl:choose>
1227</xsl:template>
1228
1229
1230<xsl:template match="table">
1231<xsl:variable name="cols-in-first-row">
1232 <xsl:choose>
1233 <xsl:when test="tbody/tr">
1234 <xsl:apply-templates select="(tbody[1]/tr[1]/td[1]|tbody[1]/tr[1]/th[1])[1]" mode="count-cols"/>
1235 </xsl:when>
1236 <xsl:otherwise>
1237 <xsl:apply-templates select="(tr[1]/td[1]|tr[1]/th[1])[1]" mode="count-cols"/>
1238 </xsl:otherwise>
1239 </xsl:choose>
1240</xsl:variable>
1241<xsl:variable name="width">
1242 <xsl:if test="@width"><xsl:value-of select="substring-before(@width,'%')"/></xsl:if>
1243</xsl:variable>
1244<xsl:if test="@summary and not(@summary='')">
1245 <xsl:comment><xsl:value-of select="@summary"/></xsl:comment>
1246 <xsl:call-template name="output-message">
1247 <xsl:with-param name="msg">The summary attribute on tables cannot be converted to DITA.
1248The attribute's contents were placed in a comment before the table.</xsl:with-param>
1249 </xsl:call-template>
1250</xsl:if>
1251<table>
1252 <xsl:apply-templates select="@class"/>
1253 <xsl:if test="@align"><xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute></xsl:if>
1254 <xsl:choose>
1255 <xsl:when test="number($width) &lt; 100"><xsl:attribute name="pgwide">0</xsl:attribute></xsl:when>
1256 <xsl:when test="string-length($width)"><xsl:attribute name="pgwide">1</xsl:attribute></xsl:when>
1257 </xsl:choose>
1258 <xsl:choose>
1259 <xsl:when test="@rules='none' and @border='0'">
1260 <xsl:attribute name="frame">none</xsl:attribute>
1261 <xsl:attribute name="rowsep">0</xsl:attribute>
1262 <xsl:attribute name="colsep">0</xsl:attribute>
1263 </xsl:when>
1264 <xsl:when test="@border='0'">
1265 <xsl:attribute name="rowsep">0</xsl:attribute>
1266 <xsl:attribute name="colsep">0</xsl:attribute>
1267 </xsl:when>
1268 <xsl:when test="@rules='cols'">
1269 <xsl:attribute name="rowsep">0</xsl:attribute>
1270 </xsl:when>
1271 <xsl:when test="@rules='rows'">
1272 <xsl:attribute name="colsep">0</xsl:attribute>
1273 </xsl:when>
1274 </xsl:choose>
1275 <xsl:choose>
1276 <xsl:when test="@frame='void'"><xsl:attribute name="frame">none</xsl:attribute></xsl:when>
1277 <xsl:when test="@frame='above'"><xsl:attribute name="frame">top</xsl:attribute></xsl:when>
1278 <xsl:when test="@frame='below'"><xsl:attribute name="frame">bottom</xsl:attribute></xsl:when>
1279 <xsl:when test="@frame='border'"><xsl:attribute name="frame">all</xsl:attribute></xsl:when>
1280 <xsl:when test="@frame='box'"><xsl:attribute name="frame">all</xsl:attribute></xsl:when>
1281 <xsl:when test="@frame='hsides'"><xsl:attribute name="frame">topbot</xsl:attribute></xsl:when>
1282 <xsl:when test="@frame='lhs'"><xsl:attribute name="frame">sides</xsl:attribute></xsl:when>
1283 <xsl:when test="@frame='rhs'"><xsl:attribute name="frame">sides</xsl:attribute></xsl:when>
1284 <xsl:when test="@frame='vsides'"><xsl:attribute name="frame">sides</xsl:attribute></xsl:when>
1285 </xsl:choose>
1286
1287 <xsl:apply-templates select="caption"/>
1288<tgroup>
1289<!-- add colspan data here -->
1290<xsl:attribute name="cols"><xsl:value-of select="$cols-in-first-row"/></xsl:attribute>
1291<xsl:call-template name="create-colspec">
1292 <xsl:with-param name="total-cols"><xsl:value-of select="$cols-in-first-row"/></xsl:with-param>
1293</xsl:call-template>
1294<xsl:choose>
1295 <xsl:when test="thead">
1296 <thead><xsl:apply-templates select="thead/tr"/></thead>
1297 </xsl:when>
1298 <xsl:when test="tr[th and not(td)]">
1299 <thead><xsl:apply-templates select="tr[th and not(td)]">
1300 <!--ideally, do for-each only for rows that contain TH, and place within THEAD;
1301 then open up the TBODY for the rest of the rows -->
1302 <!-- unforch, all the data will go into one place for now -->
1303 </xsl:apply-templates></thead>
1304 </xsl:when>
1305</xsl:choose>
1306<tbody>
1307 <xsl:apply-templates select="tbody/tr[*]|tr[td]"/>
1308</tbody></tgroup></table>
1309</xsl:template>
1310
1311<xsl:template name="create-colspec">
1312 <xsl:param name="total-cols">0</xsl:param>
1313 <xsl:param name="on-column">1</xsl:param>
1314 <xsl:if test="$on-column &lt;= $total-cols">
1315 <colspec>
1316 <xsl:attribute name="colname">col<xsl:value-of select="$on-column"/></xsl:attribute>
1317 <xsl:if test="@align"><xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute></xsl:if>
1318 </colspec>
1319 <xsl:call-template name="create-colspec">
1320 <xsl:with-param name="total-cols"><xsl:value-of select="$total-cols"/></xsl:with-param>
1321 <xsl:with-param name="on-column"><xsl:value-of select="$on-column + 1"/></xsl:with-param>
1322 </xsl:call-template>
1323 </xsl:if>
1324</xsl:template>
1325
1326<xsl:template match="table/caption">
1327 <title><xsl:apply-templates select="@class|*|text()|comment()"/></title>
1328</xsl:template>
1329
1330<xsl:template match="tr">
1331<row>
1332 <xsl:if test="@valign"><xsl:attribute name="valign"><xsl:value-of select="@valign"/></xsl:attribute></xsl:if>
1333 <xsl:apply-templates select="@class"/>
1334 <xsl:apply-templates/>
1335</row>
1336</xsl:template>
1337
1338<xsl:template match="td|th">
1339<entry>
1340 <xsl:if test="@rowspan">
1341 <xsl:attribute name="morerows"><xsl:value-of select="number(@rowspan)-1"/></xsl:attribute>
1342 </xsl:if>
1343 <xsl:if test="@colspan"> <!-- Allow entries to span columns -->
1344 <xsl:variable name="current-cell"><xsl:call-template name="current-cell-position"/></xsl:variable>
1345 <xsl:attribute name="namest">col<xsl:value-of select="$current-cell"/></xsl:attribute>
1346 <xsl:attribute name="nameend">col<xsl:value-of select="$current-cell + number(@colspan) - 1"/></xsl:attribute>
1347 </xsl:if>
1348 <xsl:choose>
1349 <xsl:when test="@align"><xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute></xsl:when>
1350 <xsl:when test="../@align"><xsl:attribute name="align"><xsl:value-of select="../@align"/></xsl:attribute></xsl:when>
1351 </xsl:choose>
1352 <xsl:apply-templates select="@class"/>
1353 <xsl:choose>
1354 <xsl:when test="table"><p><xsl:apply-templates select="*|text()|comment()"/></p></xsl:when>
1355 <xsl:otherwise><xsl:apply-templates select="*|text()|comment()"/></xsl:otherwise>
1356 </xsl:choose>
1357</entry>
1358</xsl:template>
1359
1360<!-- Determine which column the current entry sits in. Count the current entry,
1361 plus every entry before it; take spanned rows and columns into account.
1362 If any entries in this table span rows, we must examine the entire table to
1363 be sure of the current column. Use mode="find-matrix-column".
1364 Otherwise, we just need to examine the current row. Use mode="count-cells". -->
1365<xsl:template name="current-cell-position">
1366 <xsl:choose>
1367 <xsl:when test="parent::tr/parent::thead">
1368 <xsl:apply-templates select="(ancestor::table[1]/thead/tr/*[1])[1]"
1369 mode="find-matrix-column">
1370 <xsl:with-param name="stop-id"><xsl:value-of select="generate-id(.)"/></xsl:with-param>
1371 </xsl:apply-templates>
1372 </xsl:when>
1373 <xsl:when test="ancestor::table[1]//*[@rowspan][1]">
1374 <xsl:apply-templates select="(ancestor::table[1]/tbody/tr/*[1]|ancestor::table[1]/tr/*[1])[1]"
1375 mode="find-matrix-column">
1376 <xsl:with-param name="stop-id"><xsl:value-of select="generate-id(.)"/></xsl:with-param>
1377 </xsl:apply-templates>
1378 </xsl:when>
1379 <xsl:when test="not(preceding-sibling::td|preceding-sibling::th)">1</xsl:when>
1380 <xsl:otherwise>
1381 <xsl:apply-templates select="(preceding-sibling::th|preceding-sibling::td)[last()]" mode="count-cells"/>
1382 </xsl:otherwise>
1383 </xsl:choose>
1384</xsl:template>
1385
1386<!-- Count the number of cells in the current row. Move backwards from the test cell. Add one
1387 for each entry, plus the number of spanned columns. -->
1388<xsl:template match="*" mode="count-cells">
1389 <xsl:param name="current-count">1</xsl:param>
1390 <xsl:variable name="new-count">
1391 <xsl:choose>
1392 <xsl:when test="@colspan"><xsl:value-of select="$current-count + number(@colspan)"/></xsl:when>
1393 <xsl:otherwise><xsl:value-of select="$current-count + 1"/></xsl:otherwise>
1394 </xsl:choose>
1395 </xsl:variable>
1396 <xsl:choose>
1397 <xsl:when test="not(preceding-sibling::td|preceding-sibling::th)"><xsl:value-of select="$new-count"/></xsl:when>
1398 <xsl:otherwise>
1399 <xsl:apply-templates select="(preceding-sibling::th|preceding-sibling::td)[last()]" mode="count-cells">
1400 <xsl:with-param name="current-count"><xsl:value-of select="$new-count"/></xsl:with-param>
1401 </xsl:apply-templates>
1402 </xsl:otherwise>
1403 </xsl:choose>
1404</xsl:template>
1405
1406<!-- Set up a pseudo-matrix to find the column of the current entry. Start with the first entry
1407 in the first row. Progress to the end of the row, then start the next row; go until we find
1408 the test cell (with id=$stop-id).
1409 If an entry spans rows, add the cells that will be covered to $matrix.
1410 If we get to an entry and its position is already filled in $matrix, then the entry is pushed
1411 to the side. Add one to the column count and re-try the entry. -->
1412<xsl:template match="*" mode="find-matrix-column">
1413 <xsl:param name="stop-id"/>
1414 <xsl:param name="matrix"/>
1415 <xsl:param name="row-count">1</xsl:param>
1416 <xsl:param name="col-count">1</xsl:param>
1417 <!-- $current-position has the format [1:3] for row 1, col 3. Use to test if this cell is covered. -->
1418 <xsl:variable name="current-position">[<xsl:value-of select="$row-count"/>:<xsl:value-of select="$col-count"/>]</xsl:variable>
1419
1420 <xsl:choose>
1421 <!-- If the current value is already covered, increment the column number and try again. -->
1422 <xsl:when test="contains($matrix,$current-position)">
1423 <xsl:apply-templates select="." mode="find-matrix-column">
1424 <xsl:with-param name="stop-id"><xsl:value-of select="$stop-id"/></xsl:with-param>
1425 <xsl:with-param name="matrix"><xsl:value-of select="$matrix"/></xsl:with-param>
1426 <xsl:with-param name="row-count"><xsl:value-of select="$row-count"/></xsl:with-param>
1427 <xsl:with-param name="col-count"><xsl:value-of select="$col-count + 1"/></xsl:with-param>
1428 </xsl:apply-templates>
1429 </xsl:when>
1430 <!-- If this is the cell we are testing, return the current column number. -->
1431 <xsl:when test="generate-id(.)=$stop-id">
1432 <xsl:value-of select="$col-count"/>
1433 </xsl:when>
1434 <xsl:otherwise>
1435 <!-- Figure out what the next column value will be. -->
1436 <xsl:variable name="next-col-count">
1437 <xsl:choose>
1438 <xsl:when test="not(following-sibling::*)">1</xsl:when>
1439 <xsl:when test="@colspan"><xsl:value-of select="$col-count + number(@colspan) - 1"/></xsl:when>
1440 <xsl:otherwise><xsl:value-of select="$col-count + 1"/></xsl:otherwise>
1441 </xsl:choose>
1442 </xsl:variable>
1443 <!-- Determine any values that need to be added to the matrix, if this entry spans rows. -->
1444 <xsl:variable name="new-matrix-values">
1445 <xsl:if test="@rowspan">
1446 <xsl:call-template name="add-to-matrix">
1447 <xsl:with-param name="start-row"><xsl:value-of select="number($row-count)"/></xsl:with-param>
1448 <xsl:with-param name="end-row"><xsl:value-of select="number($row-count) + number(@rowspan) - 1"/></xsl:with-param>
1449 <xsl:with-param name="start-col"><xsl:value-of select="number($col-count)"/></xsl:with-param>
1450 <xsl:with-param name="end-col">
1451 <xsl:choose>
1452 <xsl:when test="@colspan"><xsl:value-of select="number($col-count) + number(@colspan) - 1"/></xsl:when>
1453 <xsl:otherwise><xsl:value-of select="number($col-count)"/></xsl:otherwise>
1454 </xsl:choose>
1455 </xsl:with-param>
1456 </xsl:call-template>
1457 </xsl:if>
1458 </xsl:variable>
1459 <xsl:choose>
1460 <!-- If there are more entries in this row, move to the next one. -->
1461 <xsl:when test="following-sibling::*">
1462 <xsl:apply-templates select="following-sibling::*[1]" mode="find-matrix-column">
1463 <xsl:with-param name="stop-id"><xsl:value-of select="$stop-id"/></xsl:with-param>
1464 <xsl:with-param name="matrix"><xsl:value-of select="$matrix"/><xsl:value-of select="$new-matrix-values"/></xsl:with-param>
1465 <xsl:with-param name="row-count"><xsl:value-of select="$row-count"/></xsl:with-param>
1466 <xsl:with-param name="col-count"><xsl:value-of select="$next-col-count"/></xsl:with-param>
1467 </xsl:apply-templates>
1468 </xsl:when>
1469 <!-- Otherwise, move to the first entry in the next row. -->
1470 <xsl:otherwise>
1471 <xsl:apply-templates select="../following-sibling::tr[1]/*[1]" mode="find-matrix-column">
1472 <xsl:with-param name="stop-id"><xsl:value-of select="$stop-id"/></xsl:with-param>
1473 <xsl:with-param name="matrix"><xsl:value-of select="$matrix"/><xsl:value-of select="$new-matrix-values"/></xsl:with-param>
1474 <xsl:with-param name="row-count"><xsl:value-of select="$row-count + 1"/></xsl:with-param>
1475 <xsl:with-param name="col-count"><xsl:value-of select="1"/></xsl:with-param>
1476 </xsl:apply-templates>
1477 </xsl:otherwise>
1478 </xsl:choose>
1479 </xsl:otherwise>
1480 </xsl:choose>
1481</xsl:template>
1482
1483<!-- This template returns values that must be added to the table matrix. Every cell in the box determined
1484 by start-row, end-row, start-col, and end-col will be added. First add every value from the first
1485 column. When past $end-row, move to the next column. When past $end-col, every value is added. -->
1486<xsl:template name="add-to-matrix">
1487 <xsl:param name="start-row"/>
1488 <xsl:param name="end-row"/>
1489 <xsl:param name="current-row"><xsl:value-of select="$start-row"/></xsl:param>
1490 <xsl:param name="start-col"/>
1491 <xsl:param name="end-col"/>
1492 <xsl:param name="current-col"><xsl:value-of select="$start-col"/></xsl:param>
1493 <xsl:choose>
1494 <xsl:when test="$current-col > $end-col"/> <!-- Out of the box; every value has been added -->
1495 <xsl:when test="$current-row > $end-row"> <!-- Finished with this column; move to next -->
1496 <xsl:call-template name="add-to-matrix">
1497 <xsl:with-param name="start-row"><xsl:value-of select="$start-row"/></xsl:with-param>
1498 <xsl:with-param name="end-row"><xsl:value-of select="$end-row"/></xsl:with-param>
1499 <xsl:with-param name="current-row"><xsl:value-of select="$start-row"/></xsl:with-param>
1500 <xsl:with-param name="start-col"><xsl:value-of select="$start-col"/></xsl:with-param>
1501 <xsl:with-param name="end-col"><xsl:value-of select="$end-col"/></xsl:with-param>
1502 <xsl:with-param name="current-col"><xsl:value-of select="$current-col + 1"/></xsl:with-param>
1503 </xsl:call-template>
1504 </xsl:when>
1505 <xsl:otherwise>
1506 <!-- Output the value for the current entry -->
1507 <xsl:text>[</xsl:text>
1508 <xsl:value-of select="$current-row"/>:<xsl:value-of select="$current-col"/>
1509 <xsl:text>]</xsl:text>
1510 <!-- Move to the next row, in the same column. -->
1511 <xsl:call-template name="add-to-matrix">
1512 <xsl:with-param name="start-row"><xsl:value-of select="$start-row"/></xsl:with-param>
1513 <xsl:with-param name="end-row"><xsl:value-of select="$end-row"/></xsl:with-param>
1514 <xsl:with-param name="current-row"><xsl:value-of select="$current-row + 1"/></xsl:with-param>
1515 <xsl:with-param name="start-col"><xsl:value-of select="$start-col"/></xsl:with-param>
1516 <xsl:with-param name="end-col"><xsl:value-of select="$end-col"/></xsl:with-param>
1517 <xsl:with-param name="current-col"><xsl:value-of select="$current-col"/></xsl:with-param>
1518 </xsl:call-template>
1519 </xsl:otherwise>
1520 </xsl:choose>
1521</xsl:template>
1522
1523<xsl:template match="tbody|tfoot|thead">
1524 <xsl:apply-templates/>
1525</xsl:template>
1526
1527<!-- If a table entry contains a paragraph, and nothing but a paragraph, do not
1528 create the <p> tag in the <entry>. Let everything fall through into <entry>. -->
1529<xsl:template match="td/p|th/p">
1530 <xsl:choose>
1531 <xsl:when test="following-sibling::*|preceding-sibling::*">
1532 <p><xsl:apply-templates select="@class|*|text()|comment()"/></p>
1533 </xsl:when>
1534 <xsl:when test="normalize-space(following-sibling::text()|preceding-sibling::text())=''">
1535 <xsl:apply-templates select="*|text()|comment()"/>
1536 </xsl:when>
1537 <xsl:otherwise>
1538 <p><xsl:apply-templates select="@class|*|text()|comment()"/></p>
1539 </xsl:otherwise>
1540 </xsl:choose>
1541</xsl:template>
1542
1543<xsl:template match="span[@class='bold']">
1544 <b>
1545 <xsl:apply-templates select="*|text()|comment()"/>
1546 </b>
1547</xsl:template>
1548
1549<xsl:template match="span[@class='italic']">
1550 <i>
1551 <xsl:apply-templates select="*|text()|comment()"/>
1552 </i>
1553</xsl:template>
1554
1555<xsl:template match="span[@class='bold-italic']">
1556 <b><i>
1557 <xsl:apply-templates select="*|text()|comment()"/>
1558 </i></b>
1559</xsl:template>
1560
1561
1562<!-- case of span with no attributes at all -->
1563
1564<xsl:template match="span[not(string(@*))]">
1565 <ph>
1566 <xsl:apply-templates select="*|text()|comment()"/>
1567 </ph>
1568</xsl:template>
1569
1570<!-- Search for span styles that Tidy moved into /html/head/style
1571 Each known value adds something to the return value, such as [b] for bold.
1572 The returned value is parsed to determine which wrappers to create.
1573 New values can be added here; processing for the new value will need
1574 to be merged into the sequential b/i/u/tt processing below. -->
1575<xsl:template name="get-span-style">
1576 <xsl:variable name="classval"><xsl:value-of select="@class"/></xsl:variable>
1577 <xsl:variable name="searchval">span.<xsl:value-of select="$classval"/></xsl:variable>
1578 <xsl:variable name="span-style">
1579 <xsl:value-of select="substring-before(substring-after(/html/head/style/text(),$searchval),'}')"/>}<xsl:text/>
1580 </xsl:variable>
1581 <xsl:if test="contains($span-style,'font-weight:bold') or contains($span-style,'font-weight :bold') or
1582 contains($span-style,'font-weight: bold') or
1583 contains($span-style,'font-weight : bold')">[b]</xsl:if>
1584 <xsl:if test="contains($span-style,'font-style:italic') or contains($span-style,'font-style :italic') or
1585 contains($span-style,'font-style: italic') or
1586 contains($span-style,'font-style : italic')">[i]</xsl:if>
1587 <xsl:if test="contains($span-style,'text-decoration: underline') or contains($span-style,'text-decoration :underline') or
1588 contains($span-style,'text-decoration: underline') or
1589 contains($span-style,'text-decoration : underline')">[u]</xsl:if>
1590 <xsl:if test="contains($span-style,'font-family:Courier') or contains($span-style,'font-family :Courier') or
1591 contains($span-style,'font-family: Courier') or
1592 contains($span-style,'font-family : Courier')">[tt]</xsl:if>
1593 <xsl:if test="contains($span-style,'font-weight:normal') or contains($span-style,'font-weight :normal') or
1594 contains($span-style,'font-weight: normal') or
1595 contains($span-style,'font-weight : normal')">[normal]</xsl:if>
1596</xsl:template>
1597
1598<!-- Process a span with a tidy-created class. It is known to have one or more
1599 values from b, i, u, or tt. For each value, create the element if needed,
1600 and move on to the next one, passing the style value from /html/head/style -->
1601<xsl:template name="bold-span">
1602 <xsl:param name="span-style"/>
1603 <xsl:choose>
1604 <xsl:when test="contains($span-style,'[b]')">
1605 <b><xsl:call-template name="italic-span"><xsl:with-param name="span-style" select="$span-style"/></xsl:call-template></b>
1606 </xsl:when>
1607 <xsl:otherwise><xsl:call-template name="italic-span"><xsl:with-param name="span-style" select="$span-style"/></xsl:call-template></xsl:otherwise>
1608 </xsl:choose>
1609</xsl:template>
1610<xsl:template name="italic-span">
1611 <xsl:param name="span-style"/>
1612 <xsl:choose>
1613 <xsl:when test="contains($span-style,'[i]')">
1614 <i><xsl:call-template name="underline-span"><xsl:with-param name="span-style" select="$span-style"/></xsl:call-template></i>
1615 </xsl:when>
1616 <xsl:otherwise><xsl:call-template name="underline-span"><xsl:with-param name="span-style" select="$span-style"/></xsl:call-template></xsl:otherwise>
1617 </xsl:choose>
1618</xsl:template>
1619<xsl:template name="underline-span">
1620 <xsl:param name="span-style"/>
1621 <xsl:choose>
1622 <xsl:when test="contains($span-style,'[u]')">
1623 <u><xsl:call-template name="courier-span"><xsl:with-param name="span-style" select="$span-style"/></xsl:call-template></u>
1624 </xsl:when>
1625 <xsl:otherwise><xsl:call-template name="courier-span"><xsl:with-param name="span-style" select="$span-style"/></xsl:call-template></xsl:otherwise>
1626 </xsl:choose>
1627</xsl:template>
1628<xsl:template name="courier-span">
1629 <xsl:param name="span-style"/>
1630 <xsl:choose>
1631 <xsl:when test="contains($span-style,'[tt]')">
1632 <tt><xsl:call-template name="normal-span"><xsl:with-param name="span-style" select="$span-style"/></xsl:call-template></tt>
1633 </xsl:when>
1634 <xsl:otherwise><xsl:call-template name="normal-span"><xsl:with-param name="span-style" select="$span-style"/></xsl:call-template></xsl:otherwise>
1635 </xsl:choose>
1636</xsl:template>
1637<xsl:template name="normal-span">
1638 <xsl:param name="span-style"/>
1639 <xsl:choose>
1640 <!-- If a span has "normal" style and nothing else, create <ph> -->
1641 <xsl:when test="contains($span-style,'[normal]') and
1642 substring-before($span-style,'[normal]')='' and
1643 substring-after($span-style,'[normal]')=''">
1644 <ph><xsl:apply-templates select="*|text()|comment()"/></ph>
1645 </xsl:when>
1646 <xsl:otherwise><xsl:apply-templates select="*|text()|comment()"/></xsl:otherwise>
1647 </xsl:choose>
1648</xsl:template>
1649
1650<xsl:template match="span">
1651 <xsl:choose>
1652 <xsl:when test="@class='bold-italic'">
1653 <b><i><xsl:apply-templates select="*|text()|comment()"/></i></b>
1654 </xsl:when>
1655 <!-- If the span has a value created by tidy, parse /html/head/style -->
1656 <xsl:when test="@class='c1' or @class='c2' or @class='c3' or
1657 @class='c4' or @class='c5' or @class='c6' or
1658 @class='c7' or @class='c8' or @class='c9'">
1659 <xsl:variable name="span-style"><xsl:call-template name="get-span-style"/></xsl:variable>
1660 <xsl:choose>
1661 <xsl:when test="string-length($span-style)>0">
1662 <xsl:call-template name="bold-span"><xsl:with-param name="span-style" select="$span-style"/></xsl:call-template>
1663 </xsl:when>
1664 <xsl:otherwise>
1665 <xsl:variable name="searchval">span.<xsl:value-of select="@class"/></xsl:variable>
1666 <xsl:variable name="orig-span-style">
1667 <xsl:value-of select="substring-before(substring-after(/html/head/style/text(),$searchval),'}')"/>}<xsl:text/>
1668 </xsl:variable>
1669 <xsl:call-template name="output-message">
1670 <xsl:with-param name="msg">CLEANUP ACTION: provide a better phrase markup for a SPAN tag.
1671The element's contents have been placed in a phrase element.
1672There is a comment next to the phrase with the span's class value.</xsl:with-param>
1673 </xsl:call-template>
1674 <xsl:if test="$verbose">
1675 <xsl:comment>Original: &lt;span @class=<xsl:value-of select="@class"/>&gt;, <xsl:value-of select="@class"/>=<xsl:value-of select="$orig-span-style"/></xsl:comment>
1676 </xsl:if>
1677 <ph><xsl:apply-templates select="*|text()|comment()"/></ph>
1678 </xsl:otherwise>
1679 </xsl:choose>
1680 </xsl:when>
1681 <xsl:otherwise>
1682 <xsl:call-template name="output-message">
1683 <xsl:with-param name="msg">CLEANUP ACTION: provide a better phrase markup for a SPAN tag.
1684The element's contents have been placed in a phrase element.
1685There is a comment next to the phrase with the span's class value.</xsl:with-param>
1686 </xsl:call-template>
1687 <xsl:if test="$verbose">
1688 <xsl:comment>Original: &lt;span @class=<xsl:value-of select="@class"/>&gt;</xsl:comment>
1689 </xsl:if>
1690 <ph><xsl:apply-templates select="@class"/><xsl:apply-templates select="*|text()|comment()"/></ph>
1691 </xsl:otherwise>
1692 </xsl:choose>
1693</xsl:template>
1694
1695<!-- generate dlentry wrapper for DL/DD/DT -->
1696
1697<xsl:template match="dt">
1698<dlentry>
1699 <dt><xsl:apply-templates select="@class|*|text()|comment()"/></dt>
1700 <xsl:apply-templates select="following-sibling::*[1]" mode="indirect"/>
1701</dlentry>
1702</xsl:template>
1703
1704<xsl:template match="dd"/>
1705
1706<xsl:template match="dt" mode="indirect"/>
1707<xsl:template match="dd" mode="indirect">
1708 <dd>
1709 <xsl:apply-templates select="@class|*|text()|comment()"/>
1710 </dd>
1711 <xsl:apply-templates select="following-sibling::*[1]" mode="indirect"/>
1712</xsl:template>
1713
1714
1715<!-- named templates -->
1716
1717<!--
1718<xsl:template name="sect1topic">
1719<topic xml:lang="{$default-lang}">
1720 <xsl:if test="@id"><xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute></xsl:if>
1721 <xsl:apply-templates/>
1722</topic>
1723</xsl:template>
1724-->
1725
1726
1727<!-- things noted for disambiguation -->
1728
1729<!-- encapsulate text within body -->
1730<xsl:template match="body/text()|body/div/text()">
1731 <xsl:variable name="bodytxt"><xsl:value-of select="normalize-space(.)"/></xsl:variable>
1732 <xsl:if test="string-length($bodytxt)>0">
1733 <!-- issue a message here? Not EVERY time, puleeeze. test for first node if we must... -->
1734 <p>
1735 <xsl:value-of select="."/>
1736 </p>
1737 </xsl:if>
1738 <!-- text nodes get wrapped; blanks fall through -->
1739</xsl:template>
1740
1741<!-- encapsulate phrases within body -->
1742<xsl:template match="body/i|body/div/i" priority="4">
1743 <p><i><xsl:apply-templates select="@class|*|text()|comment()"/></i></p>
1744</xsl:template>
1745<xsl:template match="body/b|body/div/b" priority="4">
1746 <p><b><xsl:apply-templates select="@class|*|text()|comment()"/></b></p>
1747</xsl:template>
1748<xsl:template match="body/u|body/div/u" priority="4">
1749 <p><u><xsl:apply-templates select="@class|*|text()|comment()"/></u></p>
1750</xsl:template>
1751
1752<!-- 03/28/2003 RDA: consolidate all <a> processing into single template -->
1753<!-- <xsl:template match="body/a" priority="4">
1754 <xsl:choose>
1755 <xsl:when test="@name">
1756 <xsl:comment>Removed anchor point <xsl:value-of select="@name"/></xsl:comment>
1757 </xsl:when>
1758 <xsl:when test="@id">
1759 <xsl:comment>Removed anchor point <xsl:value-of select="@id"/></xsl:comment>
1760 </xsl:when>
1761 </xsl:choose>
1762 <xsl:if test="@href">
1763 <p>
1764 <xref>
1765 <xsl:call-template name="genlinkattrs"/>
1766 <xsl:apply-templates/>
1767 </xref>
1768 </p>
1769 </xsl:if>
1770</xsl:template> -->
1771
1772
1773<!-- case of deprecated elements with no clear migrational intent -->
1774
1775<xsl:template match="small|big">
1776 <xsl:call-template name="output-message">
1777 <xsl:with-param name="msg">CLEANUP ACTION: provide a better phrase markup for a BIG or SMALL tag.
1778The element's contents have been placed in a required-cleanup element.</xsl:with-param>
1779 </xsl:call-template>
1780 <xsl:variable name="content">
1781 <xsl:attribute name="remap"><xsl:value-of select="name()"/></xsl:attribute>
1782 <ph>
1783 <xsl:apply-templates select="@class|*|text()|comment()"/>
1784 </ph>
1785 </xsl:variable>
1786 <xsl:choose>
1787 <xsl:when test="$generateRequiredCleanup">
1788 <required-cleanup>
1789 <xsl:copy-of select="$content"/>
1790 </required-cleanup>
1791 </xsl:when>
1792 <xsl:otherwise>
1793 <xsl:copy-of select="$content"/>
1794 </xsl:otherwise>
1795 </xsl:choose>
1796</xsl:template>
1797
1798
1799<xsl:template match="s|strike">
1800 <xsl:call-template name="output-message">
1801 <xsl:with-param name="msg">CLEANUP ACTION: provide a better phrase markup for a strikethrough tag.
1802The element's contents have been placed in a required-cleanup element.</xsl:with-param>
1803 </xsl:call-template>
1804 <xsl:variable name="content">
1805 <xsl:attribute name="remap"><xsl:value-of select="name()"/></xsl:attribute>
1806 <ph>
1807 <xsl:apply-templates select="@class|*|text()|comment()"/>
1808 </ph>
1809 </xsl:variable>
1810 <xsl:choose>
1811 <xsl:when test="$generateRequiredCleanup">
1812 <required-cleanup>
1813 <xsl:copy-of select="$content"/>
1814 </required-cleanup>
1815 </xsl:when>
1816 <xsl:otherwise>
1817 <xsl:copy-of select="$content"/>
1818 </xsl:otherwise>
1819 </xsl:choose>
1820</xsl:template>
1821
1822<!-- set of rules for faux-pre sections (paragraphs with br, using samp for font effect)-->
1823
1824<xsl:template match="p[samp][not(text())]">
1825 <pre>
1826 <xsl:apply-templates mode="re-pre"/>
1827 </pre>
1828</xsl:template>
1829
1830<xsl:template match="samp" mode="re-pre">
1831 <xsl:apply-templates mode="re-pre"/>
1832</xsl:template>
1833
1834<xsl:template match="samp/br" mode="re-pre"/><!-- won't need introduced space if original source has it -->
1835
1836<xsl:template match="comment()">
1837 <xsl:comment><xsl:value-of select="."/></xsl:comment>
1838</xsl:template>
1839
1840<!-- =========== CATCH UNDEFINED ELEMENTS (for stylesheet maintainers) =========== -->
1841
1842<!-- (this rule should NOT produce output in production setting) -->
1843<xsl:template match="*">
1844 <xsl:call-template name="output-message">
1845 <xsl:with-param name="msg">CLEANUP ACTION: no DITA equivalent for HTML element '<xsl:value-of select="name()"/>'.
1846The element has been placed in a required-cleanup element.</xsl:with-param>
1847 </xsl:call-template>
1848 <xsl:variable name="content">
1849 <ph>
1850 <xsl:attribute name="remap"><xsl:value-of select="name()"/></xsl:attribute>
1851 <xsl:apply-templates select="*|text()|comment()"/>
1852 </ph>
1853 </xsl:variable>
1854 <xsl:choose>
1855 <xsl:when test="$generateRequiredCleanup">
1856 <required-cleanup>
1857 <xsl:copy-of select="$content"/>
1858 </required-cleanup>
1859 </xsl:when>
1860 <xsl:otherwise>
1861 <xsl:copy-of select="$content"/>
1862 </xsl:otherwise>
1863 </xsl:choose>
1864</xsl:template>
1865
1866<!-- ====================================================================================== -->
1867<!-- Special templates for pre-processing an XHTML file, in order to merge sequential lists -->
1868
1869<!-- If there are not any split lists surrounding this element, copy it as is. If this is between
1870 two parts of a split list, it will be pulled in to the preceding list item, so ignore it now. -->
1871<xsl:template match="*|@*|comment()|processing-instruction()|text()" mode="shift-lists">
1872 <xsl:choose>
1873 <xsl:when test="not(following-sibling::ol[1][@start]) or not(preceding-sibling::ol)">
1874 <xsl:copy>
1875 <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="shift-lists"/>
1876 </xsl:copy>
1877 </xsl:when>
1878 <xsl:otherwise>
1879 <!-- There is a re-started list after this. Check to make sure the numbers are correct. -->
1880 <xsl:variable name="supposed-next-start">
1881 <xsl:choose>
1882 <xsl:when test="preceding-sibling::ol[1]/@start">
1883 <xsl:value-of select="number(preceding-sibling::ol[1]/@start) + count(preceding-sibling::ol[1]/li)"/>
1884 </xsl:when>
1885 <xsl:otherwise>
1886 <xsl:value-of select="count(preceding-sibling::ol[1]/li) + 1"/>
1887 </xsl:otherwise>
1888 </xsl:choose>
1889 </xsl:variable>
1890 <xsl:choose>
1891 <!-- If the next list continues the previous, this element was pulled in to the previous list. -->
1892 <xsl:when test="$supposed-next-start=following-sibling::ol[1]/@start"/>
1893 <xsl:otherwise>
1894 <xsl:copy>
1895 <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="shift-lists"/>
1896 </xsl:copy>
1897 </xsl:otherwise>
1898 </xsl:choose>
1899 </xsl:otherwise>
1900 </xsl:choose>
1901</xsl:template>
1902
1903<!-- Process ordered lists individually. -->
1904<xsl:template match="ol" mode="shift-lists">
1905 <xsl:choose>
1906 <!-- If this could be a continuation, check the @start value against the previous list -->
1907 <xsl:when test="@start and preceding-sibling::ol">
1908 <xsl:variable name="supposed-start">
1909 <xsl:choose>
1910 <xsl:when test="preceding-sibling::ol[1]/@start">
1911 <xsl:value-of select="number(preceding-sibling::ol[1]/@start) + count(preceding-sibling::ol[1]/li)"/>
1912 </xsl:when>
1913 <xsl:otherwise>
1914 <xsl:value-of select="count(preceding-sibling::ol[1]/li) + 1"/>
1915 </xsl:otherwise>
1916 </xsl:choose>
1917 </xsl:variable>
1918 <xsl:choose>
1919 <!-- If this continues the previous list, it was pulled in when processing that list. -->
1920 <xsl:when test="$supposed-start=@start"/>
1921 <!-- Otherwise, there's a goof-up somewhere, just copy it to the output -->
1922 <xsl:otherwise>
1923 <xsl:copy>
1924 <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="shift-lists"/>
1925 </xsl:copy>
1926 </xsl:otherwise>
1927 </xsl:choose>
1928 </xsl:when>
1929 <!-- The list does not continue a previous list (though it may start a new one) -->
1930 <xsl:otherwise>
1931 <xsl:copy>
1932 <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="shift-lists"/>
1933 </xsl:copy>
1934 </xsl:otherwise>
1935 </xsl:choose>
1936</xsl:template>
1937
1938<!-- All list items but the last one are copied as-is. The last one is also copied, but we need to check
1939 for continued lists. If this list is continued, everything between this item and the next list should
1940 be copied in to the end of this list item. After the item is processed, add all of the list items from
1941 the continue-ing list. -->
1942<xsl:template match="ol/li[not(following-sibling::li)]" mode="shift-lists">
1943 <xsl:variable name="supposed-next-start">
1944 <xsl:choose>
1945 <xsl:when test="../@start"><xsl:value-of select="number(../@start) + count(../li)"/></xsl:when>
1946 <xsl:otherwise><xsl:value-of select="count(../li) + 1"/></xsl:otherwise>
1947 </xsl:choose>
1948 </xsl:variable>
1949 <xsl:copy>
1950 <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="shift-lists"/>
1951 <xsl:if test="../following-sibling::ol[1]/@start and $supposed-next-start=../following-sibling::ol[1]/@start">
1952 <xsl:variable name="next-id"><xsl:value-of select="generate-id(../following-sibling::ol[1])"/></xsl:variable>
1953 <xsl:apply-templates
1954 select="../following-sibling::text()[generate-id(following-sibling::ol[1])=$next-id]|
1955 ../following-sibling::*[generate-id(following-sibling::ol[1])=$next-id]"
1956 mode="add-to-list"/>
1957 </xsl:if>
1958 </xsl:copy>
1959 <xsl:if test="../following-sibling::ol[1]/@start and $supposed-next-start=../following-sibling::ol[1]/@start">
1960 <xsl:apply-templates select="../following-sibling::ol[1]/*" mode="shift-lists"/>
1961 </xsl:if>
1962</xsl:template>
1963
1964<!-- Matches anything between 2 lists that are being merged. -->
1965<xsl:template match="*|@*|comment()|processing-instruction()|text()" mode="add-to-list">
1966 <xsl:copy>
1967 <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="add-to-list"/>
1968 </xsl:copy>
1969</xsl:template>
1970
1971<!-- Validate the input parameters -->
1972<xsl:template name="validate-parameters">
1973 <xsl:if test="not($infotype='topic' or $infotype='concept' or $infotype='reference' or $infotype='task')">
1974 <xsl:call-template name="output-message">
1975 <xsl:with-param name="msg">'<xsl:value-of select="$infotype"/>' is an invalid infotype, use 'topic' as the default infotype.</xsl:with-param>
1976 </xsl:call-template>
1977 </xsl:if>
1978 <xsl:if test="not($dita-extension='.dita' or $dita-extension='.xml')">
1979 <xsl:call-template name="output-message">
1980 <xsl:with-param name="msg">'<xsl:value-of select="$dita-extension"/>' is an invalid dita extension, please use '.dita' or '.xml' as the dita extension.</xsl:with-param>
1981 </xsl:call-template>
1982 </xsl:if>
1983 <xsl:if test="not(contains($FILENAME, '.htm'))">
1984 <xsl:call-template name="output-message">
1985 <xsl:with-param name="msg">The parameter FILENAME should ends with '.htm' or '.html'.</xsl:with-param>
1986 </xsl:call-template>
1987 </xsl:if>
1988</xsl:template>
1989
1990</xsl:stylesheet>