| 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 | <!-- |
|---|
| 9 | |
|---|
| 10 | A brutally hacked version of EBNF that works around FO's inability to |
|---|
| 11 | automatically determine the width of table columns. It merges the lhs, ::= and |
|---|
| 12 | rhs columns into a single one, allowing the production to look the way we want |
|---|
| 13 | in the YAML spec: |
|---|
| 14 | |
|---|
| 15 | c-printable ::= #x9 | #xA | #xD |
|---|
| 16 | | [#x20-#x7E] | #x85 |
|---|
| 17 | | [#xA0-#xD7FF] |
|---|
| 18 | | [#xE000-#xFFFD] |
|---|
| 19 | | [#x10000-#x10FFFF] |
|---|
| 20 | |
|---|
| 21 | c-byte-order-mark ::= #xFEFF |
|---|
| 22 | |
|---|
| 23 | Note that the '::=' is NOT aligned, unlike the original EBNF layout. Also, |
|---|
| 24 | to properly indent multiple production lines, it is necessary to add the |
|---|
| 25 | entities somehow. This is done in a pre-processing XSLT script; it |
|---|
| 26 | really should be done here instead. |
|---|
| 27 | |
|---|
| 28 | Finally, the last column (annotation) is removed altogether. This allows us |
|---|
| 29 | to assign 95% of the page width to the production itself. |
|---|
| 30 | |
|---|
| 31 | The original version header was: |
|---|
| 32 | |
|---|
| 33 | ******************************************************************** |
|---|
| 34 | $Id: ebnf_fo.xsl,v 1.1 2004/12/03 19:09:48 oren Exp $ |
|---|
| 35 | ******************************************************************** |
|---|
| 36 | |
|---|
| 37 | This file is part of the XSL DocBook Stylesheet distribution. |
|---|
| 38 | See ../README or http://nwalsh.com/docbook/xsl/ for copyright |
|---|
| 39 | and other information. |
|---|
| 40 | |
|---|
| 41 | ******************************************************************** |
|---|
| 42 | |
|---|
| 43 | <doc:reference xmlns=""> |
|---|
| 44 | <referenceinfo> |
|---|
| 45 | <releaseinfo role="meta"> |
|---|
| 46 | $Id: ebnf_fo.xsl,v 1.1 2004/12/03 19:09:48 oren Exp $ |
|---|
| 47 | </releaseinfo> |
|---|
| 48 | <author><surname>Walsh</surname> |
|---|
| 49 | <firstname>Norman</firstname></author> |
|---|
| 50 | <copyright><year>1999</year><year>2000</year><year>2001</year> |
|---|
| 51 | <holder>Norman Walsh</holder> |
|---|
| 52 | </copyright> |
|---|
| 53 | </referenceinfo> |
|---|
| 54 | <title>HTML EBNF Reference</title> |
|---|
| 55 | |
|---|
| 56 | <partintro> |
|---|
| 57 | <section><title>Introduction</title> |
|---|
| 58 | |
|---|
| 59 | <para>This is technical reference documentation for the DocBook XSL |
|---|
| 60 | Stylesheets; it documents (some of) the parameters, templates, and |
|---|
| 61 | other elements of the stylesheets.</para> |
|---|
| 62 | |
|---|
| 63 | <para>This reference describes the templates and parameters relevant |
|---|
| 64 | to formatting EBNF markup.</para> |
|---|
| 65 | |
|---|
| 66 | <para>This is not intended to be <quote>user</quote> documentation. |
|---|
| 67 | It is provided for developers writing customization layers for the |
|---|
| 68 | stylesheets, and for anyone who's interested in <quote>how it |
|---|
| 69 | works</quote>.</para> |
|---|
| 70 | |
|---|
| 71 | <para>Although I am trying to be thorough, this documentation is known |
|---|
| 72 | to be incomplete. Don't forget to read the source, too :-)</para> |
|---|
| 73 | </section> |
|---|
| 74 | </partintro> |
|---|
| 75 | </doc:reference> |
|---|
| 76 | |
|---|
| 77 | ==================================================================== --> |
|---|
| 78 | |
|---|
| 79 | <xsl:template match="productionset"> |
|---|
| 80 | <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable> |
|---|
| 81 | |
|---|
| 82 | <xsl:choose> |
|---|
| 83 | <xsl:when test="title"> |
|---|
| 84 | <fo:block id="{$id}" xsl:use-attribute-sets="formal.object.properties"> |
|---|
| 85 | <xsl:call-template name="formal.object.heading"> |
|---|
| 86 | <xsl:with-param name="placement" select="'before'"/> |
|---|
| 87 | </xsl:call-template> |
|---|
| 88 | |
|---|
| 89 | <fo:table table-layout="fixed" width="100%"> |
|---|
| 90 | <fo:table-column column-number="1" column-width="5%"/> |
|---|
| 91 | <fo:table-column column-number="2" column-width="95%"/> |
|---|
| 92 | <fo:table-body> |
|---|
| 93 | <xsl:apply-templates select="production|productionrecap"/> |
|---|
| 94 | </fo:table-body> |
|---|
| 95 | </fo:table> |
|---|
| 96 | </fo:block> |
|---|
| 97 | </xsl:when> |
|---|
| 98 | <xsl:otherwise> |
|---|
| 99 | <fo:table id="{$id}" table-layout="fixed" width="100%"> |
|---|
| 100 | <fo:table-column column-number="1" column-width="5%"/> |
|---|
| 101 | <fo:table-column column-number="2" column-width="95%"/> |
|---|
| 102 | <fo:table-body> |
|---|
| 103 | <xsl:apply-templates select="production|productionrecap"/> |
|---|
| 104 | </fo:table-body> |
|---|
| 105 | </fo:table> |
|---|
| 106 | </xsl:otherwise> |
|---|
| 107 | </xsl:choose> |
|---|
| 108 | </xsl:template> |
|---|
| 109 | |
|---|
| 110 | <xsl:template match="productionset/title"> |
|---|
| 111 | <!-- suppressed --> |
|---|
| 112 | </xsl:template> |
|---|
| 113 | |
|---|
| 114 | <xsl:template match="production"> |
|---|
| 115 | <xsl:param name="recap" select="false()"/> |
|---|
| 116 | <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable> |
|---|
| 117 | <fo:table-row> |
|---|
| 118 | <fo:table-cell> |
|---|
| 119 | <fo:block text-align="start"> |
|---|
| 120 | <xsl:text>[</xsl:text> |
|---|
| 121 | <xsl:number count="production" level="any"/> |
|---|
| 122 | <xsl:text>]</xsl:text> |
|---|
| 123 | </fo:block> |
|---|
| 124 | </fo:table-cell> |
|---|
| 125 | <fo:table-cell> |
|---|
| 126 | <fo:block text-align="start" font-family="{$monospace.font.family}"> |
|---|
| 127 | <xsl:choose> |
|---|
| 128 | <xsl:when test="$recap"> |
|---|
| 129 | <fo:basic-link internal-destination="{$id}" |
|---|
| 130 | xsl:use-attribute-sets="xref.properties"> |
|---|
| 131 | <xsl:apply-templates select="lhs"/> |
|---|
| 132 | </fo:basic-link> |
|---|
| 133 | </xsl:when> |
|---|
| 134 | <xsl:otherwise> |
|---|
| 135 | <fo:wrapper id="{$id}"> |
|---|
| 136 | <xsl:apply-templates select="lhs"/> |
|---|
| 137 | </fo:wrapper> |
|---|
| 138 | </xsl:otherwise> |
|---|
| 139 | </xsl:choose> |
|---|
| 140 | <xsl:text> </xsl:text> |
|---|
| 141 | <xsl:copy-of select="$ebnf.assignment"/> |
|---|
| 142 | <xsl:apply-templates select="rhs"/> |
|---|
| 143 | <xsl:copy-of select="$ebnf.statement.terminator"/> |
|---|
| 144 | </fo:block> |
|---|
| 145 | </fo:table-cell> |
|---|
| 146 | </fo:table-row> |
|---|
| 147 | </xsl:template> |
|---|
| 148 | |
|---|
| 149 | <xsl:template match="productionrecap"> |
|---|
| 150 | <xsl:variable name="targets" select="key('id',@linkend)"/> |
|---|
| 151 | <xsl:variable name="target" select="$targets[1]"/> |
|---|
| 152 | |
|---|
| 153 | <xsl:if test="count($targets)=0"> |
|---|
| 154 | <xsl:message> |
|---|
| 155 | <xsl:text>Error: no ID for productionrecap linkend: </xsl:text> |
|---|
| 156 | <xsl:value-of select="@linkend"/> |
|---|
| 157 | <xsl:text>.</xsl:text> |
|---|
| 158 | </xsl:message> |
|---|
| 159 | </xsl:if> |
|---|
| 160 | |
|---|
| 161 | <xsl:if test="count($targets)>1"> |
|---|
| 162 | <xsl:message> |
|---|
| 163 | <xsl:text>Warning: multiple "IDs" for productionrecap linkend: </xsl:text> |
|---|
| 164 | <xsl:value-of select="@linkend"/> |
|---|
| 165 | <xsl:text>.</xsl:text> |
|---|
| 166 | </xsl:message> |
|---|
| 167 | </xsl:if> |
|---|
| 168 | |
|---|
| 169 | <xsl:apply-templates select="$target"> |
|---|
| 170 | <xsl:with-param name="recap" select="true()"/> |
|---|
| 171 | </xsl:apply-templates> |
|---|
| 172 | </xsl:template> |
|---|
| 173 | |
|---|
| 174 | <xsl:template match="lhs"> |
|---|
| 175 | <xsl:apply-templates/> |
|---|
| 176 | </xsl:template> |
|---|
| 177 | |
|---|
| 178 | <xsl:template match="rhs"> |
|---|
| 179 | <xsl:apply-templates/> |
|---|
| 180 | </xsl:template> |
|---|
| 181 | |
|---|
| 182 | <xsl:template match="nonterminal"> |
|---|
| 183 | <xsl:variable name="linkend"> |
|---|
| 184 | <xsl:call-template name="xpointer.idref"> |
|---|
| 185 | <xsl:with-param name="xpointer" select="@def"/> |
|---|
| 186 | </xsl:call-template> |
|---|
| 187 | </xsl:variable> |
|---|
| 188 | |
|---|
| 189 | <xsl:call-template name="check.id.unique"> |
|---|
| 190 | <xsl:with-param name="linkend" select="$linkend"/> |
|---|
| 191 | </xsl:call-template> |
|---|
| 192 | |
|---|
| 193 | <xsl:call-template name="check.idref.targets"> |
|---|
| 194 | <xsl:with-param name="linkend" select="$linkend"/> |
|---|
| 195 | <xsl:with-param name="element-list">production</xsl:with-param> |
|---|
| 196 | </xsl:call-template> |
|---|
| 197 | |
|---|
| 198 | <!-- If you don't provide content, you can't point outside this doc. --> |
|---|
| 199 | <xsl:choose> |
|---|
| 200 | <xsl:when test="*|text()"><!--nop--></xsl:when> |
|---|
| 201 | <xsl:otherwise> |
|---|
| 202 | <xsl:if test="$linkend = ''"> |
|---|
| 203 | <xsl:message> |
|---|
| 204 | <xsl:text>Non-terminals with no content must point to </xsl:text> |
|---|
| 205 | <xsl:text>production elements in the current document.</xsl:text> |
|---|
| 206 | </xsl:message> |
|---|
| 207 | <xsl:message> |
|---|
| 208 | <xsl:text>Invalid xpointer for empty nt: </xsl:text> |
|---|
| 209 | <xsl:value-of select="@def"/> |
|---|
| 210 | </xsl:message> |
|---|
| 211 | </xsl:if> |
|---|
| 212 | </xsl:otherwise> |
|---|
| 213 | </xsl:choose> |
|---|
| 214 | |
|---|
| 215 | <xsl:variable name="href"> |
|---|
| 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:call-template name="object.id"> |
|---|
| 221 | <xsl:with-param name="object" select="$target"/> |
|---|
| 222 | </xsl:call-template> |
|---|
| 223 | </xsl:when> |
|---|
| 224 | <xsl:otherwise> |
|---|
| 225 | <xsl:value-of select="@def"/> |
|---|
| 226 | </xsl:otherwise> |
|---|
| 227 | </xsl:choose> |
|---|
| 228 | </xsl:variable> |
|---|
| 229 | |
|---|
| 230 | <fo:basic-link internal-destination="{$href}" |
|---|
| 231 | xsl:use-attribute-sets="xref.properties"> |
|---|
| 232 | <xsl:choose> |
|---|
| 233 | <xsl:when test="*|text()"> |
|---|
| 234 | <xsl:apply-templates/> |
|---|
| 235 | </xsl:when> |
|---|
| 236 | <xsl:otherwise> |
|---|
| 237 | <xsl:choose> |
|---|
| 238 | <xsl:when test="$linkend != ''"> |
|---|
| 239 | <xsl:variable name="targets" select="key('id',$linkend)"/> |
|---|
| 240 | <xsl:variable name="target" select="$targets[1]"/> |
|---|
| 241 | <xsl:apply-templates select="$target/lhs"/> |
|---|
| 242 | </xsl:when> |
|---|
| 243 | <xsl:otherwise> |
|---|
| 244 | <xsl:text>???</xsl:text> |
|---|
| 245 | </xsl:otherwise> |
|---|
| 246 | </xsl:choose> |
|---|
| 247 | </xsl:otherwise> |
|---|
| 248 | </xsl:choose> |
|---|
| 249 | </fo:basic-link> |
|---|
| 250 | </xsl:template> |
|---|
| 251 | |
|---|
| 252 | <xsl:template match="rhs/lineannotation"> |
|---|
| 253 | <!--nop--> |
|---|
| 254 | </xsl:template> |
|---|
| 255 | |
|---|
| 256 | <xsl:template match="rhs/lineannotation" mode="rhslo"> |
|---|
| 257 | <xsl:text>/* </xsl:text> |
|---|
| 258 | <xsl:apply-templates/> |
|---|
| 259 | <xsl:text> */</xsl:text> |
|---|
| 260 | </xsl:template> |
|---|
| 261 | |
|---|
| 262 | <xsl:template match="constraint"> |
|---|
| 263 | <xsl:call-template name="check.id.unique"> |
|---|
| 264 | <xsl:with-param name="linkend" select="@linkend"/> |
|---|
| 265 | </xsl:call-template> |
|---|
| 266 | |
|---|
| 267 | <xsl:call-template name="check.idref.targets"> |
|---|
| 268 | <xsl:with-param name="linkend" select="@linkend"/> |
|---|
| 269 | <xsl:with-param name="element-list">constraintdef</xsl:with-param> |
|---|
| 270 | </xsl:call-template> |
|---|
| 271 | |
|---|
| 272 | <xsl:variable name="href"> |
|---|
| 273 | <xsl:variable name="targets" select="key('id',@linkend)"/> |
|---|
| 274 | <xsl:variable name="target" select="$targets[1]"/> |
|---|
| 275 | <xsl:call-template name="object.id"> |
|---|
| 276 | <xsl:with-param name="object" select="$target"/> |
|---|
| 277 | </xsl:call-template> |
|---|
| 278 | </xsl:variable> |
|---|
| 279 | |
|---|
| 280 | <xsl:if test="preceding-sibling::constraint"> |
|---|
| 281 | <fo:inline linefeed-treatment="preserve">
</fo:inline> |
|---|
| 282 | </xsl:if> |
|---|
| 283 | <xsl:text>[ </xsl:text> |
|---|
| 284 | |
|---|
| 285 | <xsl:choose> |
|---|
| 286 | <xsl:when test="@role"> |
|---|
| 287 | <xsl:value-of select="@role"/> |
|---|
| 288 | <xsl:text>: </xsl:text> |
|---|
| 289 | </xsl:when> |
|---|
| 290 | <xsl:otherwise> |
|---|
| 291 | <xsl:variable name="targets" select="key('id',@linkend)"/> |
|---|
| 292 | <xsl:variable name="target" select="$targets[1]"/> |
|---|
| 293 | <xsl:if test="$target/@role"> |
|---|
| 294 | <xsl:value-of select="$target/@role"/> |
|---|
| 295 | <xsl:text>: </xsl:text> |
|---|
| 296 | </xsl:if> |
|---|
| 297 | </xsl:otherwise> |
|---|
| 298 | </xsl:choose> |
|---|
| 299 | |
|---|
| 300 | <fo:basic-link internal-destination="{$href}" |
|---|
| 301 | xsl:use-attribute-sets="xref.properties"> |
|---|
| 302 | <xsl:variable name="targets" select="key('id',@linkend)"/> |
|---|
| 303 | <xsl:variable name="target" select="$targets[1]"/> |
|---|
| 304 | <xsl:apply-templates select="$target" mode="title.markup"/> |
|---|
| 305 | </fo:basic-link> |
|---|
| 306 | <xsl:text> ]</xsl:text> |
|---|
| 307 | </xsl:template> |
|---|
| 308 | |
|---|
| 309 | <xsl:template match="constraintdef"> |
|---|
| 310 | <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable> |
|---|
| 311 | <fo:block id="{$id}"> |
|---|
| 312 | <xsl:apply-templates/> |
|---|
| 313 | </fo:block> |
|---|
| 314 | </xsl:template> |
|---|
| 315 | |
|---|
| 316 | <xsl:template match="constraintdef/title"> |
|---|
| 317 | <fo:block font-weight="bold"> |
|---|
| 318 | <xsl:apply-templates/> |
|---|
| 319 | </fo:block> |
|---|
| 320 | </xsl:template> |
|---|
| 321 | |
|---|
| 322 | <!-- ==================================================================== --> |
|---|
| 323 | |
|---|
| 324 | </xsl:stylesheet> |
|---|