ebnf.xsl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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: ebnf.xsl 9664 2012-11-07 20:02:17Z bobstayton $
  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: ebnf.xsl 9664 2012-11-07 20:02:17Z bobstayton $
  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|info/title">
  57. <xsl:text> for </xsl:text>
  58. <xsl:value-of select="title|info/title[1]"/>
  59. </xsl:if>
  60. </xsl:attribute>
  61. <xsl:if test="title|info/title">
  62. <tr>
  63. <th align="{$direction.align.start}" valign="top">
  64. <xsl:apply-templates select="." mode="class.attribute"/>
  65. <xsl:apply-templates select="title|info/title[1]"/>
  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="{$direction.align.start}" valign="top" width="3%">
  94. <xsl:text>[</xsl:text>
  95. <xsl:apply-templates select="." mode="label.markup"/>
  96. <xsl:text>]</xsl:text>
  97. </td>
  98. <td align="{$direction.align.end}" 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="id.attribute"/>
  112. <xsl:call-template name="anchor"/>
  113. <xsl:apply-templates select="lhs"/>
  114. </xsl:otherwise>
  115. </xsl:choose>
  116. </td>
  117. <td valign="top" width="5%" align="center">
  118. <xsl:copy-of select="$ebnf.assignment"/>
  119. </td>
  120. <td valign="top" width="52%">
  121. <xsl:apply-templates select="rhs"/>
  122. <xsl:copy-of select="$ebnf.statement.terminator"/>
  123. </td>
  124. <td align="{$direction.align.start}" valign="top" width="30%">
  125. <xsl:choose>
  126. <xsl:when test="rhs/lineannotation|constraint">
  127. <xsl:apply-templates select="rhs/lineannotation" mode="rhslo"/>
  128. <xsl:apply-templates select="constraint"/>
  129. </xsl:when>
  130. <xsl:otherwise>
  131. <xsl:text>&#160;</xsl:text>
  132. </xsl:otherwise>
  133. </xsl:choose>
  134. </td>
  135. </tr>
  136. </xsl:template>
  137. <xsl:template match="productionrecap">
  138. <xsl:variable name="targets" select="key('id',@linkend)"/>
  139. <xsl:variable name="target" select="$targets[1]"/>
  140. <xsl:if test="count($targets)=0">
  141. <xsl:message>
  142. <xsl:text>Error: no ID for productionrecap linkend: </xsl:text>
  143. <xsl:value-of select="@linkend"/>
  144. <xsl:text>.</xsl:text>
  145. </xsl:message>
  146. </xsl:if>
  147. <xsl:if test="count($targets)&gt;1">
  148. <xsl:message>
  149. <xsl:text>Warning: multiple "IDs" for productionrecap linkend: </xsl:text>
  150. <xsl:value-of select="@linkend"/>
  151. <xsl:text>.</xsl:text>
  152. </xsl:message>
  153. </xsl:if>
  154. <xsl:apply-templates select="$target">
  155. <xsl:with-param name="recap" select="true()"/>
  156. </xsl:apply-templates>
  157. </xsl:template>
  158. <xsl:template match="lhs">
  159. <xsl:apply-templates/>
  160. </xsl:template>
  161. <xsl:template match="rhs">
  162. <xsl:apply-templates/>
  163. <xsl:if test="following-sibling::rhs">
  164. <xsl:text> |</xsl:text>
  165. <br/>
  166. </xsl:if>
  167. </xsl:template>
  168. <xsl:template match="nonterminal">
  169. <xsl:variable name="linkend">
  170. <xsl:call-template name="xpointer.idref">
  171. <xsl:with-param name="xpointer" select="@def"/>
  172. </xsl:call-template>
  173. </xsl:variable>
  174. <xsl:call-template name="check.id.unique">
  175. <xsl:with-param name="linkend" select="$linkend"/>
  176. </xsl:call-template>
  177. <xsl:call-template name="check.idref.targets">
  178. <xsl:with-param name="linkend" select="$linkend"/>
  179. <xsl:with-param name="element-list">production</xsl:with-param>
  180. </xsl:call-template>
  181. <!-- If you don't provide content, you can't point outside this doc. -->
  182. <xsl:choose>
  183. <xsl:when test="*|text()"><!--nop--></xsl:when>
  184. <xsl:otherwise>
  185. <xsl:if test="$linkend = ''">
  186. <xsl:message>
  187. <xsl:text>Non-terminals with no content must point to </xsl:text>
  188. <xsl:text>production elements in the current document.</xsl:text>
  189. </xsl:message>
  190. <xsl:message>
  191. <xsl:text>Invalid xpointer for empty nt: </xsl:text>
  192. <xsl:value-of select="@def"/>
  193. </xsl:message>
  194. </xsl:if>
  195. </xsl:otherwise>
  196. </xsl:choose>
  197. <xsl:variable name="href">
  198. <xsl:choose>
  199. <xsl:when test="$linkend != ''">
  200. <xsl:variable name="targets" select="key('id',$linkend)"/>
  201. <xsl:variable name="target" select="$targets[1]"/>
  202. <xsl:call-template name="href.target">
  203. <xsl:with-param name="object" select="$target"/>
  204. </xsl:call-template>
  205. </xsl:when>
  206. <xsl:otherwise>
  207. <xsl:value-of select="@def"/>
  208. </xsl:otherwise>
  209. </xsl:choose>
  210. </xsl:variable>
  211. <a href="{$href}">
  212. <xsl:choose>
  213. <xsl:when test="*|text()">
  214. <xsl:apply-templates/>
  215. </xsl:when>
  216. <xsl:otherwise>
  217. <xsl:choose>
  218. <xsl:when test="$linkend != ''">
  219. <xsl:variable name="targets" select="key('id',$linkend)"/>
  220. <xsl:variable name="target" select="$targets[1]"/>
  221. <xsl:apply-templates select="$target/lhs"/>
  222. </xsl:when>
  223. <xsl:otherwise>
  224. <xsl:text>???</xsl:text>
  225. </xsl:otherwise>
  226. </xsl:choose>
  227. </xsl:otherwise>
  228. </xsl:choose>
  229. </a>
  230. </xsl:template>
  231. <xsl:template match="rhs/lineannotation">
  232. <!--nop-->
  233. </xsl:template>
  234. <xsl:template match="rhs/lineannotation" mode="rhslo">
  235. <xsl:text>/*&#160;</xsl:text>
  236. <xsl:apply-templates/>
  237. <xsl:text>&#160;*/</xsl:text>
  238. <br/>
  239. </xsl:template>
  240. <xsl:template match="constraint">
  241. <xsl:call-template name="check.id.unique">
  242. <xsl:with-param name="linkend" select="@linkend"/>
  243. </xsl:call-template>
  244. <xsl:call-template name="check.idref.targets">
  245. <xsl:with-param name="linkend" select="@linkend"/>
  246. <xsl:with-param name="element-list">constraintdef</xsl:with-param>
  247. </xsl:call-template>
  248. <xsl:variable name="href">
  249. <xsl:variable name="targets" select="key('id',@linkend)"/>
  250. <xsl:variable name="target" select="$targets[1]"/>
  251. <xsl:call-template name="href.target">
  252. <xsl:with-param name="object" select="$target"/>
  253. </xsl:call-template>
  254. </xsl:variable>
  255. <xsl:text>[&#160;</xsl:text>
  256. <xsl:choose>
  257. <xsl:when test="@role">
  258. <xsl:value-of select="@role"/>
  259. <xsl:text>: </xsl:text>
  260. </xsl:when>
  261. <xsl:otherwise>
  262. <xsl:variable name="targets" select="key('id',@linkend)"/>
  263. <xsl:variable name="target" select="$targets[1]"/>
  264. <xsl:if test="$target/@role">
  265. <xsl:value-of select="$target/@role"/>
  266. <xsl:text>: </xsl:text>
  267. </xsl:if>
  268. </xsl:otherwise>
  269. </xsl:choose>
  270. <a href="{$href}">
  271. <xsl:variable name="targets" select="key('id',@linkend)"/>
  272. <xsl:variable name="target" select="$targets[1]"/>
  273. <xsl:apply-templates select="$target" mode="title.markup"/>
  274. </a>
  275. <xsl:text>&#160;]</xsl:text>
  276. <xsl:if test="following-sibling::constraint">
  277. <br/>
  278. </xsl:if>
  279. </xsl:template>
  280. <xsl:template match="constraintdef">
  281. <div>
  282. <xsl:apply-templates select="." mode="class.attribute"/>
  283. <xsl:call-template name="id.attribute"/>
  284. <xsl:call-template name="anchor"/>
  285. <xsl:apply-templates/>
  286. </div>
  287. </xsl:template>
  288. <xsl:template match="constraintdef/title">
  289. <p><strong xmlns:xslo="http://www.w3.org/1999/XSL/Transform"><xsl:apply-templates/></strong></p>
  290. </xsl:template>
  291. <!-- ==================================================================== -->
  292. </xsl:stylesheet>