1 <?xml version="1.0" encoding="ASCII"?><!--This file was created automatically by html2xhtml--><!--from the HTML stylesheets.--><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">
3 <!-- ********************************************************************
5 This file is part of the XSL DocBook Stylesheet distribution.
6 See ../README or http://cdn.docbook.org/release/xsl/current/ for
7 copyright and other information.
9 ******************************************************************** -->
11 <!-- ==================================================================== -->
13 <!-- This module contains templates that match against HTML nodes. It is used
14 to post-process result tree fragments for some sorts of cleanup.
15 These templates can only ever be fired by a processor that supports
18 <!-- ==================================================================== -->
20 <!-- insert.html.p mode templates insert a particular RTF at the beginning
21 of the first paragraph in the primary RTF. -->
23 <xsl:template match="/" mode="insert.html.p">
24 <xsl:param name="mark" select="'?'"/>
25 <xsl:apply-templates mode="insert.html.p">
26 <xsl:with-param name="mark" select="$mark"/>
27 </xsl:apply-templates>
30 <xsl:template match="*" mode="insert.html.p">
31 <xsl:param name="mark" select="'?'"/>
33 <xsl:copy-of select="@*"/>
34 <xsl:apply-templates mode="insert.html.p">
35 <xsl:with-param name="mark" select="$mark"/>
36 </xsl:apply-templates>
40 <xsl:template xmlns:html="http://www.w3.org/1999/xhtml" match="html:p|p" mode="insert.html.p">
41 <xsl:param name="mark" select="'?'"/>
43 <xsl:copy-of select="@*"/>
44 <xsl:if test="not(preceding::p|preceding::html:p)">
45 <xsl:copy-of select="$mark"/>
47 <xsl:apply-templates mode="insert.html.p">
48 <xsl:with-param name="mark" select="$mark"/>
49 </xsl:apply-templates>
53 <xsl:template match="text()|processing-instruction()|comment()" mode="insert.html.p">
54 <xsl:param name="mark" select="'?'"/>
58 <!-- ==================================================================== -->
60 <!-- insert.html.text mode templates insert a particular RTF at the beginning
61 of the first text-node in the primary RTF. -->
63 <xsl:template match="/" mode="insert.html.text">
64 <xsl:param name="mark" select="'?'"/>
65 <xsl:apply-templates mode="insert.html.text">
66 <xsl:with-param name="mark" select="$mark"/>
67 </xsl:apply-templates>
70 <xsl:template match="*" mode="insert.html.text">
71 <xsl:param name="mark" select="'?'"/>
73 <xsl:copy-of select="@*"/>
74 <xsl:apply-templates mode="insert.html.text">
75 <xsl:with-param name="mark" select="$mark"/>
76 </xsl:apply-templates>
80 <xsl:template match="text()|processing-instruction()|comment()" mode="insert.html.text">
81 <xsl:param name="mark" select="'?'"/>
83 <xsl:if test="not(preceding::text())">
84 <xsl:copy-of select="$mark"/>
90 <xsl:template match="processing-instruction()|comment()" mode="insert.html.text">
91 <xsl:param name="mark" select="'?'"/>
95 <!-- ==================================================================== -->
97 <!-- unwrap.p mode templates remove blocks from HTML p elements (and
98 other places where blocks aren't allowed) -->
100 <xsl:template name="unwrap.p">
101 <xsl:param name="p"/>
103 <xsl:when test="$exsl.node.set.available != 0 and function-available('set:leading') and function-available('set:trailing')">
104 <xsl:apply-templates select="exsl:node-set($p)" mode="unwrap.p"/>
107 <xsl:copy-of select="$p"/>
112 <xsl:template xmlns:html="http://www.w3.org/1999/xhtml" match="html:p|p" mode="unwrap.p">
113 <!-- xmlns:html is necessary for the xhtml stylesheet case -->
114 <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"/>
116 <xsl:when test="$blocks">
117 <xsl:call-template name="unwrap.p.nodes">
118 <xsl:with-param name="wrap" select="."/>
119 <xsl:with-param name="first" select="1"/>
120 <xsl:with-param name="nodes" select="node()"/>
121 <xsl:with-param name="blocks" select="$blocks"/>
126 <xsl:copy-of select="@*"/>
127 <xsl:apply-templates mode="unwrap.p"/>
133 <xsl:template match="*" mode="unwrap.p">
135 <xsl:copy-of select="@*"/>
136 <xsl:apply-templates mode="unwrap.p"/>
140 <xsl:template match="text()|processing-instruction()|comment()" mode="unwrap.p">
144 <xsl:template name="unwrap.p.nodes">
145 <xsl:param name="wrap" select="."/>
146 <xsl:param name="first" select="0"/>
147 <xsl:param name="nodes"/>
148 <xsl:param name="blocks"/>
149 <xsl:variable name="block" select="$blocks[1]"/>
151 <!-- This template should never get called if these functions aren't available -->
152 <!-- but this test is still necessary so that processors don't choke on the -->
153 <!-- function calls if they don't support the set: functions -->
154 <xsl:if test="function-available('set:leading') and function-available('set:trailing')">
156 <xsl:when test="$blocks">
157 <xsl:variable name="leading" select="set:leading($nodes,$block)"/>
158 <xsl:variable name="trailing" select="set:trailing($nodes,$block)"/>
160 <xsl:if test="(($wrap/@id or $wrap/@xml:id) and $first = 1) or $leading">
161 <xsl:element name="{local-name($wrap)}" namespace="http://www.w3.org/1999/xhtml">
162 <xsl:for-each select="$wrap/@*">
163 <xsl:if test="$first != 0 or local-name(.) != 'id'">
167 <xsl:apply-templates select="$leading" mode="unwrap.p"/>
171 <xsl:apply-templates select="$block" mode="unwrap.p"/>
173 <xsl:if test="$trailing">
174 <xsl:call-template name="unwrap.p.nodes">
175 <xsl:with-param name="wrap" select="$wrap"/>
176 <xsl:with-param name="nodes" select="$trailing"/>
177 <xsl:with-param name="blocks" select="$blocks[position() > 1]"/>
183 <xsl:if test="(($wrap/@id or $wrap/@xml:id) and $first = 1) or $nodes">
184 <xsl:element name="{local-name($wrap)}" namespace="http://www.w3.org/1999/xhtml">
185 <xsl:for-each select="$wrap/@*">
186 <xsl:if test="$first != 0 or local-name(.) != 'id'">
190 <xsl:apply-templates select="$nodes" mode="unwrap.p"/>
198 <!-- ==================================================================== -->
199 <!-- make.verbatim.mode replaces spaces and newlines -->
201 <xsl:template match="/" mode="make.verbatim.mode">
202 <xsl:apply-templates mode="make.verbatim.mode"/>
205 <xsl:template match="*" mode="make.verbatim.mode">
207 <xsl:copy-of select="@*"/>
208 <xsl:apply-templates mode="make.verbatim.mode"/>
212 <xsl:template match="processing-instruction()|comment()" mode="make.verbatim.mode">
216 <xsl:template match="text()" mode="make.verbatim.mode">
217 <xsl:variable name="text" select="translate(., ' ', ' ')"/>
220 <xsl:when test="not(contains($text, '
'))">
221 <xsl:value-of select="$text"/>
225 <xsl:variable name="len" select="string-length($text)"/>
228 <xsl:when test="$len = 1">
234 <xsl:variable name="half" select="$len div 2"/>
235 <xsl:call-template name="make-verbatim-recursive">
236 <xsl:with-param name="text" select="substring($text, 1, $half)"/>
238 <xsl:call-template name="make-verbatim-recursive">
239 <xsl:with-param name="text" select="substring($text, ($half + 1), $len)"/>
247 <xsl:template name="make-verbatim-recursive">
248 <xsl:param name="text" select="''"/>
251 <xsl:when test="not(contains($text, '
'))">
252 <xsl:value-of select="$text"/>
256 <xsl:variable name="len" select="string-length($text)"/>
259 <xsl:when test="$len = 1">
265 <xsl:variable name="half" select="$len div 2"/>
266 <xsl:call-template name="make-verbatim-recursive">
267 <xsl:with-param name="text" select="substring($text, 1, $half)"/>
269 <xsl:call-template name="make-verbatim-recursive">
270 <xsl:with-param name="text" select="substring($text, ($half + 1), $len)"/>
278 <!-- ==================================================================== -->
280 <!-- remove.empty.div mode templates remove empty blocks -->
282 <xsl:template name="remove.empty.div">
283 <xsl:param name="div"/>
285 <xsl:when test="$exsl.node.set.available != 0">
286 <xsl:apply-templates select="exsl:node-set($div)" mode="remove.empty.div"/>
289 <xsl:copy-of select="$div"/>
294 <xsl:template xmlns:html="http://www.w3.org/1999/xhtml" match="html:p|p|html:div|div" mode="remove.empty.div">
295 <xsl:if test="node()">
297 <xsl:copy-of select="@*"/>
298 <xsl:apply-templates mode="remove.empty.div"/>
303 <xsl:template match="*" mode="remove.empty.div">
305 <xsl:copy-of select="@*"/>
306 <xsl:apply-templates mode="remove.empty.div"/>
310 <xsl:template match="text()|processing-instruction()|comment()" mode="remove.empty.div">
314 <!-- ==================================================================== -->