1 <?xml version="1.0" encoding="ASCII"?>
2 <!--This file was created automatically by html2xhtml-->
3 <!--from the HTML stylesheets.-->
4 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:set="http://exslt.org/sets" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="exsl set" version="1.0">
6 <!-- ********************************************************************
7 $Id: html-rtf.xsl 8345 2009-03-16 06:44:07Z bobstayton $
8 ********************************************************************
10 This file is part of the XSL DocBook Stylesheet distribution.
11 See ../README or http://docbook.sf.net/release/xsl/current/ for
12 copyright and other information.
14 ******************************************************************** -->
16 <!-- ==================================================================== -->
18 <!-- This module contains templates that match against HTML nodes. It is used
19 to post-process result tree fragments for some sorts of cleanup.
20 These templates can only ever be fired by a processor that supports
23 <!-- ==================================================================== -->
25 <!-- insert.html.p mode templates insert a particular RTF at the beginning
26 of the first paragraph in the primary RTF. -->
28 <xsl:template match="/" mode="insert.html.p">
29 <xsl:param name="mark" select="'?'"/>
30 <xsl:apply-templates mode="insert.html.p">
31 <xsl:with-param name="mark" select="$mark"/>
32 </xsl:apply-templates>
35 <xsl:template match="*" mode="insert.html.p">
36 <xsl:param name="mark" select="'?'"/>
38 <xsl:copy-of select="@*"/>
39 <xsl:apply-templates mode="insert.html.p">
40 <xsl:with-param name="mark" select="$mark"/>
41 </xsl:apply-templates>
45 <xsl:template xmlns:html="http://www.w3.org/1999/xhtml" match="html:p|p" mode="insert.html.p">
46 <xsl:param name="mark" select="'?'"/>
48 <xsl:copy-of select="@*"/>
49 <xsl:if test="not(preceding::p|preceding::html:p)">
50 <xsl:copy-of select="$mark"/>
52 <xsl:apply-templates mode="insert.html.p">
53 <xsl:with-param name="mark" select="$mark"/>
54 </xsl:apply-templates>
58 <xsl:template match="text()|processing-instruction()|comment()" mode="insert.html.p">
59 <xsl:param name="mark" select="'?'"/>
63 <!-- ==================================================================== -->
65 <!-- insert.html.text mode templates insert a particular RTF at the beginning
66 of the first text-node in the primary RTF. -->
68 <xsl:template match="/" mode="insert.html.text">
69 <xsl:param name="mark" select="'?'"/>
70 <xsl:apply-templates mode="insert.html.text">
71 <xsl:with-param name="mark" select="$mark"/>
72 </xsl:apply-templates>
75 <xsl:template match="*" mode="insert.html.text">
76 <xsl:param name="mark" select="'?'"/>
78 <xsl:copy-of select="@*"/>
79 <xsl:apply-templates mode="insert.html.text">
80 <xsl:with-param name="mark" select="$mark"/>
81 </xsl:apply-templates>
85 <xsl:template match="text()|processing-instruction()|comment()" mode="insert.html.text">
86 <xsl:param name="mark" select="'?'"/>
88 <xsl:if test="not(preceding::text())">
89 <xsl:copy-of select="$mark"/>
95 <xsl:template match="processing-instruction()|comment()" mode="insert.html.text">
96 <xsl:param name="mark" select="'?'"/>
100 <!-- ==================================================================== -->
102 <!-- unwrap.p mode templates remove blocks from HTML p elements (and
103 other places where blocks aren't allowed) -->
105 <xsl:template name="unwrap.p">
106 <xsl:param name="p"/>
108 <xsl:when test="$exsl.node.set.available != 0 and function-available('set:leading') and function-available('set:trailing')">
109 <xsl:apply-templates select="exsl:node-set($p)" mode="unwrap.p"/>
112 <xsl:copy-of select="$p"/>
117 <xsl:template xmlns:html="http://www.w3.org/1999/xhtml" match="html:p|p" mode="unwrap.p">
118 <!-- xmlns:html is necessary for the xhtml stylesheet case -->
119 <xsl:variable name="blocks" select="address|blockquote|div|hr|h1|h2|h3|h4|h5|h6 |layer|p|pre|table|dl|menu|ol|ul|form |html:address|html:blockquote|html:div|html:hr |html:h1|html:h2|html:h3|html:h4|html:h5|html:h6 |html:layer|html:p|html:pre|html:table|html:dl |html:menu|html:ol|html:ul|html:form"/>
121 <xsl:when test="$blocks">
122 <xsl:call-template name="unwrap.p.nodes">
123 <xsl:with-param name="wrap" select="."/>
124 <xsl:with-param name="first" select="1"/>
125 <xsl:with-param name="nodes" select="node()"/>
126 <xsl:with-param name="blocks" select="$blocks"/>
131 <xsl:copy-of select="@*"/>
132 <xsl:apply-templates mode="unwrap.p"/>
138 <xsl:template match="*" mode="unwrap.p">
140 <xsl:copy-of select="@*"/>
141 <xsl:apply-templates mode="unwrap.p"/>
145 <xsl:template match="text()|processing-instruction()|comment()" mode="unwrap.p">
149 <xsl:template name="unwrap.p.nodes">
150 <xsl:param name="wrap" select="."/>
151 <xsl:param name="first" select="0"/>
152 <xsl:param name="nodes"/>
153 <xsl:param name="blocks"/>
154 <xsl:variable name="block" select="$blocks[1]"/>
156 <!-- This template should never get called if these functions aren't available -->
157 <!-- but this test is still necessary so that processors don't choke on the -->
158 <!-- function calls if they don't support the set: functions -->
159 <xsl:if test="function-available('set:leading') and function-available('set:trailing')">
161 <xsl:when test="$blocks">
162 <xsl:variable name="leading" select="set:leading($nodes,$block)"/>
163 <xsl:variable name="trailing" select="set:trailing($nodes,$block)"/>
165 <xsl:if test="(($wrap/@id or $wrap/@xml:id) and $first = 1) or $leading">
166 <xsl:element name="{local-name($wrap)}" namespace="http://www.w3.org/1999/xhtml">
167 <xsl:for-each select="$wrap/@*">
168 <xsl:if test="$first != 0 or local-name(.) != 'id'">
172 <xsl:apply-templates select="$leading" mode="unwrap.p"/>
176 <xsl:apply-templates select="$block" mode="unwrap.p"/>
178 <xsl:if test="$trailing">
179 <xsl:call-template name="unwrap.p.nodes">
180 <xsl:with-param name="wrap" select="$wrap"/>
181 <xsl:with-param name="nodes" select="$trailing"/>
182 <xsl:with-param name="blocks" select="$blocks[position() > 1]"/>
188 <xsl:if test="(($wrap/@id or $wrap/@xml:id) and $first = 1) or $nodes">
189 <xsl:element name="{local-name($wrap)}" namespace="http://www.w3.org/1999/xhtml">
190 <xsl:for-each select="$wrap/@*">
191 <xsl:if test="$first != 0 or local-name(.) != 'id'">
195 <xsl:apply-templates select="$nodes" mode="unwrap.p"/>
203 <!-- ==================================================================== -->
204 <!-- make.verbatim.mode replaces spaces and newlines -->
206 <xsl:template match="/" mode="make.verbatim.mode">
207 <xsl:apply-templates mode="make.verbatim.mode"/>
210 <xsl:template match="*" mode="make.verbatim.mode">
212 <xsl:copy-of select="@*"/>
213 <xsl:apply-templates mode="make.verbatim.mode"/>
217 <xsl:template match="processing-instruction()|comment()" mode="make.verbatim.mode">
221 <xsl:template match="text()" mode="make.verbatim.mode">
222 <xsl:variable name="text" select="translate(., ' ', ' ')"/>
225 <xsl:when test="not(contains($text, ' '))">
226 <xsl:value-of select="$text"/>
230 <xsl:variable name="len" select="string-length($text)"/>
233 <xsl:when test="$len = 1">
239 <xsl:variable name="half" select="$len div 2"/>
240 <xsl:call-template name="make-verbatim-recursive">
241 <xsl:with-param name="text" select="substring($text, 1, $half)"/>
243 <xsl:call-template name="make-verbatim-recursive">
244 <xsl:with-param name="text" select="substring($text, ($half + 1), $len)"/>
252 <xsl:template name="make-verbatim-recursive">
253 <xsl:param name="text" select="''"/>
256 <xsl:when test="not(contains($text, ' '))">
257 <xsl:value-of select="$text"/>
261 <xsl:variable name="len" select="string-length($text)"/>
264 <xsl:when test="$len = 1">
270 <xsl:variable name="half" select="$len div 2"/>
271 <xsl:call-template name="make-verbatim-recursive">
272 <xsl:with-param name="text" select="substring($text, 1, $half)"/>
274 <xsl:call-template name="make-verbatim-recursive">
275 <xsl:with-param name="text" select="substring($text, ($half + 1), $len)"/>
283 <!-- ==================================================================== -->
285 <!-- remove.empty.div mode templates remove empty blocks -->
287 <xsl:template name="remove.empty.div">
288 <xsl:param name="div"/>
290 <xsl:when test="$exsl.node.set.available != 0">
291 <xsl:apply-templates select="exsl:node-set($div)" mode="remove.empty.div"/>
294 <xsl:copy-of select="$div"/>
299 <xsl:template xmlns:html="http://www.w3.org/1999/xhtml" match="html:p|p|html:div|div" mode="remove.empty.div">
300 <xsl:if test="node()">
302 <xsl:copy-of select="@*"/>
303 <xsl:apply-templates mode="remove.empty.div"/>
308 <xsl:template match="*" mode="remove.empty.div">
310 <xsl:copy-of select="@*"/>
311 <xsl:apply-templates mode="remove.empty.div"/>
315 <xsl:template match="text()|processing-instruction()|comment()" mode="remove.empty.div">
319 <!-- ==================================================================== -->