ebnf.xsl 10 KB

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