summaryrefslogtreecommitdiff
path: root/xslt/docbook/html/db2html-funcsynopsis.xsl
blob: d9c612e96df3de490e9c3d304c62438e38898028 (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
<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
<!--
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option) any
later version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License
along with this program; see the file COPYING.LGPL.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:str="http://exslt.org/strings"
                xmlns="http://www.w3.org/1999/xhtml"
                extension-element-prefixes="str"
                version="1.0">

<!--!!==========================================================================
DocBook to HTML - Function Synopses
:Requires: db2html-block db2html-inline

REMARK: Describe this module
-->


<!--@@==========================================================================
db2html.funcsynopsis.style
How to render #{funcsynopsis} elements

This parameter controls the indentation style used to render #{funcsynopsis}
elements.  Supported values are #{'KR'} and #{'ANSI'}.  This value can also
be set with the #{db2html.funcsynopsis.style} processing instruction at the
top of the XML document.  The same processing instruction or inside a
#{funcsynopsis} element will override this setting for that synopsis.
-->
<xsl:param name="db2html.funcsynopsis.style">
  <xsl:choose>
    <xsl:when test="/processing-instruction('db2html.funcsynopsis.style')">
      <xsl:value-of select="/processing-instruction('db2html.funcsynopsis.style')"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="'ANSI'"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:param>


<!-- == Matched Templates == -->

<!-- = funcdef = -->
<xsl:template match="funcdef">
  <xsl:call-template name="db2html.inline"/>
</xsl:template>

<!-- = funcparams = -->
<xsl:template match="funcparams">
  <xsl:text>(</xsl:text>
  <xsl:call-template name="db2html.inline"/>
  <xsl:text>)</xsl:text>
</xsl:template>

<!-- = funcprototype = -->
<xsl:template match="funcprototype">
  <xsl:variable name="style">
    <xsl:choose>
      <xsl:when test="../processing-instruction('db2html.funcsynopsis.style')">
        <xsl:value-of select="../processing-instruction('db2html.funcsynopsis.style')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$db2html.funcsynopsis.style"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:for-each select="funcdef/preceding-sibling::modifier">
    <xsl:apply-templates select="."/>
    <xsl:text> </xsl:text>
  </xsl:for-each>
  <xsl:apply-templates select="funcdef"/>
  <xsl:text> (</xsl:text>
  <xsl:choose>
    <xsl:when test="$style = 'KR'">
      <xsl:for-each select="void | varargs | paramdef">
        <xsl:if test="position() != 1">
          <xsl:text>, </xsl:text>
        </xsl:if>
        <xsl:choose>
          <xsl:when test="self::paramdef">
            <xsl:call-template name="db2html.inline">
              <xsl:with-param name="node" select="."/>
              <xsl:with-param name="children" select="parameter"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates select="."/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
      <xsl:text>)</xsl:text>
      <xsl:for-each select="funcdef/following-sibling::modifier">
        <xsl:text> </xsl:text>
        <xsl:apply-templates select="."/>
      </xsl:for-each>
      <xsl:text>;</xsl:text>
      <xsl:for-each select="paramdef">
        <xsl:text>&#x000A;    </xsl:text>
        <xsl:apply-templates select="."/>
        <xsl:text>;</xsl:text>
      </xsl:for-each>
    </xsl:when>
    <!-- ANSI is the default -->
    <xsl:otherwise>
      <xsl:variable name="indent">
        <xsl:call-template name="_db2html.funcsynopsis.pad">
          <xsl:with-param name="nodes" select="funcdef | funcdef/preceding-sibling::modifier"/>
        </xsl:call-template>
        <xsl:value-of select="str:padding(count(funcdef/preceding-sibling::modifier) + 2)"/>
      </xsl:variable>
      <xsl:for-each select="void | varargs | paramdef">
        <xsl:if test="position() != 1">
          <xsl:text>,&#x000A;</xsl:text>
          <xsl:value-of select="$indent"/>
        </xsl:if>
        <xsl:apply-templates select="."/>
      </xsl:for-each>
      <xsl:text>)</xsl:text>
      <xsl:for-each select="funcdef/following-sibling::modifier">
        <xsl:text> </xsl:text>
        <xsl:apply-templates select="."/>
      </xsl:for-each>
      <xsl:text>;</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- = funcsynopsis = -->
<xsl:template match="funcsynopsis">
  <xsl:call-template name="db2html.pre">
    <xsl:with-param name="node" select="."/>
    <xsl:with-param name="indent" select="true()"/>
    <xsl:with-param name="children" select="*"/>
  </xsl:call-template>
</xsl:template>

<!-- = funcsynopsisinfo = -->
<xsl:template match="funcsynopsisinfo">
  <xsl:call-template name="db2html.pre"/>
</xsl:template>

<!-- = initializer = -->
<xsl:template match="initializer">
  <xsl:call-template name="db2html.inline"/>
</xsl:template>

<!-- = modifier = -->
<xsl:template match="modifier">
  <xsl:call-template name="db2html.inline"/>
</xsl:template>

<!-- = paramdef = -->
<xsl:template match="paramdef">
  <xsl:call-template name="db2html.inline"/>
</xsl:template>

<!-- = varargs = -->
<xsl:template match="varargs">
  <xsl:text>...</xsl:text>
</xsl:template>

<!-- = void = -->
<xsl:template match="void">
  <xsl:text>void</xsl:text>
</xsl:template>


<!-- == Utility Templates == -->

<!--#* _db2html.funcsynopsis.pad -->
<xsl:template name="_db2html.funcsynopsis.pad">
  <xsl:param name="nodes"/>
  <xsl:value-of select="str:padding(string-length($nodes[1]))"/>
  <xsl:if test="$nodes[position() != 1]">
    <xsl:call-template name="_db2html.funcsynopsis.pad">
      <xsl:with-param name="nodes" select="$nodes[position() != 1]"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>