ebnf.xsl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
  4. exclude-result-prefixes="doc"
  5. version='1.0'>
  6. <!-- ********************************************************************
  7. $Id: ebnf.xsl 9664 2012-11-07 20:02:17Z bobstayton $
  8. ********************************************************************
  9. This file is part of the XSL DocBook Stylesheet distribution.
  10. See ../README or http://docbook.sf.net/release/xsl/current/ for
  11. copyright and other information.
  12. ******************************************************************** -->
  13. <doc:reference xmlns="">
  14. <referenceinfo>
  15. <releaseinfo role="meta">
  16. $Id: ebnf.xsl 9664 2012-11-07 20:02:17Z bobstayton $
  17. </releaseinfo>
  18. <author><surname>Walsh</surname>
  19. <firstname>Norman</firstname></author>
  20. <copyright><year>1999</year><year>2000</year>
  21. <holder>Norman Walsh</holder>
  22. </copyright>
  23. </referenceinfo>
  24. <title>HTML EBNF Reference</title>
  25. <partintro>
  26. <section><title>Introduction</title>
  27. <para>This is technical reference documentation for the DocBook XSL
  28. Stylesheets; it documents (some of) the parameters, templates, and
  29. other elements of the stylesheets.</para>
  30. <para>This reference describes the templates and parameters relevant
  31. to formatting EBNF markup.</para>
  32. <para>This is not intended to be <quote>user</quote> documentation.
  33. It is provided for developers writing customization layers for the
  34. stylesheets, and for anyone who's interested in <quote>how it
  35. works</quote>.</para>
  36. <para>Although I am trying to be thorough, this documentation is known
  37. to be incomplete. Don't forget to read the source, too :-)</para>
  38. </section>
  39. </partintro>
  40. </doc:reference>
  41. <!-- ==================================================================== -->
  42. <xsl:template match="productionset">
  43. <table width="100%" cellpadding="5">
  44. <xsl:if test="$ebnf.table.bgcolor != ''">
  45. <xsl:attribute name="bgcolor">
  46. <xsl:value-of select="$ebnf.table.bgcolor"/>
  47. </xsl:attribute>
  48. </xsl:if>
  49. <xsl:if test="$ebnf.table.border != 0">
  50. <xsl:attribute name="border">1</xsl:attribute>
  51. </xsl:if>
  52. <xsl:attribute name="class">
  53. <xsl:value-of select="local-name(.)"/>
  54. </xsl:attribute>
  55. <xsl:attribute name="summary">
  56. <xsl:text>EBNF</xsl:text>
  57. <xsl:if test="title|info/title">
  58. <xsl:text> for </xsl:text>
  59. <xsl:value-of select="title|info/title[1]"/>
  60. </xsl:if>
  61. </xsl:attribute>
  62. <xsl:if test="title|info/title">
  63. <tr>
  64. <th align="{$direction.align.start}" valign="top">
  65. <xsl:apply-templates select="." mode="class.attribute"/>
  66. <xsl:apply-templates select="title|info/title[1]"/>
  67. </th>
  68. </tr>
  69. </xsl:if>
  70. <tr>
  71. <td>
  72. <table border="0" width="99%" cellpadding="0">
  73. <xsl:if test="$ebnf.table.bgcolor != ''">
  74. <xsl:attribute name="bgcolor">
  75. <xsl:value-of select="$ebnf.table.bgcolor"/>
  76. </xsl:attribute>
  77. </xsl:if>
  78. <xsl:attribute name="class">
  79. <xsl:value-of select="local-name(.)"/>
  80. </xsl:attribute>
  81. <xsl:attribute name="summary">EBNF productions</xsl:attribute>
  82. <xsl:apply-templates select="production|productionrecap"/>
  83. </table>
  84. </td>
  85. </tr>
  86. </table>
  87. </xsl:template>
  88. <xsl:template match="productionset/title">
  89. <xsl:apply-templates/>
  90. </xsl:template>
  91. <xsl:template match="production">
  92. <xsl:param name="recap" select="false()"/>
  93. <tr>
  94. <td align="{$direction.align.start}" valign="top" width="3%">
  95. <xsl:text>[</xsl:text>
  96. <xsl:apply-templates select="." mode="label.markup"/>
  97. <xsl:text>]</xsl:text>
  98. </td>
  99. <td align="{$direction.align.end}" valign="top" width="10%">
  100. <xsl:choose>
  101. <xsl:when test="$recap">
  102. <a>
  103. <xsl:attribute name="href">
  104. <xsl:call-template name="href.target">
  105. <xsl:with-param name="object" select="."/>
  106. </xsl:call-template>
  107. </xsl:attribute>
  108. <xsl:apply-templates select="lhs"/>
  109. </a>
  110. </xsl:when>
  111. <xsl:otherwise>
  112. <xsl:call-template name="id.attribute"/>
  113. <xsl:call-template name="anchor"/>
  114. <xsl:apply-templates select="lhs"/>
  115. </xsl:otherwise>
  116. </xsl:choose>
  117. </td>
  118. <td valign="top" width="5%" align="center">
  119. <xsl:copy-of select="$ebnf.assignment"/>
  120. </td>
  121. <td valign="top" width="52%">
  122. <xsl:apply-templates select="rhs"/>
  123. <xsl:copy-of select="$ebnf.statement.terminator"/>
  124. </td>
  125. <td align="{$direction.align.start}" valign="top" width="30%">
  126. <xsl:choose>
  127. <xsl:when test="rhs/lineannotation|constraint">
  128. <xsl:apply-templates select="rhs/lineannotation" mode="rhslo"/>
  129. <xsl:apply-templates select="constraint"/>
  130. </xsl:when>
  131. <xsl:otherwise>
  132. <xsl:text>&#160;</xsl:text>
  133. </xsl:otherwise>
  134. </xsl:choose>
  135. </td>
  136. </tr>
  137. </xsl:template>
  138. <xsl:template match="productionrecap">
  139. <xsl:variable name="targets" select="key('id',@linkend)"/>
  140. <xsl:variable name="target" select="$targets[1]"/>
  141. <xsl:if test="count($targets)=0">
  142. <xsl:message>
  143. <xsl:text>Error: no ID for productionrecap linkend: </xsl:text>
  144. <xsl:value-of select="@linkend"/>
  145. <xsl:text>.</xsl:text>
  146. </xsl:message>
  147. </xsl:if>
  148. <xsl:if test="count($targets)>1">
  149. <xsl:message>
  150. <xsl:text>Warning: multiple "IDs" for productionrecap linkend: </xsl:text>
  151. <xsl:value-of select="@linkend"/>
  152. <xsl:text>.</xsl:text>
  153. </xsl:message>
  154. </xsl:if>
  155. <xsl:apply-templates select="$target">
  156. <xsl:with-param name="recap" select="true()"/>
  157. </xsl:apply-templates>
  158. </xsl:template>
  159. <xsl:template match="lhs">
  160. <xsl:apply-templates/>
  161. </xsl:template>
  162. <xsl:template match="rhs">
  163. <xsl:apply-templates/>
  164. <xsl:if test="following-sibling::rhs">
  165. <xsl:text> |</xsl:text>
  166. <br/>
  167. </xsl:if>
  168. </xsl:template>
  169. <xsl:template match="nonterminal">
  170. <xsl:variable name="linkend">
  171. <xsl:call-template name="xpointer.idref">
  172. <xsl:with-param name="xpointer" select="@def"/>
  173. </xsl:call-template>
  174. </xsl:variable>
  175. <xsl:call-template name="check.id.unique">
  176. <xsl:with-param name="linkend" select="$linkend"/>
  177. </xsl:call-template>
  178. <xsl:call-template name="check.idref.targets">
  179. <xsl:with-param name="linkend" select="$linkend"/>
  180. <xsl:with-param name="element-list">production</xsl:with-param>
  181. </xsl:call-template>
  182. <!-- If you don't provide content, you can't point outside this doc. -->
  183. <xsl:choose>
  184. <xsl:when test="*|text()"><!--nop--></xsl:when>
  185. <xsl:otherwise>
  186. <xsl:if test="$linkend = ''">
  187. <xsl:message>
  188. <xsl:text>Non-terminals with no content must point to </xsl:text>
  189. <xsl:text>production elements in the current document.</xsl:text>
  190. </xsl:message>
  191. <xsl:message>
  192. <xsl:text>Invalid xpointer for empty nt: </xsl:text>
  193. <xsl:value-of select="@def"/>
  194. </xsl:message>
  195. </xsl:if>
  196. </xsl:otherwise>
  197. </xsl:choose>
  198. <xsl:variable name="href">
  199. <xsl:choose>
  200. <xsl:when test="$linkend != ''">
  201. <xsl:variable name="targets" select="key('id',$linkend)"/>
  202. <xsl:variable name="target" select="$targets[1]"/>
  203. <xsl:call-template name="href.target">
  204. <xsl:with-param name="object" select="$target"/>
  205. </xsl:call-template>
  206. </xsl:when>
  207. <xsl:otherwise>
  208. <xsl:value-of select="@def"/>
  209. </xsl:otherwise>
  210. </xsl:choose>
  211. </xsl:variable>
  212. <a href="{$href}">
  213. <xsl:choose>
  214. <xsl:when test="*|text()">
  215. <xsl:apply-templates/>
  216. </xsl:when>
  217. <xsl:otherwise>
  218. <xsl:choose>
  219. <xsl:when test="$linkend != ''">
  220. <xsl:variable name="targets" select="key('id',$linkend)"/>
  221. <xsl:variable name="target" select="$targets[1]"/>
  222. <xsl:apply-templates select="$target/lhs"/>
  223. </xsl:when>
  224. <xsl:otherwise>
  225. <xsl:text>???</xsl:text>
  226. </xsl:otherwise>
  227. </xsl:choose>
  228. </xsl:otherwise>
  229. </xsl:choose>
  230. </a>
  231. </xsl:template>
  232. <xsl:template match="rhs/lineannotation">
  233. <!--nop-->
  234. </xsl:template>
  235. <xsl:template match="rhs/lineannotation" mode="rhslo">
  236. <xsl:text>/*&#160;</xsl:text>
  237. <xsl:apply-templates/>
  238. <xsl:text>&#160;*/</xsl:text>
  239. <br/>
  240. </xsl:template>
  241. <xsl:template match="constraint">
  242. <xsl:call-template name="check.id.unique">
  243. <xsl:with-param name="linkend" select="@linkend"/>
  244. </xsl:call-template>
  245. <xsl:call-template name="check.idref.targets">
  246. <xsl:with-param name="linkend" select="@linkend"/>
  247. <xsl:with-param name="element-list">constraintdef</xsl:with-param>
  248. </xsl:call-template>
  249. <xsl:variable name="href">
  250. <xsl:variable name="targets" select="key('id',@linkend)"/>
  251. <xsl:variable name="target" select="$targets[1]"/>
  252. <xsl:call-template name="href.target">
  253. <xsl:with-param name="object" select="$target"/>
  254. </xsl:call-template>
  255. </xsl:variable>
  256. <xsl:text>[&#160;</xsl:text>
  257. <xsl:choose>
  258. <xsl:when test="@role">
  259. <xsl:value-of select="@role"/>
  260. <xsl:text>: </xsl:text>
  261. </xsl:when>
  262. <xsl:otherwise>
  263. <xsl:variable name="targets" select="key('id',@linkend)"/>
  264. <xsl:variable name="target" select="$targets[1]"/>
  265. <xsl:if test="$target/@role">
  266. <xsl:value-of select="$target/@role"/>
  267. <xsl:text>: </xsl:text>
  268. </xsl:if>
  269. </xsl:otherwise>
  270. </xsl:choose>
  271. <a href="{$href}">
  272. <xsl:variable name="targets" select="key('id',@linkend)"/>
  273. <xsl:variable name="target" select="$targets[1]"/>
  274. <xsl:apply-templates select="$target" mode="title.markup"/>
  275. </a>
  276. <xsl:text>&#160;]</xsl:text>
  277. <xsl:if test="following-sibling::constraint">
  278. <br/>
  279. </xsl:if>
  280. </xsl:template>
  281. <xsl:template match="constraintdef">
  282. <div>
  283. <xsl:apply-templates select="." mode="class.attribute"/>
  284. <xsl:call-template name="id.attribute"/>
  285. <xsl:call-template name="anchor"/>
  286. <xsl:apply-templates/>
  287. </div>
  288. </xsl:template>
  289. <xsl:template match="constraintdef/title">
  290. <p><b><xsl:apply-templates/></b></p>
  291. </xsl:template>
  292. <!-- ==================================================================== -->
  293. </xsl:stylesheet>