compact.xsl 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet xmlns:rng="http://relaxng.org/ns/structure/1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:d="http://dyomedea.com/ns/id" version="1.0" exclude-result-prefixes="rng d">
  3. <xsl:variable name="meta" select="document('../reference-manual/elements-meta.xml')"/>
  4. <xsl:variable name="schema" select="document('../reference-manual/compact-summary.rng')"/>
  5. <xsl:variable name="spaces" select="' '"/>
  6. <xsl:strip-space elements="*"/>
  7. <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
  8. <xsl:template match="*|@*|processing-instruction()">
  9. <xsl:copy>
  10. <xsl:apply-templates select="@*"/>
  11. <xsl:apply-templates select="*|text()"/>
  12. </xsl:copy>
  13. </xsl:template>
  14. <xsl:template match="get-reference">
  15. <xsl:apply-templates select="$schema//*[@d:id]" mode="production"/>
  16. </xsl:template>
  17. <xsl:template match="get-ebnf">
  18. <programlisting>
  19. <xsl:apply-templates select="$schema/*" mode="synopsis"/>
  20. </programlisting>
  21. </xsl:template>
  22. <xsl:template match="*[rng:ref/@name='datatypeName' and normalize-space(.) = '{}']" mode="name">
  23. <xsl:text>datatypeName param exceptPattern</xsl:text>
  24. </xsl:template>
  25. <xsl:template match="*[*[1][self::rng:ref] and *[2][self::rng:oneOrMore]]" mode="name">
  26. <xsl:value-of select="concat(rng:ref/@name, ' ', rng:oneOrMore/rng:value, ' ', rng:oneOrMore/rng:ref/@name)"/>
  27. </xsl:template>
  28. <xsl:template match="*" mode="production" name="production">
  29. <!--<xsl:comment><xsl:value-of select="@d:id"/></xsl:comment>-->
  30. <xsl:variable name="current-meta" select="$meta//refentry[@id=current()/@d:id]"/>
  31. <xsl:param name="title" select="$current-meta/compact"/>
  32. <xsl:param name="id" select="concat('ch16-', @d:id)"/>
  33. <refentry id="{$id}">
  34. <refmeta>
  35. <refentrytitle>
  36. <xsl:value-of select="$title"/>
  37. </refentrytitle>
  38. </refmeta>
  39. <refnamediv>
  40. <indexterm id="IXT-{generate-id()}">
  41. <primary>
  42. <xsl:value-of select="$title"/>
  43. </primary>
  44. </indexterm>
  45. <refname>
  46. <xsl:value-of select="$title"/>
  47. </refname>
  48. <xsl:apply-templates select="$current-meta/purpose" mode="meta"/>
  49. </refnamediv>
  50. <refsect1>
  51. <title>Class:</title>
  52. <para>
  53. <xsl:value-of select="ancestor::rng:define/@name"/>
  54. </para>
  55. </refsect1>
  56. <refsynopsisdiv>
  57. <synopsis>
  58. <xsl:text>&#xa;</xsl:text>
  59. <xsl:apply-templates select="." mode="synopsis">
  60. <xsl:with-param name="indent" select="0"/>
  61. </xsl:apply-templates>
  62. <xsl:text>&#xa;</xsl:text>
  63. </synopsis>
  64. </refsynopsisdiv>
  65. <refsect1>
  66. <title>May be included in:</title>
  67. <para>
  68. <xsl:apply-templates select="." mode="parent1"/>
  69. </para>
  70. </refsect1>
  71. <xsl:apply-templates select="$current-meta/name" mode="meta"/>
  72. <xsl:apply-templates select="$current-meta/compact-description" mode="meta"/>
  73. <xsl:apply-templates select="$current-meta/restrictions" mode="meta"/>
  74. <xsl:apply-templates select="$current-meta/compact-example" mode="meta"/>
  75. </refentry>
  76. </xsl:template>
  77. <xsl:template match="restrictions" mode="meta">
  78. <refsect1>
  79. <title>Restrictions:</title>
  80. <xsl:choose>
  81. <xsl:when test="para">
  82. <xsl:apply-templates mode="meta"/>
  83. </xsl:when>
  84. <xsl:otherwise>
  85. <para>
  86. <xsl:apply-templates mode="meta"/>
  87. </para>
  88. </xsl:otherwise>
  89. </xsl:choose>
  90. </refsect1>
  91. </xsl:template>
  92. <xsl:template match="rng:define" mode="parent1">
  93. <xsl:apply-templates select="//rng:ref[@name=current()/@name]" mode="parent2"/>
  94. </xsl:template>
  95. <xsl:template match="*" mode="parent1">
  96. <xsl:call-template name="searchParent"/>
  97. </xsl:template>
  98. <xsl:template match="*[@d:id]" mode="parent2" name="gotParent">
  99. <xsl:param name="depth" select="0"/>
  100. <literal>
  101. <xsl:value-of select="$meta//refentry[@id=current()/@d:id]/compact"/>
  102. </literal>
  103. <xsl:text>, </xsl:text>
  104. </xsl:template>
  105. <xsl:template match="*" mode="parent2" name="searchParent">
  106. <xsl:param name="depth" select="0"/>
  107. <xsl:apply-templates select="parent::*" mode="parent2">
  108. <xsl:with-param name="depth" select="$depth"/>
  109. </xsl:apply-templates>
  110. </xsl:template>
  111. <xsl:template match="rng:define" mode="parent2" priority="1">
  112. <xsl:param name="depth" select="0"/>
  113. <xsl:if test="$depth &lt; 2">
  114. <xsl:apply-templates select="//rng:ref[@name=current()/@name]" mode="parent2">
  115. <xsl:with-param name="depth" select="$depth+1"/>
  116. </xsl:apply-templates>
  117. </xsl:if>
  118. </xsl:template>
  119. <xsl:template match="name" mode="meta">
  120. <refsect1>
  121. <title>XML syntax equivalent:</title>
  122. <para>
  123. <xsl:apply-templates mode="meta"/>
  124. </para>
  125. </refsect1>
  126. </xsl:template>
  127. <xsl:template match="purpose" mode="meta">
  128. <refpurpose>
  129. <xsl:apply-templates mode="meta"/>
  130. </refpurpose>
  131. </xsl:template>
  132. <xsl:template match="compact-example" mode="meta">
  133. <refsect1>
  134. <title>Example:</title>
  135. <programlisting>
  136. <xsl:apply-templates mode="meta"/>
  137. </programlisting>
  138. </refsect1>
  139. </xsl:template>
  140. <xsl:template match="compact-description" mode="meta">
  141. <refsect1>
  142. <title>Description:</title>
  143. <xsl:apply-templates mode="meta"/>
  144. </refsect1>
  145. </xsl:template>
  146. <xsl:template match="*|@*" mode="meta">
  147. <xsl:copy>
  148. <xsl:apply-templates select="@*" mode="meta"/>
  149. <xsl:apply-templates mode="meta"/>
  150. </xsl:copy>
  151. </xsl:template>
  152. <xsl:template match="this|thisElement|thisParent" mode="meta">
  153. <literal><xsl:value-of select="ancestor::refentry/compact"/></literal>
  154. </xsl:template>
  155. <xsl:template match="this[@path]" mode="meta">
  156. <xsl:apply-templates select="ancestor::refentry/*[name()=current()/@path]/node()" mode="meta"/>
  157. </xsl:template>
  158. <xsl:template match="thisName" mode="meta">
  159. <literal><xsl:value-of select="ancestor::refentry/name"/></literal>
  160. </xsl:template>
  161. <xsl:template match="varlistentry//this" mode="meta">
  162. <xsl:copy-of select="ancestor::varlistentry/term/literal"/>
  163. </xsl:template>
  164. <xsl:template match="*" mode="synopsis">
  165. <xsl:comment>
  166. <xsl:value-of select="name()"/>
  167. </xsl:comment>
  168. </xsl:template>
  169. <xsl:template match="rng:grammar|rng:group|rng:choice|rng:oneOrMore|rng:zeroOrMore" mode="synopsis">
  170. <xsl:param name="indent" select="1"/>
  171. <xsl:apply-templates select="." mode="prefix">
  172. <xsl:with-param name="indent" select="$indent"/>
  173. </xsl:apply-templates>
  174. <xsl:apply-templates mode="synopsis"/>
  175. <xsl:apply-templates select="." mode="suffix"/>
  176. </xsl:template>
  177. <xsl:template match="rng:choice[count(*) > 1 and (not(parent::rng:define) or preceding-sibling::* or following-sibling::*)]|rng:oneOrMore[count(*) > 1]|rng:zeroOrMore[count(*) > 1]" mode="synopsis">
  178. <xsl:param name="indent" select="1"/>
  179. <xsl:apply-templates select="." mode="prefix">
  180. <xsl:with-param name="indent" select="$indent"/>
  181. </xsl:apply-templates>
  182. <xsl:text>(</xsl:text>
  183. <xsl:apply-templates mode="synopsis"/>
  184. <xsl:text>)</xsl:text>
  185. <xsl:apply-templates select="." mode="suffix"/>
  186. </xsl:template>
  187. <xsl:template match="rng:define" mode="synopsis">
  188. <xsl:text>&#xa;</xsl:text>
  189. <xsl:value-of select="@name"/>
  190. <xsl:value-of select="substring($spaces, 1, 20 - string-length(@name))"/>
  191. <xsl:text>::= </xsl:text>
  192. <xsl:apply-templates mode="synopsis"/>
  193. </xsl:template>
  194. <xsl:template match="rng:optional" mode="synopsis">
  195. <xsl:param name="indent" select="1"/>
  196. <xsl:apply-templates select="." mode="prefix">
  197. <xsl:with-param name="indent" select="$indent"/>
  198. </xsl:apply-templates>
  199. <xsl:text>[</xsl:text>
  200. <xsl:apply-templates mode="synopsis"/>
  201. <xsl:text>]</xsl:text>
  202. <xsl:apply-templates select="." mode="suffix"/>
  203. </xsl:template>
  204. <xsl:template match="rng:ref" mode="synopsis">
  205. <xsl:param name="indent" select="1"/>
  206. <xsl:apply-templates select="." mode="prefix">
  207. <xsl:with-param name="indent" select="$indent"/>
  208. </xsl:apply-templates>
  209. <emphasis>
  210. <xsl:value-of select="@name"/>
  211. </emphasis>
  212. <xsl:apply-templates select="." mode="suffix"/>
  213. </xsl:template>
  214. <xsl:template match="rng:data" mode="synopsis">
  215. <xsl:param name="indent" select="1"/>
  216. <xsl:apply-templates select="." mode="prefix">
  217. <xsl:with-param name="indent" select="$indent"/>
  218. </xsl:apply-templates>
  219. <xsl:if test="*">(</xsl:if>
  220. <emphasis>
  221. <xsl:value-of select="@type"/>
  222. </emphasis>
  223. <xsl:apply-templates mode="synopsis"/>
  224. <xsl:if test="*">)</xsl:if>
  225. <xsl:apply-templates select="." mode="suffix"/>
  226. </xsl:template>
  227. <xsl:template match="rng:except" mode="synopsis">
  228. <xsl:param name="indent" select="1"/>
  229. <xsl:apply-templates select="." mode="prefix">
  230. <xsl:with-param name="indent" select="$indent"/>
  231. </xsl:apply-templates>
  232. <xsl:text> - </xsl:text>
  233. <xsl:if test="count(*) > 1">(</xsl:if>
  234. <xsl:apply-templates mode="synopsis"/>
  235. <xsl:if test="count(*) > 1">)</xsl:if>
  236. <xsl:apply-templates select="." mode="suffix"/>
  237. </xsl:template>
  238. <xsl:template match="rng:value" mode="synopsis">
  239. <xsl:param name="indent" select="1"/>
  240. <xsl:apply-templates select="." mode="prefix">
  241. <xsl:with-param name="indent" select="$indent"/>
  242. </xsl:apply-templates>
  243. <xsl:text>"</xsl:text>
  244. <xsl:value-of select="."/>
  245. <xsl:apply-templates select="." mode="suffix"/>
  246. <xsl:text>"</xsl:text>
  247. </xsl:template>
  248. <xsl:template match="*" mode="prefix"/>
  249. <xsl:template match="*[preceding-sibling::* and not(parent::rng:choice)]" mode="prefix">
  250. <xsl:text> </xsl:text>
  251. </xsl:template>
  252. <xsl:template match="*[preceding-sibling::* and parent::rng:choice]" mode="prefix">
  253. <xsl:param name="indent" select="1"/>
  254. <xsl:if test="$indent = 1">
  255. <xsl:if test="parent::rng:choice[parent::rng:define and not(preceding-sibling::*|following-sibling::*)]">
  256. <xsl:text>&#xa;</xsl:text>
  257. <xsl:value-of select="substring($spaces, 1, 24)"/>
  258. </xsl:if>
  259. <xsl:text>|</xsl:text>
  260. </xsl:if>
  261. </xsl:template>
  262. <xsl:template match="*" mode="suffix"/>
  263. <xsl:template match="rng:zeroOrMore" mode="suffix">
  264. <xsl:text>*</xsl:text>
  265. </xsl:template>
  266. <xsl:template match="rng:oneOrMore" mode="suffix">
  267. <xsl:text>+</xsl:text>
  268. </xsl:template>
  269. </xsl:stylesheet>