VirtualBox

source: vbox/trunk/src/libs/dita-ot-1.8.5/plugins/h2d/h2d.xsl@ 99507

最後變更 在這個檔案從99507是 98584,由 vboxsync 提交於 2 年 前

Docs: bugref:10302. Setting svn properties of DITA-OT library.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette