summaryrefslogtreecommitdiff
path: root/doc/publican/protocol-to-docbook.xsl
blob: 210e0dbb2573e3868f878e361534b6e66fc600f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />

<xsl:template match="/">
  <!-- insert docbook's DOCTYPE blurb -->
    <xsl:text disable-output-escaping = "yes"><![CDATA[
<!DOCTYPE appendix PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  <!ENTITY % BOOK_ENTITIES SYSTEM "Wayland.ent">
%BOOK_ENTITIES;
]>
]]></xsl:text>

  <appendix id="appe-Wayland-Protocol">
    <title>Wayland Protocol Specification</title>
    <xsl:apply-templates select="protocol/copyright" />

    <xsl:apply-templates select="protocol/interface" />
  </appendix>
</xsl:template>

<!-- Break text blocks separated by two new lines into paragraphs -->
<xsl:template name="break">
     <xsl:param name="text" />
     <xsl:param name="linebreak" select="'&#10;&#10;'" />
     <xsl:choose>
       <xsl:when test="contains($text,$linebreak)">
         <para>
           <xsl:value-of select="substring-before($text,$linebreak)" />
         </para>
         <xsl:call-template name="break">
           <xsl:with-param name="text" select="substring-after($text,$linebreak)" />
         </xsl:call-template>
       </xsl:when>
       <xsl:otherwise>
         <para><xsl:value-of select="$text" /></para>
       </xsl:otherwise>
     </xsl:choose>
</xsl:template>

<!-- Copyright blurb -->
<xsl:template match="copyright">
  <para>
    <literallayout>
      <xsl:value-of select="." disable-output-escaping="yes"/>
    </literallayout>
  </para>
</xsl:template>

<!-- Interface descriptions -->
<xsl:template match="interface" >
  <section id="protocol-spec-{@name}">
    <title>
      <xsl:value-of select="@name" />
      <!-- only show summary if it exists -->
      <xsl:if test="description/@summary">
	- <xsl:value-of select="description/@summary" />
      </xsl:if>
    </title>
    <xsl:call-template name="break">
      <xsl:with-param name="text" select="description" />
    </xsl:call-template>
    <xsl:if test="request">
      <section>
        <title>Requests provided by <xsl:value-of select="@name" /></title>
        <xsl:apply-templates select="request" />
      </section>
    </xsl:if>
    <xsl:if test="event">
      <section>
        <title>Events provided by <xsl:value-of select="@name" /></title>
        <xsl:apply-templates select="event" />
      </section>
    </xsl:if>
    <xsl:if test="enum">
      <section>
        <title>Enums provided by <xsl:value-of select="@name" /></title>
      <xsl:apply-templates select="enum" />
      </section>
    </xsl:if>
  </section>
</xsl:template>

<!-- table contents for enum values -->
<xsl:template match="entry">
  <varlistentry>
    <term><xsl:value-of select="@name"/></term>
    <listitem>
      <simpara>
        <xsl:value-of select="@value"/>
        <xsl:if test="@summary" >
          - <xsl:value-of select="@summary"/>
        </xsl:if>
      </simpara>
    </listitem>
  </varlistentry>
</xsl:template>

<!-- table contents for request/event arguments -->
<xsl:template match="arg">
  <varlistentry>
    <term><xsl:value-of select="@name"/></term>
    <listitem>
        <simpara>
          <xsl:value-of select="@type"/>
          <xsl:if test="@summary" >
            - <xsl:value-of select="@summary"/>
          </xsl:if>
        </simpara>
    </listitem>
  </varlistentry>
</xsl:template>

<!-- id arguments -->
<xsl:template match="arg[@type='object' and @interface]">
  <varlistentry>
    <term><xsl:value-of select="@name"/></term>
    <listitem>
        <simpara>
          <link linkend="protocol-spec-{@interface}">
            <xsl:value-of select="@interface"/>
          </link>
          <xsl:if test="@summary" >
            - <xsl:value-of select="@summary"/>
          </xsl:if>
        </simpara>
    </listitem>
  </varlistentry>
</xsl:template>

<!-- new_id arguments -->
<xsl:template match="arg[@type='new_id' and @interface]">
  <varlistentry>
    <term><xsl:value-of select="@name"/></term>
    <listitem>
        <simpara>
          id for the new
          <link linkend="protocol-spec-{@interface}">
            <xsl:value-of select="@interface"/>
          </link>
          <xsl:if test="@summary" >
            - <xsl:value-of select="@summary"/>
          </xsl:if>
        </simpara>
    </listitem>
  </varlistentry>
</xsl:template>

<!-- enum and bitfield arguemnts -->
<xsl:template match="arg[@enum]">
  <varlistentry>
    <term><xsl:value-of select="@name"/></term>
    <listitem>
        <simpara>
          <xsl:choose>
            <xsl:when test="contains(@enum, '.')">
              <link linkend="protocol-spec-{substring-before(@enum, '.')}-enum-{substring-after(@enum, '.')}">
                <xsl:value-of select="substring-before(@enum, '.')"/>
                <xsl:text>::</xsl:text>
                <xsl:value-of select="substring-after(@enum, '.')"/>
              </link>
            </xsl:when>
            <xsl:otherwise>
              <link linkend="protocol-spec-{../../@name}-enum-{@enum}">
                <xsl:value-of select="../../@name"/>
                <xsl:text>::</xsl:text>
                <xsl:value-of select="@enum"/>
              </link>
            </xsl:otherwise>
          </xsl:choose>
          (<xsl:value-of select="@type"/>)
          <xsl:if test="@summary" >
            - <xsl:value-of select="@summary"/>
          </xsl:if>
        </simpara>
    </listitem>
  </varlistentry>
</xsl:template>

<!-- Request/event list -->
<xsl:template match="request|event">
  <section id="protocol-spec-{../@name}-{name()}-{@name}">
    <title>
      <xsl:value-of select="../@name"/>::<xsl:value-of select="@name" />
      <xsl:if test="description/@summary">
        - <xsl:value-of select="description/@summary" />
      </xsl:if>
    </title>
    <para>
      <variablelist>
        <xsl:apply-templates select="arg"/>
      </variablelist>
    </para>
    <xsl:call-template name="break">
      <xsl:with-param name="text" select="description" />
    </xsl:call-template>
  </section>
</xsl:template>

<!-- Enumeration -->
<xsl:template match="enum">
  <section id="protocol-spec-{../@name}-enum-{@name}">
    <title>
      <xsl:value-of select="../@name"/>::<xsl:value-of select="@name" />
      <xsl:if test="@bitfield">
        - bitfield
      </xsl:if>
      <xsl:if test="description/@summary">
        - <xsl:value-of select="description/@summary" />
      </xsl:if>
    </title>
    <xsl:call-template name="break">
      <xsl:with-param name="text" select="description" />
    </xsl:call-template>
    <variablelist>
      <xsl:apply-templates select="entry"/>
    </variablelist>
  </section>
</xsl:template>

</xsl:stylesheet>

<!-- vim: set expandtab shiftwidth=2: -->