No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xep2texml.xsl 14KB

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