-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxep2texml.xsl
451 lines (391 loc) · 14.4 KB
/
xep2texml.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:str="http://xsltsl.org/string">
<!--
* Copyright (c) 2008 - 2017 Tobias Markmann
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TOBIAS MARKMANN ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL TOBIAS MARKMANN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Thanks to the XSLT Standard Library http://xsltsl.sourceforge.net/.
-->
<!--<xsl:include href="xsltsl/string.xsl"/>-->
<xsl:import href="texml-xsl/stdlib.xsl"/>
<!-- Create a variable named $maxXEPVersiom containing the MAX version -->
<xsl:variable name="maxXEPVersion">
<xsl:value-of select='/xep/header/revision[position()=1]/version'/>
</xsl:variable>
<!-- Create a variable named $maxXEPDate containing the MAX date -->
<xsl:variable name="maxXEPDate">
<xsl:for-each select="/xep/header/revision">
<xsl:sort select="date" data-type="text" order="descending" />
<xsl:if test="position() = 1">
<xsl:value-of select="date" />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- Format URLs for the front page. Putting too long URLs in the footnotes. -->
<xsl:template name="formatURL">
<xsl:param name="url"/>
<xsl:choose>
<xsl:when test="string-length($url) > 80">
<cmd name="thanks"><parm><cmd name="url"><parm><xsl:value-of select="$url"/></parm></cmd></parm></cmd> \hspace{0.5 cm}
</xsl:when>
<xsl:otherwise>
<cmd name="url"><parm><xsl:value-of select="$url"/></parm></cmd> \\
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- convert "document": create header and continue -->
<xsl:template match="xep">
<TeXML>
<!-- create header -->
<TeXML escape="0">
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[DIV=10]{scrartcl}
\KOMAoptions{paper=a4}
\usepackage[
pdftitle={XEP-<xsl:value-of select="/xep/header/number"/>: <xsl:value-of select="/xep/header/title"/>},
pdfauthor={XMPP Standards Foundation},
pdfcreator={XEP2PDF},
pdfproducer={XEP2PDF},
breaklinks = true,
unicode,
pagebackref,
xetex]{hyperref}
% break URLs at more places
\renewcommand{\UrlBreaks}{\do\/\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X\do\Y\do\Z\do\0\do\1}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{tabu}
\usepackage{longtable}
\usepackage{listings}
\usepackage{varwidth}
\usepackage{titling}
\usepackage{titletoc}
\usepackage{float}
\usepackage{adjustbox}
\usepackage{hyphenat}
\hypersetup{colorlinks, linkcolor=blue, anchorcolor=blue, urlcolor=blue}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont[Ligatures={Common}]{Gentium Basic}
\setsansfont[Scale=MatchLowercase]{Gentium Basic}
\setmonofont[Scale=MatchLowercase]{Inconsolata}
\setkomafont{descriptionlabel}{\normalfont\bfseries}
\usepackage[english]{babel}
\pagestyle{fancy}
\fancyfoot{}
\fancyhead{}
%% page numbering
\newcommand{\XEPNumber}[0]{<xsl:value-of select="/xep/header/number"/>}
\newcommand{\XEPVersion}[0]{<xsl:value-of select="$maxXEPVersion"/>}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\fancyhead[L,L]{\includegraphics[totalheight=10pt]{xmpp.pdf} \slshape \leftmark}
\fancyfoot[C,C]{\thepage}
\pretitle{
\begin{figure*}[h]
\begin{center}
\includegraphics[totalheight=7.5cm]{xmpp-text.pdf}
\end{center}
\end{figure*}
\begin{center}\LARGE
}
\sloppy
</TeXML>
<cmd name="title" nl2="1">
<parm>XEP-<cmd name="XEPNumber" />: <xsl:value-of select="/xep/header/title"/></parm>
</cmd>
<cmd name="author">
<parm><TeXML escape="0">
<xsl:for-each select='/xep/header/author'><xsl:value-of select="firstname"/><xsl:text> </xsl:text><xsl:value-of select="surname"/> \\
<xsl:if test="email"><xsl:call-template name="formatURL"><xsl:with-param name="url">mailto:<xsl:value-of select="email"/></xsl:with-param></xsl:call-template></xsl:if>
<xsl:if test="jid"><xsl:call-template name="formatURL"><xsl:with-param name="url">xmpp:<xsl:value-of select="jid"/></xsl:with-param></xsl:call-template></xsl:if>
<xsl:if test="uri"><xsl:call-template name="formatURL"><xsl:with-param name="url"><xsl:value-of select="uri"/></xsl:with-param></xsl:call-template></xsl:if> <xsl:if test='position() != last()'> \and </xsl:if>
</xsl:for-each>
</TeXML></parm>
</cmd>
<cmd name="date">
<parm><TeXML escape="0"><xsl:value-of select="$maxXEPDate"/>\\ Version <xsl:value-of select="$maxXEPVersion"/></TeXML></parm>
</cmd>
<!-- process content -->
<env name="document">
<TeXML escape="0">
<cmd name="lstset">
<parm>language=XML,
breaklines=true,
emptylines=5,
frame=single,
rulecolor=\color{black},
basicstyle=\ttfamily\small\color{darkgray},
keywordstyle=\color{cyan},
stringstyle=\color{blue},
tagstyle=\color{purple},
markfirstintag=true
</parm>
</cmd>
</TeXML>
<cmd name="KOMAoptions"><parm>DIV=24</parm></cmd>
<cmd name="pagestyle"><parm>empty</parm></cmd>
<cmd name="maketitle" />
<cmd name="thispagestyle"><parm>empty</parm></cmd>
<env name="center">
<env name="tabular"><parm>ccc</parm>
<TeXML escape="0">
<cmd name="textbf"><parm>Status</parm></cmd> & <cmd name="textbf"><parm>Type</parm></cmd> & <cmd name="textbf"><parm>Short Name</parm></cmd> \\
<xsl:value-of select="/xep/header/status"/> & <xsl:value-of select="/xep/header/type"/> & <TeXML escape="1"><xsl:value-of select="/xep/header/shortname"/></TeXML>
</TeXML>
</env>
</env>
<env name="abstract">
<xsl:value-of select="/xep/header/abstract"/>
</env>
<cmd name="newpage" nl2="1"/>
<TeXML escape="0">
\fancyhead[L,L]{\includegraphics[totalheight=10pt]{xmpp.pdf} \slshape \leftmark}
\fancyfoot[C,C]{\thepage}
</TeXML>
<cmd name="KOMAoptions"><parm>DIV=10</parm></cmd>
<cmd name="section*" nl2="1"><parm>Legal</parm></cmd>
<xsl:apply-templates select="/xep/header/legal" />
<cmd name="newpage" nl2="1"/>
<cmd name="tableofcontents" nl2="1"/>
<cmd name="newpage" nl2="1"/>
<cmd name="pagestyle" nl2="1"><parm>fancy</parm></cmd>
<cmd name="setcounter" nl2="1"><parm>page</parm><parm>1</parm></cmd>
<xsl:apply-templates/>
</env>
</TeXML>
</xsl:template>
<!-- for legal crap -->
<xsl:template match="copyright">
<cmd name="subsection*" nl2="1"><parm>Copyright</parm></cmd>
<group><cmd name="small" />
<xsl:apply-templates/>
</group>
</xsl:template>
<xsl:template match="permissions">
<cmd name="subsection*" nl2="1"><parm>Permissions</parm></cmd>
<group><cmd name="small" />
<xsl:apply-templates/>
</group>
</xsl:template>
<xsl:template match="warranty">
<cmd name="subsection*" nl2="1"><parm>Warranty</parm></cmd>
<group><cmd name="small" />
<xsl:apply-templates/>
</group>
</xsl:template>
<xsl:template match="liability">
<cmd name="subsection*"><parm>Liability</parm></cmd>
<group><cmd name="small" />
<xsl:apply-templates/>
</group>
</xsl:template>
<xsl:template match="conformance">
<cmd name="subsection*"><parm>Conformance</parm></cmd>
<group><cmd name="small" />
<xsl:apply-templates/>
</group>
</xsl:template>
<xsl:template match="header">
</xsl:template>
<!-- table -->
<xsl:template match='table'>
<TeXML escape="0">
<env name="center">
<env name='longtabu'>
<parm><xsl:for-each select='tr[1]/th | tr[1]/td'><xsl:if test="position() = 1">l</xsl:if><xsl:if test='position() != last() and position() > 1'>X</xsl:if><xsl:if test='position() = last()'>X</xsl:if></xsl:for-each></parm>
<xsl:for-each select='tr'>
<xsl:for-each select='td | th'><xsl:if test='position() > 1'> & </xsl:if><TeXML escape="1"><xsl:value-of select='.'/></TeXML><xsl:if test='position() = last()'> \\</xsl:if></xsl:for-each>
<xsl:if test="position() = 1">
\hline
\hline
\endhead
</xsl:if>
</xsl:for-each>
</env>
</env>
</TeXML>
</xsl:template>
<!-- link -->
<xsl:template match="span">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="link">
<xsl:variable name="isHTTP">
<xsl:call-template name="str:string-match">
<xsl:with-param name="text"><xsl:value-of select="text()"/></xsl:with-param>
<xsl:with-param name="pattern">*http*</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="isInternal">
<xsl:call-template name="str:string-match">
<xsl:with-param name="text"><xsl:value-of select="@url"/></xsl:with-param>
<xsl:with-param name="pattern">#*</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$isInternal = 0">
<cmd name="href">
<parm>
<TeXML escape="0"><xsl:value-of select='@url'/></TeXML>
</parm>
<parm>
<xsl:if test="$isHTTP = 1">
<cmd name="url"><parm><xsl:apply-templates/></parm></cmd>
</xsl:if>
<xsl:if test="$isHTTP = 0">
<xsl:apply-templates/>
</xsl:if>
</parm>
</cmd>
</xsl:if>
<xsl:if test="$isInternal = 1">
<cmd name="hyperref">
<opt><TeXML escape="0"><xsl:value-of select='@url'/></TeXML></opt>
<parm><xsl:apply-templates/></parm>
</cmd>
<!--<TeXML escape="0"> { </TeXML><cmd name="footnotesize" /><cmd name="pageref"><parm><TeXML escape="0"><xsl:value-of select='@url'/></TeXML></parm></cmd><TeXML escape="0"> } </TeXML>-->
</xsl:if>
</xsl:template>
<!-- note -->
<xsl:template match="note">
<cmd name="footnote"><parm><xsl:apply-templates/></parm></cmd>
</xsl:template>
<!-- em -->
<xsl:template match="em">
<cmd name="emph"><parm><xsl:apply-templates/></parm></cmd>
</xsl:template>
<!-- strong -->
<xsl:template match="strong">
<cmd name="textbf"><parm><xsl:apply-templates/></parm></cmd>
</xsl:template>
<!-- sub -->
<xsl:template match="sub">
<math><cmd name="textsuperscript"><parm><xsl:apply-templates/></parm></cmd></math>
</xsl:template>
<!-- span[@class='super'] -->
<xsl:template match="span[@class='super']">
<math><spec cat="sup"/><spec cat="bg"/><xsl:apply-templates/><spec cat="eg"/></math>
</xsl:template>
<!-- p -->
<xsl:template match="p">
<xsl:apply-templates/><TeXML escape="0" emptylines="1"><xsl:text>\\
</xsl:text></TeXML>
</xsl:template>
<!-- li -->
<xsl:template match="li">
<TeXML escape="1" emptylines="1">
<cmd name="item" /> <xsl:apply-templates/><xsl:text>
</xsl:text>
</TeXML>
</xsl:template>
<!-- ul -->
<xsl:template match="ul">
<env name="itemize">
<xsl:apply-templates/>
</env>
</xsl:template>
<!-- ol -->
<xsl:template match="ol">
<env name="enumerate">
<xsl:apply-templates/>
</env>
</xsl:template>
<!-- dl -->
<xsl:template match="dl">
<env name="description">
<xsl:apply-templates/>
</env>
</xsl:template>
<!-- di -->
<xsl:template match="di">
<TeXML escape="1" emptylines="1">
<cmd name="item"><opt><xsl:value-of select="./dt" /></opt></cmd>
<xsl:text>
</xsl:text>
<xsl:value-of select="./dd" />
</TeXML>
</xsl:template>
<!-- example -->
<xsl:template match="example">
<env name="lstlisting">
<opt>caption=<group><TeXML escape="1"><xsl:value-of select="@caption"/></TeXML></group></opt>
<TeXML escape="0" emptylines="1">
<xsl:apply-templates />
</TeXML>
</env>
</xsl:template>
<xsl:template match="br">
<!--<cmd name="newline" gr="0"/>-->
</xsl:template>
<!-- code -->
<xsl:template match="code">
<xsl:if test='@class = "inline"'>
<cmd name='path'><parm><TeXML escape="0"><xsl:value-of select="."/></TeXML></parm></cmd>
</xsl:if>
<xsl:if test='not(@class)'>
<env name="lstlisting">
<TeXML escape="0" emptylines="1" ligatures="1">
<xsl:value-of select="."/>
</TeXML>
</env>
</xsl:if>
</xsl:template>
<!-- img -->
<xsl:template match="img">
<env name="figure"><opt>H</opt>
<cmd name="centering" />
<cmd name="adjustimage"><parm><TeXML escape="0">max size={.9\textwidth}{.9\textheight}</TeXML></parm><parm>inlineimage-<xsl:value-of select="/xep/header/number" />-<xsl:value-of select="count(preceding::img)" /></parm></cmd>
</env>
</xsl:template>
<!-- section3 -->
<xsl:template match="section3">
<cmd name="subsubsection" nl2="1">
<parm><xsl:text></xsl:text><xsl:value-of select="@topic"/></parm>
</cmd>
<cmd name="label">
<parm><TeXML escape="0"><xsl:value-of select="@anchor" /></TeXML></parm>
</cmd>
<xsl:apply-templates />
</xsl:template>
<!-- section2 -->
<xsl:template match="section2">
<cmd name="subsection" nl2="1">
<parm><xsl:text></xsl:text><xsl:value-of select="@topic"/></parm>
</cmd>
<cmd name="label">
<parm><TeXML escape="0"><xsl:value-of select="@anchor" /></TeXML></parm>
</cmd>
<xsl:apply-templates />
</xsl:template>
<!-- section1 -->
<xsl:template match="section1">
<cmd name="section" nl2="1">
<parm><xsl:text></xsl:text><xsl:value-of select="@topic"/></parm>
</cmd>
<cmd name="label" nl2="1">
<parm><TeXML escape="0"><xsl:value-of select="@anchor" /></TeXML></parm>
</cmd>
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>