source: rfc2629xslt/clean-for-DTD.xslt @ 19

Last change on this file since 19 was 6, checked in by fielding@…, 15 years ago

XSLT stylesheet for enhanced RFC2629 xml2rfc output as HTML.
By Julian Reschke

Obtained from: wget -N http://www.greenbytes.de/tech/webdav/rfc2629xslt.zip

  • Property svn:eol-style set to native
File size: 16.0 KB
Line 
1<!--
2    Strip rfc2629.xslt extensions, generating XML input for MTR's xml2rfc
3
4    Copyright (c) 2006-2007, Julian Reschke (julian.reschke@greenbytes.de)
5    All rights reserved.
6
7    Redistribution and use in source and binary forms, with or without
8    modification, are permitted provided that the following conditions are met:
9
10    * Redistributions of source code must retain the above copyright notice,
11      this list of conditions and the following disclaimer.
12    * Redistributions in binary form must reproduce the above copyright notice,
13      this list of conditions and the following disclaimer in the documentation
14      and/or other materials provided with the distribution.
15    * Neither the name of Julian Reschke nor the names of its contributors
16      may be used to endorse or promote products derived from this software
17      without specific prior written permission.
18
19    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29    POSSIBILITY OF SUCH DAMAGE.
30-->
31
32<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
33                version="1.0"
34                xmlns:ed="http://greenbytes.de/2002/rfcedit"
35                xmlns:grddl="http://www.w3.org/2003/g/data-view#"
36                xmlns:x="http://purl.org/net/xml2rfc/ext"
37                xmlns:xhtml="http://www.w3.org/1999/xhtml"
38                exclude-result-prefixes="ed grddl x xhtml"
39>
40
41<!-- re-use some of the default RFC2629.xslt rules -->
42<xsl:import href="rfc2629.xslt"/>
43
44<!-- undo strip-space decls -->
45<xsl:preserve-space elements="*"/>
46
47<!-- generate DTD-valid output, override all values imported from rfc2629.xslt -->
48<xsl:output doctype-system="rfc2629.dtd" doctype-public="" method="xml" version="1.0" encoding="UTF-8" cdata-section-elements="artwork" />
49
50<!-- kick into cleanup mode -->
51<xsl:template match="/">
52  <xsl:text>&#10;</xsl:text>
53  <xsl:comment>
54    This XML document is the output of clean-for-DTD.xslt; a tool that strips
55    extensions to RFC2629(bis) from documents for processing with xml2rfc.
56</xsl:comment>
57  <xsl:apply-templates select="/" mode="cleanup"/>
58</xsl:template>
59
60<!-- rules for identity transformations -->
61
62<xsl:template match="processing-instruction()" mode="cleanup">
63  <xsl:text>&#10;</xsl:text>
64  <xsl:copy><xsl:apply-templates select="node()|@*" mode="cleanup"/></xsl:copy>
65</xsl:template>
66
67<xsl:template match="comment()|@*" mode="cleanup"><xsl:copy/></xsl:template>
68
69<xsl:template match="text()" mode="cleanup"><xsl:copy/></xsl:template>
70
71<xsl:template match="/" mode="cleanup">
72        <xsl:copy><xsl:apply-templates select="node()" mode="cleanup" /></xsl:copy>
73</xsl:template>
74
75<xsl:template match="*" mode="cleanup">
76  <xsl:element name="{local-name()}">
77        <xsl:apply-templates select="node()|@*" mode="cleanup" />
78  </xsl:element>
79</xsl:template>
80
81
82<!-- remove PI extensions -->
83
84<xsl:template match="processing-instruction('rfc-ext')" mode="cleanup"/>
85
86<!-- add issues appendix -->
87
88<xsl:template match="back" mode="cleanup">
89  <back>
90    <xsl:apply-templates select="node()|@*" mode="cleanup" />
91    <xsl:if test="not(/*/@ed:suppress-issue-appendix='yes') and //ed:issue[@status='closed']">
92      <section title="Resolved issues (to be removed by RFC Editor before publication)">
93        <t>
94          Issues that were either rejected or resolved in this version of this
95          document.
96        </t>
97        <xsl:apply-templates select="//ed:issue[@status='closed']" mode="issues" />
98      </section>
99    </xsl:if>
100    <xsl:if test="not(/*/@ed:suppress-issue-appendix='yes') and //ed:issue[@status='open']">
101      <section title="Open issues (to be removed by RFC Editor prior to publication)">
102        <xsl:apply-templates select="//ed:issue[@status!='closed']" mode="issues" />
103      </section>
104    </xsl:if>
105  </back>
106</xsl:template>
107
108
109
110
111<!-- extensions -->
112
113<xsl:template match="x:anchor-alias" mode="cleanup"/>
114
115<xsl:template match="x:bcp14" mode="cleanup">
116  <xsl:apply-templates/>
117</xsl:template>
118
119<xsl:template match="x:assign-section-number" mode="cleanup"/> 
120<xsl:template match="x:link" mode="cleanup"/>
121<xsl:template match="x:source" mode="cleanup"/>
122
123<xsl:template match="x:ref" mode="cleanup">
124  <xsl:variable name="val" select="."/>
125  <xsl:variable name="target" select="//*[@anchor and (@anchor=$val or x:anchor-alias/@value=$val)]"/>
126  <xsl:choose>
127    <xsl:when test="$target">
128      <xsl:variable name="current" select="."/>
129      <xsl:for-each select="$target">
130        <!-- make it the context -->
131        <xsl:choose>
132          <xsl:when test="self::preamble">
133            <!-- it's not an element we can link to -->
134            <xsl:comment>clean-for-DTD.xslt warning: couldn't create the link as <xsl:value-of select="name()"/> does not support the anchor attribute.</xsl:comment>
135            <xsl:value-of select="$current"/>
136          </xsl:when>
137          <xsl:otherwise>
138            <xref target="{$target/@anchor}" format="none"><xsl:value-of select="$current"/></xref>
139          </xsl:otherwise>
140        </xsl:choose>
141      </xsl:for-each>
142    </xsl:when>
143    <xsl:otherwise>
144      <xsl:message>WARNING: internal link target for '<xsl:value-of select="."/>' does not exist.</xsl:message>
145      <xsl:value-of select="."/>
146    </xsl:otherwise>
147  </xsl:choose>
148</xsl:template>
149
150<xsl:template match="x:blockquote" mode="cleanup">
151  <t><list>
152    <xsl:apply-templates mode="cleanup" />
153  </list></t>
154</xsl:template>
155
156<xsl:template match="x:h" mode="cleanup">
157  <xsl:apply-templates mode="cleanup" />
158</xsl:template>
159
160<xsl:template match="x:lt" mode="cleanup">
161  <t>
162    <xsl:apply-templates select="@hangText|@anchor" mode="cleanup"/>
163    <xsl:for-each select="t">
164      <xsl:apply-templates mode="cleanup"/>
165      <xsl:if test="position()!=last()">
166        <vspace blankLines="1"/>
167      </xsl:if>
168    </xsl:for-each>
169  </t>
170</xsl:template>
171
172<xsl:template match="x:q" mode="cleanup">
173  <xsl:text>"</xsl:text>
174  <xsl:apply-templates mode="cleanup"/>
175  <xsl:text>"</xsl:text>
176</xsl:template>
177
178<xsl:template match="x:dfn" mode="cleanup">
179  <xsl:apply-templates mode="cleanup"/>
180</xsl:template>
181
182<!-- extended reference formatting -->
183
184<xsl:template match="xref[@x:* and not(node())]" mode="cleanup">
185  <xsl:variable name="node" select="$src//*[@anchor=current()/@target]" />
186  <xsl:variable name="sec">
187    <xsl:choose>
188      <xsl:when test="starts-with(@x:rel,'#') and not(@x:sec) and $node/x:source/@href">
189        <xsl:variable name="extdoc" select="document($node/x:source/@href)"/>
190        <xsl:for-each select="$extdoc//*[@anchor=substring-after(current()/@x:rel,'#')]">
191          <xsl:call-template name="get-section-number"/>
192        </xsl:for-each>
193      </xsl:when>
194      <xsl:otherwise>
195        <xsl:value-of select="@x:sec"/>
196      </xsl:otherwise>
197    </xsl:choose>
198  </xsl:variable>
199
200  <xsl:variable name="fmt">
201    <xsl:choose>
202      <xsl:when test="@x:fmt!=''"><xsl:value-of select="@x:fmt"/></xsl:when>
203      <xsl:when test="ancestor::artwork">,</xsl:when>
204      <xsl:otherwise>of</xsl:otherwise>
205    </xsl:choose>
206  </xsl:variable>
207
208  <xsl:choose>
209    <xsl:when test="$fmt=','">
210      <xref>
211        <xsl:apply-templates select="@target|@format|@pageno|text()|*" mode="cleanup"/>
212      </xref>
213      <xsl:text>, Section </xsl:text>
214      <xsl:value-of select="$sec"/>
215    </xsl:when>
216    <xsl:when test="$fmt='sec'">
217      <xsl:text>Section </xsl:text>
218      <xsl:value-of select="$sec"/>
219    </xsl:when>
220    <xsl:when test="$fmt='number'">
221      <xsl:value-of select="$sec"/>
222    </xsl:when>
223    <xsl:when test="$fmt='()'">
224      <xref>
225        <xsl:apply-templates select="@target|@format|@pageno|text()|*" mode="cleanup"/>
226      </xref>
227      <xsl:text> (Section </xsl:text>
228      <xsl:value-of select="$sec"/>
229      <xsl:text>)</xsl:text>
230    </xsl:when>
231    <xsl:when test="$fmt='of'">
232      <xsl:text>Section </xsl:text>
233      <xsl:value-of select="$sec"/>
234      <xsl:text> of </xsl:text>
235      <xref>
236        <xsl:apply-templates select="@target|@format|@pageno|text()|*" mode="cleanup"/>
237      </xref>
238    </xsl:when>
239    <xsl:when test="$fmt='anchor'">
240      <xsl:variable name="val">
241        <xsl:call-template name="referencename">
242          <xsl:with-param name="node" select="$node" />
243        </xsl:call-template>
244      </xsl:variable>
245      <!-- remove brackets -->
246      <xsl:value-of select="substring($val,2,string-length($val)-2)"/>
247    </xsl:when>
248    <xsl:otherwise>
249      <xsl:copy>
250        <xsl:apply-templates select="node()" mode="cleanup"/>
251      </xsl:copy>
252    </xsl:otherwise>
253  </xsl:choose>
254</xsl:template>
255
256<xsl:template match="xref[@x:fmt and node()]" mode="cleanup">
257  <xsl:choose>
258    <xsl:when test="@x:fmt='none'">
259      <xsl:apply-templates mode="cleanup"/>
260    </xsl:when>
261    <xsl:when test="not(@x:fmt)">
262      <xref>
263        <xsl:copy-of select="@target|@format"/>
264        <xsl:apply-templates mode="cleanup"/>
265      </xref>
266    </xsl:when>
267    <xsl:otherwise>
268      <xsl:message>Unsupported x:fmt attribute.</xsl:message>
269    </xsl:otherwise>
270  </xsl:choose>
271</xsl:template>
272
273<xsl:template match="xref[node() and @target=//preamble/@anchor]" mode="cleanup">
274  <!-- remove the link -->
275  <xsl:apply-templates select="node()" mode="cleanup"/>
276</xsl:template>
277
278<xsl:template match="xref[not(node()) and @target=//preamble/@anchor]" mode="cleanup">
279  <!-- fatal -->
280  <xsl:message>Broken xref due to target being filtered out.</xsl:message>
281</xsl:template>
282
283<!-- issue tracking extensions -->
284
285<xsl:template match="@xml:lang" mode="cleanup"/>
286<xsl:template match="@xml:lang" />
287
288<xsl:template match="ed:*" mode="cleanup"/>
289<xsl:template match="ed:*" />
290
291<xsl:template match="@ed:*" mode="cleanup"/>
292<xsl:template match="@ed:*" />
293
294<xsl:template match="ed:annotation" mode="cleanup" />
295
296<xsl:template match="ed:replace" mode="cleanup">
297  <xsl:apply-templates mode="cleanup" />
298</xsl:template>
299
300<xsl:template match="ed:replace">
301  <xsl:apply-templates/>
302</xsl:template>
303
304<xsl:template match="ed:ins" mode="cleanup">
305  <xsl:apply-templates mode="cleanup"/>
306</xsl:template>
307
308<xsl:template match="ed:ins">
309  <xsl:apply-templates/>
310</xsl:template>
311
312<xsl:template match="ed:issue" mode="issues">
313  <section title="{@name}">
314    <xsl:variable name="sec">
315      <xsl:call-template name="get-section-number"/>
316    </xsl:variable>
317
318    <xsl:if test="$sec!=''">
319      <t>
320        In Section <xsl:value-of select="$sec"/>:
321      </t>
322    </xsl:if>
323   
324    <t>
325      Type: <xsl:value-of select="@type" />
326    </t>
327    <xsl:if test="@href">
328      <t>
329        <!-- temp. removed because of xml2rfc's handling of erefs when producing TXT-->
330        <!--<eref target="{@href}" /> -->
331        <xsl:text>&lt;</xsl:text>
332        <xsl:value-of select="@href"/>
333        <xsl:text>></xsl:text>
334        <xsl:if test="@alternate-href">
335          <xsl:text>, &lt;</xsl:text>
336          <xsl:value-of select="@alternate-href"/>
337          <xsl:text>></xsl:text>
338        </xsl:if>
339      </t>
340    </xsl:if>
341    <xsl:for-each select="ed:item">
342      <t>
343        <xsl:if test="@entered-by or @date">
344          <xsl:choose>
345            <xsl:when test="not(@entered-by)">
346              <xsl:value-of select="concat('(',@date,') ')" />
347            </xsl:when>
348            <xsl:when test="not(@date)">
349              <xsl:value-of select="concat(@entered-by,': ')" />
350            </xsl:when>
351            <xsl:otherwise>
352              <xsl:value-of select="concat(@entered-by,' (',@date,'): ')" />
353            </xsl:otherwise>
354          </xsl:choose>     
355        </xsl:if>
356        <xsl:if test="not(xhtml:p)">
357          <xsl:apply-templates select="node()" mode="issues"/>
358        </xsl:if>
359      </t>
360      <xsl:if test="xhtml:p|xhtml:pre">
361        <xsl:for-each select="node()">
362          <xsl:choose>
363            <xsl:when test="self::xhtml:p">
364              <t>
365                <xsl:apply-templates select="node()" mode="issues"/>
366              </t>
367            </xsl:when>
368            <xsl:when test="self::xhtml:pre">
369              <figure>
370                <artwork><xsl:apply-templates select="node()" mode="issues"/></artwork>
371              </figure>
372            </xsl:when>
373            <xsl:otherwise>
374              <t>
375                <xsl:apply-templates select="." mode="issues"/>
376              </t>
377            </xsl:otherwise>
378          </xsl:choose>
379        </xsl:for-each>
380      </xsl:if>
381    </xsl:for-each>
382    <xsl:if test="ed:resolution">
383      <t>
384        <xsl:text>Resolution</xsl:text>
385        <xsl:if test="ed:resolution/@datetime"> (<xsl:value-of select="ed:resolution/@datetime"/>)</xsl:if>
386        <xsl:text>: </xsl:text>
387        <xsl:value-of select="ed:resolution" />
388      </t>
389    </xsl:if>
390  </section>
391</xsl:template>
392
393<xsl:template match="ed:issueref" mode="cleanup">
394  <xsl:apply-templates mode="cleanup"/>
395</xsl:template>
396
397<xsl:template match="*" mode="issues">
398  <xsl:apply-templates mode="issues"/>
399</xsl:template>
400
401<xsl:template match="xhtml:q" mode="issues">
402  <list><t>
403    <xsl:text>"</xsl:text>
404    <xsl:apply-templates mode="issues"/>
405    <xsl:text>"</xsl:text>
406    <xsl:if test="@cite">
407      <xsl:text> -- </xsl:text>
408      <eref target="{@cite}"><xsl:value-of select="@cite"/></eref>
409    </xsl:if>
410  </t></list>
411</xsl:template>
412
413<xsl:template match="xhtml:br" mode="issues">
414  <vspace/>
415</xsl:template>
416
417<xsl:template match="xhtml:del" mode="issues">
418  <xsl:text>&lt;del></xsl:text>
419    <xsl:apply-templates mode="issues"/>
420  <xsl:text>&lt;/del></xsl:text>
421</xsl:template>
422
423<xsl:template match="xhtml:em" mode="issues">
424  <spanx style="emph">
425    <xsl:apply-templates mode="issues"/>
426  </spanx>
427</xsl:template>
428
429<xsl:template match="xhtml:ins" mode="issues">
430  <xsl:text>&lt;ins></xsl:text>
431    <xsl:apply-templates mode="issues"/>
432  <xsl:text>&lt;/ins></xsl:text>
433</xsl:template>
434
435<xsl:template match="xhtml:tt" mode="issues">
436  <xsl:apply-templates mode="issues"/>
437</xsl:template>
438
439<xsl:template match="ed:eref" mode="issues">
440  <xsl:text>&lt;</xsl:text>
441  <xsl:value-of select="."/>
442  <xsl:text>&gt;</xsl:text>
443</xsl:template>
444
445<xsl:template match="ed:issueref" mode="issues">
446  <xsl:apply-templates mode="issues"/>
447</xsl:template>
448
449<xsl:template match="text()" mode="issues">
450  <xsl:value-of select="." />
451</xsl:template>
452
453
454
455<!-- markup inside artwork element -->
456
457<xsl:template match="figure[.//artwork//iref]" mode="cleanup">
458  <!-- move up iref elements -->
459  <figure>
460    <xsl:apply-templates select="@*" mode="cleanup" />
461    <xsl:apply-templates select=".//artwork//iref" mode="cleanup"/>
462    <xsl:apply-templates select="iref|preamble|artwork|postamble" mode="cleanup" />
463  </figure>
464</xsl:template>
465
466<xsl:template match="artwork" mode="cleanup">
467  <xsl:variable name="content"><xsl:apply-templates select="."/></xsl:variable>
468  <artwork>
469    <xsl:apply-templates select="@*" mode="cleanup" />
470    <xsl:if test="starts-with(.,'&#10;')">
471      <xsl:text>&#10;</xsl:text>
472    </xsl:if>
473    <xsl:value-of select="translate($content,'&#160;&#x2500;&#x2502;&#x2508;&#x250c;&#x2510;&#x2514;&#x2518;&#x251c;&#x2524;',' -|+++++++')"/>
474  </artwork> 
475</xsl:template>
476
477
478
479<!-- artwork extensions -->
480<xsl:template match="artwork/@x:extraction-note" mode="cleanup"/>
481
482<!-- list formatting -->
483<xsl:template match="list/@x:indent" mode="cleanup"/>
484
485<!-- referencing extensions -->
486<xsl:template match="iref/@x:for-anchor" mode="cleanup"/>
487
488<!-- table styles -->
489<xsl:template match="texttable/@style" mode="cleanup"/>
490
491<!-- anchor extensions -->
492<xsl:template match="preamble/@anchor" mode="cleanup"/>
493
494<!-- section numbering -->
495<xsl:template match="section/@x:fixed-section-number" mode="cleanup"/>
496
497<!-- GRRDL info stripped -->
498<xsl:template match="@grddl:transformation" mode="cleanup"/>
499
500</xsl:transform>
Note: See TracBrowser for help on using the repository browser.