Accept attributes in inline image syntax
[multimarkdown] / XSLT / sffms.xslt
1 <?xml version='1.0' encoding='utf-8'?>
2
3 <!-- XHTML-to-SFFMS converter by Fletcher Penney
4         specifically designed for use with MultiMarkdown created XHTML
5
6         Uses the SFFMS class for output:
7         
8                 http://www.mcdemarco.net/sffms/
9         
10         MultiMarkdown Version 2.0.b5
11         
12         $Id: sffms.xslt 479 2008-01-12 23:04:13Z fletcher $
13 -->
14
15 <!-- 
16 # Copyright (C) 2005-2008  Fletcher T. Penney <fletcher@fletcherpenney.net>
17 #
18 # This program is free software; you can redistribute it and/or modify
19 # it under the terms of the GNU General Public License as published by
20 # the Free Software Foundation; either version 2 of the License, or
21 # (at your option) any later version.
22 #
23 # This program is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 # GNU General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write to the
30 #    Free Software Foundation, Inc.
31 #    59 Temple Place, Suite 330
32 #    Boston, MA 02111-1307 USA
33 -->
34
35         
36 <xsl:stylesheet
37         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
38         xmlns:html="http://www.w3.org/1999/xhtml"
39         version="1.0">
40
41         <xsl:import href="xhtml2latex.xslt"/>
42         
43         <xsl:template match="/">
44                 <xsl:apply-templates select="html:html/html:head"/>
45                 <xsl:apply-templates select="html:html/html:body"/>
46                 <xsl:call-template name="latex-footer"/>
47         </xsl:template>
48
49         <xsl:template name="latex-footer">
50                 <xsl:text>\end{document}
51 </xsl:text>
52         </xsl:template>
53
54         <xsl:template name="latex-document-class">
55                 <xsl:text>\documentclass[courier,novel]{sffms}
56 </xsl:text>
57         </xsl:template>
58
59         <xsl:template name="latex-paper-size">
60                 <xsl:text></xsl:text>
61         </xsl:template>
62
63                 <xsl:template name="latex-intro">
64                         <xsl:text>
65 \begin{document}
66
67 </xsl:text>
68                 </xsl:template>
69                 
70                 <xsl:template name="latex-title">
71                         <xsl:text></xsl:text>
72         </xsl:template>
73
74         <xsl:template name="latex-copyright">
75                         <xsl:text></xsl:text>
76         </xsl:template>
77
78         <xsl:template name="latex-begin-body">
79                 <xsl:text></xsl:text>
80         </xsl:template>
81
82         <xsl:template name="latex-header">
83         </xsl:template>
84
85         <!-- Rename Bibliography -->
86         <xsl:template name="rename-bibliography">
87         </xsl:template>
88
89         <!-- Convert headers into chapters, etc -->
90         
91         <xsl:template match="html:h1">
92                 <xsl:text>\chapter*{</xsl:text>
93                 <xsl:apply-templates select="node()"/>
94                 <xsl:text>}</xsl:text>
95                 <xsl:value-of select="$newline"/>
96                 <xsl:text>\label{</xsl:text>
97                 <xsl:value-of select="@id"/>
98                 <xsl:text>}</xsl:text>
99                 <xsl:value-of select="$newline"/>
100                 <xsl:value-of select="$newline"/>
101         </xsl:template>
102
103         <xsl:template match="html:h2">
104                 <xsl:text>\chapter{</xsl:text>
105                 <xsl:apply-templates select="node()"/>
106                 <xsl:text>}</xsl:text>
107                 <xsl:value-of select="$newline"/>
108                 <xsl:text>\label{</xsl:text>
109                 <xsl:value-of select="@id"/>
110                 <xsl:text>}</xsl:text>
111                 <xsl:value-of select="$newline"/>
112                 <xsl:value-of select="$newline"/>
113         </xsl:template>
114
115         <xsl:template match="html:h3">
116                 <xsl:text>\newscene
117
118 </xsl:text>
119                 
120         </xsl:template>
121
122         <xsl:template match="html:h4">
123         </xsl:template>
124
125         <xsl:template match="html:h5">
126         </xsl:template>
127
128         <xsl:template match="html:h6">
129         </xsl:template>
130
131
132                 <!-- code block -->
133                 <xsl:template match="html:pre/html:code">
134                         <xsl:text>\begin{verbatim}
135
136         </xsl:text>
137                         <xsl:value-of select="."/>
138                         <xsl:text>
139         \end{verbatim}
140
141         </xsl:text>
142                 </xsl:template>
143
144         <xsl:template match="*[local-name() = 'title']">
145                 <xsl:text>\title{</xsl:text>
146                         <xsl:call-template name="clean-text">
147                                 <xsl:with-param name="source">
148                                         <xsl:value-of select="."/>
149                                 </xsl:with-param>
150                         </xsl:call-template>            
151                 <xsl:text>}
152 </xsl:text>
153         </xsl:template>
154
155         <xsl:template match="html:meta">
156                 <xsl:choose>
157                         <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
158                         'abcdefghijklmnopqrstuvwxyz') = 'author'">
159                                 <xsl:text>\author{</xsl:text>
160                                 <xsl:call-template name="clean-text">
161                                         <xsl:with-param name="source">
162                                                 <xsl:value-of select="@content"/>
163                                         </xsl:with-param>
164                                 </xsl:call-template>            
165                                 <xsl:text>}
166 </xsl:text>
167                         </xsl:when>
168                         <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
169                         'abcdefghijklmnopqrstuvwxyz') = 'authorname'">
170                                 <xsl:text>\authorname{</xsl:text>
171                                 <xsl:call-template name="clean-text">
172                                         <xsl:with-param name="source">
173                                                 <xsl:value-of select="@content"/>
174                                         </xsl:with-param>
175                                 </xsl:call-template>            
176                                 <xsl:text>}
177 </xsl:text>
178                         </xsl:when>
179                         <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
180                         'abcdefghijklmnopqrstuvwxyz') = 'title'">
181                                 <xsl:text>\title{</xsl:text>
182                                 <xsl:call-template name="replace-substring">
183                                         <!-- put line breaks in -->
184                                         <xsl:with-param name="original">
185                                                 <xsl:call-template name="clean-text">
186                                                         <xsl:with-param name="source">
187                                                                 <xsl:value-of select="@content"/>
188                                                         </xsl:with-param>
189                                                 </xsl:call-template>            
190                                         </xsl:with-param>
191                                         <xsl:with-param name="substring">
192                                                 <xsl:text>   </xsl:text>
193                                         </xsl:with-param>
194                                         <xsl:with-param name="replacement">
195                                                 <xsl:text> \\ </xsl:text>
196                                         </xsl:with-param>
197                                 </xsl:call-template>
198                                 <xsl:text>}
199 </xsl:text>
200                         </xsl:when>
201                         <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
202                         'abcdefghijklmnopqrstuvwxyz') = 'runningtitle'">
203                                 <xsl:text>\runningtitle{</xsl:text>
204                                 <xsl:call-template name="clean-text">
205                                         <xsl:with-param name="source">
206                                                 <xsl:value-of select="@content"/>
207                                         </xsl:with-param>
208                                 </xsl:call-template>            
209                                 <xsl:text>}
210 </xsl:text>
211                         </xsl:when>
212                         <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
213                         'abcdefghijklmnopqrstuvwxyz') = 'surname'">
214                                 <xsl:text>\surname{</xsl:text>
215                                 <xsl:call-template name="clean-text">
216                                         <xsl:with-param name="source">
217                                                 <xsl:value-of select="@content"/>
218                                         </xsl:with-param>
219                                 </xsl:call-template>            
220                                 <xsl:text>}
221 </xsl:text>
222                         </xsl:when>
223                         <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
224                         'abcdefghijklmnopqrstuvwxyz') = 'address'">
225                                 <xsl:text>\address{</xsl:text>
226                                 <xsl:call-template name="replace-substring">
227                                         <!-- put line breaks in -->
228                                         <xsl:with-param name="original">
229                                                 <xsl:call-template name="clean-text">
230                                                         <xsl:with-param name="source">
231                                                                 <xsl:value-of select="@content"/>
232                                                         </xsl:with-param>
233                                                 </xsl:call-template>            
234                                         </xsl:with-param>
235                                         <xsl:with-param name="substring">
236                                                 <xsl:text>   </xsl:text>
237                                         </xsl:with-param>
238                                         <xsl:with-param name="replacement">
239                                                 <xsl:text> \\ </xsl:text>
240                                         </xsl:with-param>
241                                 </xsl:call-template>
242                                 <xsl:text>}
243 </xsl:text>
244                         </xsl:when>
245                         <xsl:when test="translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
246                         'abcdefghijklmnopqrstuvwxyz') = 'wordcount'">
247                                 <xsl:text>\wordcount{</xsl:text>
248                                 <xsl:call-template name="clean-text">
249                                         <xsl:with-param name="source">
250                                                 <xsl:value-of select="@content"/>
251                                         </xsl:with-param>
252                                 </xsl:call-template>            
253                                 <xsl:text>}
254 </xsl:text>
255                         </xsl:when>
256                 </xsl:choose>
257         </xsl:template>
258
259
260         <!-- Changes due to limitations of manuscript format -->
261         <xsl:template match="html:a[@href]">
262                 <xsl:value-of select="."/>
263                 <xsl:text>(</xsl:text>
264                 <xsl:call-template name="clean-text">
265                         <xsl:with-param name="source">
266                                 <xsl:value-of select="@href"/>
267                         </xsl:with-param>
268                 </xsl:call-template>            
269                 <xsl:text>)</xsl:text>
270         </xsl:template>
271
272         <!-- emphasis -->
273         <xsl:template match="html:em">
274                 <xsl:text>\underline{</xsl:text>
275                         <xsl:apply-templates select="node()"/>
276                 <xsl:text>}</xsl:text>
277         </xsl:template>
278
279         <!-- strong -->
280         <xsl:template match="html:strong">
281                 <xsl:text>\textbf{</xsl:text>
282                         <xsl:apply-templates select="node()"/>
283                 <xsl:text>}</xsl:text>
284         </xsl:template>
285
286 </xsl:stylesheet>