ebnf.xsl 10 KB

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