tutorial.xsl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  3. <!--
  4. Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <xsl:output method="text"/>
  9. <xsl:strip-space elements="*"/>
  10. <xsl:variable name="newline">
  11. <xsl:text>
  12. </xsl:text>
  13. </xsl:variable>
  14. <xsl:template match="/doxygen">
  15. <xsl:text>[/
  16. / Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  17. /
  18. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  19. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  20. /]
  21. [section:tutorial Tutorial]
  22. </xsl:text>
  23. <xsl:for-each select="compounddef[@kind = 'page' and @id = 'indexpage']">
  24. <xsl:apply-templates select="detaileddescription"/>
  25. </xsl:for-each>
  26. <xsl:for-each select="
  27. compounddef[
  28. @kind = 'page' and
  29. @id != 'indexpage' and
  30. not(contains(@id, 'src'))]">
  31. <xsl:text>[section:</xsl:text>
  32. <xsl:value-of select="concat(@id, ' ', title)"/>
  33. <xsl:text>]</xsl:text>
  34. <xsl:value-of select="$newline"/>
  35. <xsl:value-of select="$newline"/>
  36. <xsl:apply-templates select="detaileddescription"/>
  37. <xsl:variable name="srcid" select="concat(@id, 'src')"/>
  38. <xsl:if test="count(/doxygen/compounddef[@id = $srcid]) &gt; 0">
  39. <xsl:value-of select="$newline"/>
  40. <xsl:value-of select="$newline"/>
  41. <xsl:text>[section:src </xsl:text>
  42. <xsl:value-of select="/doxygen/compounddef[@id = $srcid]/title"/>
  43. <xsl:text>]</xsl:text>
  44. <xsl:value-of select="$newline"/>
  45. <xsl:value-of select="$newline"/>
  46. <xsl:apply-templates select="/doxygen/compounddef[@id = $srcid]/detaileddescription"/>
  47. <xsl:text>[endsect]</xsl:text>
  48. <xsl:value-of select="$newline"/>
  49. <xsl:value-of select="$newline"/>
  50. </xsl:if>
  51. <xsl:text>[endsect]</xsl:text>
  52. <xsl:value-of select="$newline"/>
  53. <xsl:value-of select="$newline"/>
  54. </xsl:for-each>
  55. <xsl:value-of select="$newline"/>
  56. <xsl:text>[endsect]</xsl:text>
  57. </xsl:template>
  58. <!--========== Utilities ==========-->
  59. <xsl:template name="strip-asio-ns">
  60. <xsl:param name="name"/>
  61. <xsl:choose>
  62. <xsl:when test="contains($name, 'boost::system::is_error_code_enum')">
  63. <xsl:value-of select="$name"/>
  64. </xsl:when>
  65. <xsl:when test="contains($name, 'asio::')">
  66. <xsl:value-of select="substring-after($name, 'asio::')"/>
  67. </xsl:when>
  68. <xsl:otherwise>
  69. <xsl:value-of select="$name"/>
  70. </xsl:otherwise>
  71. </xsl:choose>
  72. </xsl:template>
  73. <xsl:template name="make-id">
  74. <xsl:param name="name"/>
  75. <xsl:choose>
  76. <xsl:when test="contains($name, '::')">
  77. <xsl:call-template name="make-id">
  78. <xsl:with-param name="name"
  79. select="concat(substring-before($name, '::'), '__', substring-after($name, '::'))"/>
  80. </xsl:call-template>
  81. </xsl:when>
  82. <xsl:when test="contains($name, '=')">
  83. <xsl:call-template name="make-id">
  84. <xsl:with-param name="name"
  85. select="concat(substring-before($name, '='), '_eq_', substring-after($name, '='))"/>
  86. </xsl:call-template>
  87. </xsl:when>
  88. <xsl:when test="contains($name, '!')">
  89. <xsl:call-template name="make-id">
  90. <xsl:with-param name="name"
  91. select="concat(substring-before($name, '!'), '_not_', substring-after($name, '!'))"/>
  92. </xsl:call-template>
  93. </xsl:when>
  94. <xsl:when test="contains($name, '&lt;')">
  95. <xsl:call-template name="make-id">
  96. <xsl:with-param name="name"
  97. select="concat(substring-before($name, '&lt;'), '_lt_', substring-after($name, '&lt;'))"/>
  98. </xsl:call-template>
  99. </xsl:when>
  100. <xsl:when test="contains($name, '&gt;')">
  101. <xsl:call-template name="make-id">
  102. <xsl:with-param name="name"
  103. select="concat(substring-before($name, '&gt;'), '_gt_', substring-after($name, '&gt;'))"/>
  104. </xsl:call-template>
  105. </xsl:when>
  106. <xsl:when test="contains($name, '+')">
  107. <xsl:call-template name="make-id">
  108. <xsl:with-param name="name"
  109. select="concat(substring-before($name, '+'), '_plus_', substring-after($name, '+'))"/>
  110. </xsl:call-template>
  111. </xsl:when>
  112. <xsl:when test="contains($name, '~')">
  113. <xsl:call-template name="make-id">
  114. <xsl:with-param name="name"
  115. select="concat(substring-before($name, '~'), '_', substring-after($name, '~'))"/>
  116. </xsl:call-template>
  117. </xsl:when>
  118. <xsl:when test="contains($name, ' ')">
  119. <xsl:call-template name="make-id">
  120. <xsl:with-param name="name"
  121. select="concat(substring-before($name, ' '), '_', substring-after($name, ' '))"/>
  122. </xsl:call-template>
  123. </xsl:when>
  124. <xsl:when test="contains($name, 'boost__posix_time__ptime')">
  125. <xsl:call-template name="make-id">
  126. <xsl:with-param name="name"
  127. select="concat(substring-before($name, 'boost__posix_time__ptime'), 'ptime', substring-after($name, 'boost__posix_time__ptime'))"/>
  128. </xsl:call-template>
  129. </xsl:when>
  130. <xsl:otherwise>
  131. <xsl:value-of select="$name"/>
  132. </xsl:otherwise>
  133. </xsl:choose>
  134. </xsl:template>
  135. <xsl:template name="replace-scope-marker">
  136. <xsl:param name="text"/>
  137. <xsl:choose>
  138. <xsl:when test="contains($text, '_1_1')">
  139. <xsl:call-template name="replace-scope-marker">
  140. <xsl:with-param name="text"
  141. select="concat(substring-before($text, '_1_1'), '::', substring-after($text, '_1_1'))"/>
  142. </xsl:call-template>
  143. </xsl:when>
  144. <xsl:otherwise>
  145. <xsl:value-of select="$text"/>
  146. </xsl:otherwise>
  147. </xsl:choose>
  148. </xsl:template>
  149. <xsl:template name="refid-to-anchor">
  150. <xsl:param name="text"/>
  151. <xsl:variable name="scoped-text">
  152. <xsl:call-template name="replace-scope-marker">
  153. <xsl:with-param name="text" select="$text"/>
  154. </xsl:call-template>
  155. </xsl:variable>
  156. <xsl:value-of select="substring-after($scoped-text, '_1')"/>
  157. </xsl:template>
  158. <!--========== Markup ==========-->
  159. <xsl:template match="para">
  160. <xsl:apply-templates/>
  161. <xsl:value-of select="$newline"/>
  162. <xsl:value-of select="$newline"/>
  163. </xsl:template>
  164. <xsl:template match="title">
  165. <xsl:variable name="title">
  166. <xsl:value-of select="."/>
  167. </xsl:variable>
  168. <xsl:if test="string-length($title) > 0">
  169. <xsl:text>[heading </xsl:text>
  170. <xsl:value-of select="."/>
  171. <xsl:text>]</xsl:text>
  172. <xsl:value-of select="$newline"/>
  173. <xsl:value-of select="$newline"/>
  174. </xsl:if>
  175. </xsl:template>
  176. <xsl:template match="programlisting">
  177. <xsl:value-of select="$newline"/>
  178. <xsl:apply-templates/>
  179. <xsl:value-of select="$newline"/>
  180. </xsl:template>
  181. <xsl:template match="codeline">
  182. <xsl:if test="string-length(.) &gt; 0">
  183. <xsl:text> ``''''''``</xsl:text>
  184. </xsl:if>
  185. <xsl:apply-templates mode="codeline"/>
  186. <xsl:value-of select="$newline"/>
  187. </xsl:template>
  188. <xsl:template match="sp">
  189. <xsl:text> </xsl:text>
  190. </xsl:template>
  191. <xsl:template match="sp" mode="codeline">
  192. <xsl:text> </xsl:text>
  193. </xsl:template>
  194. <xsl:template match="linebreak">
  195. <xsl:value-of select="$newline"/>
  196. <xsl:value-of select="$newline"/>
  197. </xsl:template>
  198. <xsl:template match="listitem">
  199. <xsl:text>* </xsl:text>
  200. <xsl:apply-templates/>
  201. <xsl:value-of select="$newline"/>
  202. </xsl:template>
  203. <xsl:template match="emphasis">
  204. <xsl:text>[*</xsl:text>
  205. <xsl:value-of select="."/>
  206. <xsl:text>]</xsl:text>
  207. </xsl:template>
  208. <xsl:template match="computeroutput">
  209. <xsl:text>`</xsl:text>
  210. <xsl:value-of select="."/>
  211. <xsl:text>`</xsl:text>
  212. </xsl:template>
  213. <xsl:template match="text()">
  214. <xsl:variable name="text" select="."/>
  215. <xsl:variable name="starts-with-whitespace" select="
  216. starts-with($text, ' ') or starts-with($text, $newline)"/>
  217. <xsl:variable name="preceding-node-name">
  218. <xsl:for-each select="preceding-sibling::*">
  219. <xsl:if test="position() = last()">
  220. <xsl:value-of select="local-name()"/>
  221. </xsl:if>
  222. </xsl:for-each>
  223. </xsl:variable>
  224. <xsl:variable name="after-newline" select="
  225. $preceding-node-name = 'programlisting' or
  226. $preceding-node-name = 'linebreak'"/>
  227. <xsl:choose>
  228. <xsl:when test="$starts-with-whitespace and $after-newline">
  229. <xsl:call-template name="escape-text">
  230. <xsl:with-param name="text">
  231. <xsl:call-template name="strip-leading-whitespace">
  232. <xsl:with-param name="text" select="$text"/>
  233. </xsl:call-template>
  234. </xsl:with-param>
  235. </xsl:call-template>
  236. </xsl:when>
  237. <xsl:otherwise>
  238. <xsl:call-template name="escape-text">
  239. <xsl:with-param name="text" select="$text"/>
  240. </xsl:call-template>
  241. </xsl:otherwise>
  242. </xsl:choose>
  243. </xsl:template>
  244. <xsl:template name="strip-leading-whitespace">
  245. <xsl:param name="text"/>
  246. <xsl:choose>
  247. <xsl:when test="starts-with($text, ' ')">
  248. <xsl:call-template name="strip-leading-whitespace">
  249. <xsl:with-param name="text" select="substring($text, 2)"/>
  250. </xsl:call-template>
  251. </xsl:when>
  252. <xsl:when test="starts-with($text, $newline)">
  253. <xsl:call-template name="strip-leading-whitespace">
  254. <xsl:with-param name="text" select="substring($text, 2)"/>
  255. </xsl:call-template>
  256. </xsl:when>
  257. <xsl:otherwise>
  258. <xsl:value-of select="$text"/>
  259. </xsl:otherwise>
  260. </xsl:choose>
  261. </xsl:template>
  262. <xsl:template name="escape-text">
  263. <xsl:param name="text"/>
  264. <xsl:choose>
  265. <xsl:when test="contains($text, '_')">
  266. <xsl:value-of select="substring-before($text, '_')"/>
  267. <xsl:text>\_</xsl:text>
  268. <xsl:call-template name="escape-text">
  269. <xsl:with-param name="text" select="substring-after($text, '_')"/>
  270. </xsl:call-template>
  271. </xsl:when>
  272. <xsl:otherwise>
  273. <xsl:value-of select="$text"/>
  274. </xsl:otherwise>
  275. </xsl:choose>
  276. </xsl:template>
  277. <xsl:template match="ref[@kindref='compound']">
  278. <xsl:variable name="name">
  279. <xsl:value-of select="."/>
  280. </xsl:variable>
  281. <xsl:variable name="refid">
  282. <xsl:value-of select="@refid"/>
  283. </xsl:variable>
  284. <xsl:choose>
  285. <xsl:when test="count(/doxygen/compounddef[@id=$refid]) &gt; 0">
  286. <xsl:text>[link boost_asio.tutorial.</xsl:text>
  287. <xsl:choose>
  288. <xsl:when test="contains($refid, 'src')">
  289. <xsl:value-of select="substring-before($refid, 'src')"/>
  290. <xsl:text>.src</xsl:text>
  291. </xsl:when>
  292. <xsl:otherwise>
  293. <xsl:value-of select="$refid"/>
  294. </xsl:otherwise>
  295. </xsl:choose>
  296. <xsl:value-of select="concat(' ', .)"/>
  297. <xsl:text>]</xsl:text>
  298. </xsl:when>
  299. <xsl:when test="contains($name, 'asio::')">
  300. <xsl:variable name="ref-name">
  301. <xsl:call-template name="strip-asio-ns">
  302. <xsl:with-param name="name" select="$name"/>
  303. </xsl:call-template>
  304. </xsl:variable>
  305. <xsl:variable name="ref-id">
  306. <xsl:call-template name="make-id">
  307. <xsl:with-param name="name" select="$ref-name"/>
  308. </xsl:call-template>
  309. </xsl:variable>
  310. [link boost_asio.reference.<xsl:value-of select="$ref-id"/><xsl:text> </xsl:text><xsl:value-of
  311. select="$ref-name"/>]</xsl:when>
  312. <xsl:otherwise>
  313. <xsl:apply-templates/>
  314. </xsl:otherwise>
  315. </xsl:choose>
  316. </xsl:template>
  317. <xsl:template match="ref[@kindref='member']">
  318. <xsl:variable name="refid">
  319. <xsl:value-of select="@refid"/>
  320. </xsl:variable>
  321. <xsl:variable name="text">
  322. <xsl:call-template name="strip-asio-ns">
  323. <xsl:with-param name="name" select="."/>
  324. </xsl:call-template>
  325. </xsl:variable>
  326. <xsl:choose>
  327. <xsl:when test="$refid='index_1index'">
  328. <xsl:text>[link boost_asio.tutorial </xsl:text>
  329. <xsl:value-of select="$text"/>
  330. <xsl:text>]</xsl:text>
  331. </xsl:when>
  332. <xsl:when test="@external='reference.tags'">
  333. <xsl:variable name="anchor">
  334. <xsl:call-template name="refid-to-anchor">
  335. <xsl:with-param name="text" select="$refid"/>
  336. </xsl:call-template>
  337. </xsl:variable>
  338. <xsl:choose>
  339. <xsl:when test="count(document('reference.tags')/tagfile/compound[@kind='class']/member[anchor=$anchor]) &gt; 0">
  340. <xsl:for-each select="document('reference.tags')/tagfile/compound[@kind='class']/member[anchor=$anchor]">
  341. <xsl:variable name="scope">
  342. <xsl:call-template name="make-id">
  343. <xsl:with-param name="name">
  344. <xsl:call-template name="strip-asio-ns">
  345. <xsl:with-param name="name" select="../name"/>
  346. </xsl:call-template>
  347. </xsl:with-param>
  348. </xsl:call-template>
  349. </xsl:variable>
  350. <xsl:variable name="name">
  351. <xsl:call-template name="make-id">
  352. <xsl:with-param name="name" select="name"/>
  353. </xsl:call-template>
  354. </xsl:variable>
  355. <xsl:text>[link boost_asio.reference.</xsl:text>
  356. <xsl:if test="string-length($scope) &gt; 0">
  357. <xsl:value-of select="$scope"/><xsl:text>.</xsl:text>
  358. </xsl:if>
  359. <xsl:value-of select="$name"/>
  360. <xsl:text> </xsl:text><xsl:value-of select="$text"/><xsl:text>]</xsl:text>
  361. </xsl:for-each>
  362. </xsl:when>
  363. <xsl:otherwise>
  364. <xsl:apply-templates/>
  365. </xsl:otherwise>
  366. </xsl:choose>
  367. </xsl:when>
  368. <xsl:otherwise>
  369. <xsl:apply-templates/>
  370. </xsl:otherwise>
  371. </xsl:choose>
  372. </xsl:template>
  373. <xsl:template match="ulink">
  374. <xsl:text>[@</xsl:text>
  375. <xsl:value-of select="@url"/>
  376. <xsl:text> </xsl:text>
  377. <xsl:value-of select="."/>
  378. <xsl:text>]</xsl:text>
  379. </xsl:template>
  380. </xsl:stylesheet>