ebnf.xsl 11 KB

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