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<!-- ********************************************************************
8     $Id$
9     ********************************************************************
10
11     This file is part of the XSL DocBook Stylesheet distribution.
12     See /README or http://nwalsh.com/docbook/xsl/ for copyright
13     and other information.
14
15     ******************************************************************** -->
16
17<doc:reference xmlns="">
18<referenceinfo>
19<releaseinfo role="meta">
20$Id$
21</releaseinfo>
22<author><surname>Walsh</surname>
23<firstname>Norman</firstname></author>
24<copyright><year>1999</year><year>2000</year>
25<holder>Norman Walsh</holder>
26</copyright>
27</referenceinfo>
28<title>HTML EBNF Reference</title>
29
30<partintro>
31<section><title>Introduction</title>
32
33<para>This is technical reference documentation for the DocBook XSL
34Stylesheets; it documents (some of) the parameters, templates, and
35other elements of the stylesheets.</para>
36
37<para>This reference describes the templates and parameters relevant
38to formatting EBNF markup.</para>
39
40<para>This is not intended to be <quote>user</quote> documentation.
41It is provided for developers writing customization layers for the
42stylesheets, and for anyone who's interested in <quote>how it
43works</quote>.</para>
44
45<para>Although I am trying to be thorough, this documentation is known
46to be incomplete. Don't forget to read the source, too :-)</para>
47</section>
48</partintro>
49</doc:reference>
50
51<!-- This module formats EBNF tables. The DTD that this supports is  -->
52<!-- under development by the DocBook community. This code is        -->
53<!-- experimental and is not (yet) part of the DocBook stylesheets.  -->
54
55<xsl:include href="docbook.xsl"/>
56
57<!-- ==================================================================== -->
58
59<xsl:param name="ebnf.table.bgcolor">#F5DCB3</xsl:param>
60
61<doc:param name="ebnf.table.bgcolor" xmlns="">
62<refpurpose>Background color for EBNF tables</refpurpose>
63<refdescription>
64<para>Sets the background color for EBNF tables. No <sgmltag>bgcolor</sgmltag>
65attribute is output if <varname>ebnf.table.bgcolor</varname> is set to
66the null string. The default value matches the value used in recent
67online versions of the W3C's XML Spec productions.</para>
68</refdescription>
69</doc:param>
70
71<xsl:param name="ebnf.table.border">1</xsl:param>
72
73<doc:param name="ebnf.table.border" xmlns="">
74<refpurpose>Selects border on EBNF tables</refpurpose>
75<refdescription>
76<para>Selects the border on EBNF tables. If non-zero, the tables have
77borders, otherwise they don't.</para>
78</refdescription>
79</doc:param>
80
81<!-- ==================================================================== -->
82
83<xsl:template match="productionset">
84  <table width="100%" cellpadding="5">
85    <xsl:if test="$ebnf.table.bgcolor != ''">
86      <xsl:attribute name="bgcolor">
87	<xsl:value-of select="$ebnf.table.bgcolor"/>
88      </xsl:attribute>
89    </xsl:if>
90    <xsl:if test="$ebnf.table.border != 0">
91      <xsl:attribute name="border">1</xsl:attribute>
92    </xsl:if>
93    <xsl:attribute name="class">
94      <xsl:value-of select="name(.)"/>
95    </xsl:attribute>
96    <xsl:attribute name="summary">
97      <xsl:text>EBNF</xsl:text>
98      <xsl:if test="title">
99	<xsl:text> for </xsl:text>
100	<xsl:value-of select="title"/>
101      </xsl:if>
102    </xsl:attribute>
103
104    <xsl:if test="title">
105      <tr>
106	<th align="left" valign="top" class="{name(.)}">
107	  <xsl:apply-templates select="title"/>
108	</th>
109      </tr>
110    </xsl:if>
111    <tr>
112      <td>
113	<table border="0" width="99%" cellpadding="0">
114	  <xsl:if test="$ebnf.table.bgcolor != ''">
115	    <xsl:attribute name="bgcolor">
116	      <xsl:value-of select="$ebnf.table.bgcolor"/>
117	    </xsl:attribute>
118	  </xsl:if>
119	  <xsl:attribute name="class">
120	    <xsl:value-of select="name(.)"/>
121	  </xsl:attribute>
122	  <xsl:attribute name="summary">EBNF productions</xsl:attribute>
123	  <xsl:apply-templates select="production|productionrecap"/>
124	</table>
125      </td>
126    </tr>
127  </table>
128</xsl:template>
129
130<xsl:template match="productionset/title">
131  <xsl:apply-templates/>
132</xsl:template>
133
134<xsl:template match="production">
135  <xsl:param name="recap" select="false()"/>
136  <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
137  <tr>
138    <td align="left" valign="top" width="3%">
139      <xsl:text>[</xsl:text>
140      <xsl:number count="production" level="any"/>
141      <xsl:text>]</xsl:text>
142    </td>
143    <td align="right" valign="top" width="10%">
144      <xsl:choose>
145	<xsl:when test="$recap">
146	  <a>
147	    <xsl:attribute name="href">
148	      <xsl:call-template name="href.target">
149		<xsl:with-param name="object" select="."/>
150	      </xsl:call-template>
151	    </xsl:attribute>
152	    <xsl:apply-templates select="lhs"/>
153	  </a>
154	</xsl:when>
155	<xsl:otherwise>
156	  <a name="{$id}"/>
157	  <xsl:apply-templates select="lhs"/>
158	</xsl:otherwise>
159      </xsl:choose>
160    </td>
161    <td valign="top" width="5%" align="center"><tt>::=</tt></td>
162    <td valign="top" width="52%">
163      <xsl:apply-templates select="rhs"/>
164    </td>
165    <td align="left" valign="top" width="30%">
166      <xsl:choose>
167	<xsl:when test="rhs/lineannotation|constraint">
168	  <xsl:apply-templates select="rhs/lineannotation" mode="rhslo"/>
169	  <xsl:apply-templates select="constraint"/>
170	</xsl:when>
171	<xsl:otherwise>
172	  <xsl:text>&#160;</xsl:text>
173	</xsl:otherwise>
174      </xsl:choose>
175    </td>
176  </tr>
177</xsl:template>
178
179<xsl:template match="productionrecap">
180  <xsl:variable name="targets" select="id(@linkend)"/>
181  <xsl:variable name="target" select="$targets[1]"/>
182
183  <xsl:if test="$check.idref = '1'">
184    <xsl:if test="count($targets)=0">
185      <xsl:message>
186        <xsl:text>Error: no ID for productionrecap linkend: </xsl:text>
187        <xsl:value-of select="@linkend"/>
188        <xsl:text>.</xsl:text>
189      </xsl:message>
190    </xsl:if>
191
192    <xsl:if test="count($targets)>1">
193      <xsl:message>
194        <xsl:text>Warning: multiple "IDs" for productionrecap linkend: </xsl:text>
195        <xsl:value-of select="@linkend"/>
196        <xsl:text>.</xsl:text>
197      </xsl:message>
198    </xsl:if>
199  </xsl:if>
200  <xsl:apply-templates select="$target">
201    <xsl:with-param name="recap" select="true()"/>
202  </xsl:apply-templates>
203</xsl:template>
204
205<xsl:template match="lhs">
206  <xsl:apply-templates/>
207</xsl:template>
208
209<xsl:template match="rhs">
210  <xsl:apply-templates/>
211</xsl:template>
212
213<xsl:template match="nonterminal">
214  <xsl:variable name="linkend">
215    <xsl:call-template name="xpointer.idref">
216      <xsl:with-param name="xpointer" select="@def"/>
217    </xsl:call-template>
218  </xsl:variable>
219
220  <xsl:call-template name="check.id.unique">
221    <xsl:with-param name="linkend" select="$linkend"/>
222  </xsl:call-template>
223
224  <xsl:call-template name="check.idref.targets">
225    <xsl:with-param name="linkend" select="$linkend"/>
226    <xsl:with-param name="element-list">production</xsl:with-param>
227  </xsl:call-template>
228
229  <!-- If you don't provide content, you can't point outside this doc. -->
230  <xsl:choose>
231    <xsl:when test="*|text()"><!--nop--></xsl:when>
232    <xsl:otherwise>
233      <xsl:if test="$linkend = ''">
234	<xsl:message>
235	  <xsl:text>Non-terminals with no content must point to </xsl:text>
236	  <xsl:text>production elements in the current document.</xsl:text>
237	</xsl:message>
238	<xsl:message>
239	  <xsl:text>Invalid xpointer for empty nt: </xsl:text>
240	  <xsl:value-of select="@def"/>
241	</xsl:message>
242      </xsl:if>
243    </xsl:otherwise>
244  </xsl:choose>
245
246  <xsl:variable name="href">
247    <xsl:choose>
248      <xsl:when test="$linkend != ''">
249	<xsl:variable name="targets" select="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:when>
255      <xsl:otherwise>
256	<xsl:value-of select="@def"/>
257      </xsl:otherwise>
258    </xsl:choose>
259  </xsl:variable>
260
261  <a href="{$href}">
262    <xsl:choose>
263      <xsl:when test="*|text()">
264	<xsl:apply-templates/>
265      </xsl:when>
266      <xsl:otherwise>
267	<xsl:choose>
268	  <xsl:when test="$linkend != ''">
269	    <xsl:variable name="targets" select="id($linkend)"/>
270	    <xsl:variable name="target" select="$targets[1]"/>
271	    <xsl:apply-templates select="$target/lhs"/>
272	  </xsl:when>
273	  <xsl:otherwise>
274	    <xsl:text>???</xsl:text>
275	  </xsl:otherwise>
276	</xsl:choose>
277      </xsl:otherwise>
278    </xsl:choose>
279  </a>
280</xsl:template>
281
282<xsl:template match="rhs/lineannotation">
283  <!--nop-->
284</xsl:template>
285
286<xsl:template match="rhs/lineannotation" mode="rhslo">
287  <xsl:text>/*&#160;</xsl:text>
288  <xsl:apply-templates/>
289  <xsl:text>&#160;*/</xsl:text>
290</xsl:template>
291
292<xsl:template match="constraint">
293  <xsl:call-template name="check.id.unique">
294    <xsl:with-param name="linkend" select="@linkend"/>
295  </xsl:call-template>
296
297  <xsl:call-template name="check.idref.targets">
298    <xsl:with-param name="linkend" select="@linkend"/>
299    <xsl:with-param name="element-list">constraintdef</xsl:with-param>
300  </xsl:call-template>
301
302  <xsl:variable name="href">
303    <xsl:variable name="targets" select="id(@linkend)"/>
304    <xsl:variable name="target" select="$targets[1]"/>
305    <xsl:call-template name="href.target">
306      <xsl:with-param name="object" select="$target"/>
307    </xsl:call-template>
308  </xsl:variable>
309
310  <xsl:if test="preceding-sibling::constraint">
311    <br/>
312  </xsl:if>
313  <xsl:text>[ </xsl:text>
314
315  <xsl:choose>
316    <xsl:when test="@role">
317      <xsl:value-of select="@role"/>
318      <xsl:text>: </xsl:text>
319    </xsl:when>
320    <xsl:otherwise>
321      <xsl:variable name="targets" select="id(@linkend)"/>
322      <xsl:variable name="target" select="$targets[1]"/>
323      <xsl:if test="$target/@role">
324	<xsl:value-of select="$target/@role"/>
325	<xsl:text>: </xsl:text>
326      </xsl:if>
327    </xsl:otherwise>
328  </xsl:choose>
329
330  <a href="{$href}">
331    <xsl:variable name="targets" select="id(@linkend)"/>
332    <xsl:variable name="target" select="$targets[1]"/>
333    <xsl:apply-templates select="$target" mode="title.markup"/>
334  </a>
335  <xsl:text> ]</xsl:text>
336</xsl:template>
337
338<xsl:template match="constraintdef">
339  <div class="{name(.)}">
340    <xsl:apply-templates/>
341  </div>
342</xsl:template>
343
344<xsl:template match="constraintdef/title">
345  <p><b><xsl:apply-templates/></b></p>
346</xsl:template>
347
348<!-- ==================================================================== -->
349
350</xsl:stylesheet>
351