source: rfc2629xslt/xsl11toFop.xslt @ 22

Last change on this file since 22 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: 5.4 KB
Line 
1<!--
2    Transform XSL 1.1 extensions to FOP extensions
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               xmlns:fo="http://www.w3.org/1999/XSL/Format"
34               xmlns:fox="http://xml.apache.org/fop/extensions"
35               version="1.0"
36>
37
38<!-- transform bookmark elements -->
39
40<xsl:template match="fo:bookmark-tree" >
41  <xsl:apply-templates/>
42</xsl:template>
43
44<xsl:template match="fo:bookmark" >
45  <fox:outline internal-destination="{@internal-destination}">
46    <xsl:apply-templates/>
47  </fox:outline>
48</xsl:template>
49
50<xsl:template match="fo:bookmark-title" >
51  <fox:label>
52    <xsl:apply-templates/>
53  </fox:label>
54</xsl:template>
55
56
57<!-- work around for missing page break stuff -->
58
59<xsl:template match="fo:block[@page-break-before='always']">
60  <xsl:copy>
61    <xsl:attribute name="break-before">page</xsl:attribute>
62    <xsl:attribute name="keep-with-previous">auto</xsl:attribute>
63    <xsl:apply-templates select="@*[not(name()='page-break-before') and not(name()='id')]" />
64    <xsl:apply-templates select="@id" />
65    <xsl:apply-templates select="node()" />
66  </xsl:copy>
67</xsl:template>
68
69<!-- work around weird list item behaviour -->
70
71<xsl:template match="fo:list-item-body/fo:block[not(node())]">
72  <xsl:copy>
73    <xsl:apply-templates select="@*"/>
74    <!-- add NBSP so the block is not empty -->
75    <xsl:text>&#160;</xsl:text>
76  </xsl:copy>
77</xsl:template>
78
79<!-- add destination elements where IDs are defined -->
80<xsl:template match="@id">
81  <xsl:copy-of select="."/>
82  <fox:destination internal-destination="{.}"/>
83</xsl:template>
84
85<xsl:template match="fo:list-item/@id">
86  <!-- dunno how to in list items, so move into list-item-body -->
87</xsl:template>
88
89<xsl:template match="fo:list-item[@id]/fo:list-item-body">
90  <xsl:copy>
91    <xsl:attribute name="id"><xsl:value-of select="../@id"/></xsl:attribute>
92    <xsl:apply-templates select="@*|node()"/>
93  </xsl:copy>
94</xsl:template>
95
96<!-- index-page-citation-list -->
97
98<xsl:attribute-set name="internal-link">
99  <xsl:attribute name="color">#000080</xsl:attribute>
100</xsl:attribute-set>
101
102<xsl:template match="fo:index-page-citation-list">
103  <xsl:variable name="items" select="fo:index-key-reference"/>
104  <xsl:variable name="entries" select="//*[@index-key=$items/@ref-index-key]"/>
105  <xsl:for-each select="$entries">
106    <fo:basic-link internal-destination="{ancestor-or-self::*/@id}" xsl:use-attribute-sets="internal-link">
107      <xsl:if test="contains(@index-key,',primary') and substring-after(@index-key,',primary')=''">
108        <xsl:attribute name="font-weight">bold</xsl:attribute>
109      </xsl:if>
110      <fo:page-number-citation ref-id="{ancestor-or-self::*/@id}"/>
111      <xsl:if test="not(ancestor-or-self::*/@id)">
112        <xsl:message>WARNING: No ID found for <xsl:value-of select="@index-key"/>.</xsl:message>
113      </xsl:if>
114    </fo:basic-link>
115    <xsl:if test="position()!=last()"><xsl:text>, </xsl:text></xsl:if>
116  </xsl:for-each>
117</xsl:template>
118
119<!-- suppress and map-->
120<xsl:template match="@index-key" />
121<xsl:template match="fo:index-range-end" />
122<xsl:template match="fo:index-range-begin">
123  <fo:wrapper id="{@id}"/>
124</xsl:template>
125
126<!-- remove stuff not understood -->
127<xsl:template match="@page-break-inside"/>
128
129<!-- remove third-party extensions -->
130
131<xsl:template match="*[namespace-uri()!='http://www.w3.org/1999/XSL/Format' and namespace-uri()!='http://xml.apache.org/fop/extensions']" />
132<xsl:template match="@*[namespace-uri()!='' and namespace-uri()!='http://www.w3.org/1999/XSL/Format' and namespace-uri()!='http://xml.apache.org/fop/extensions']" />
133
134
135
136<xsl:template match="node()|@*">
137  <xsl:copy>
138    <xsl:apply-templates select="@*[not(name()='id')]" />
139    <xsl:apply-templates select="@id" />
140    <xsl:apply-templates select="node()" />
141  </xsl:copy>
142</xsl:template>
143
144<xsl:template match="/">
145        <xsl:copy><xsl:apply-templates select="node()" /></xsl:copy>
146</xsl:template>
147
148</xsl:transform>
Note: See TracBrowser for help on using the repository browser.