Debian Codegraph @

xslt/mallard/html/mal2html-api.xsl

raw
1 <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
2 <!--
3 This program is free software; you can redistribute it and/or modify it under
4 the terms of the GNU Lesser General Public License as published by the Free
5 Software Foundation; either version 2 of the License, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 details.
12
13 You should have received a copy of the GNU Lesser General Public License
14 along with this program; see the file COPYING.LGPL. If not, see <http://www.gnu.org/licenses/>.
15 -->
16
17 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
18 xmlns:mal="http://projectmallard.org/1.0/"
19 xmlns:e="http://projectmallard.org/experimental/"
20 xmlns:api="http://projectmallard.org/experimental/api/"
21 xmlns:exsl="http://exslt.org/common"
22 xmlns:math="http://exslt.org/math"
23 xmlns:html="http://www.w3.org/1999/xhtml"
24 xmlns="http://www.w3.org/1999/xhtml"
25 exclude-result-prefixes="mal e api exsl math html"
26 version="1.0">
27
28 <!--!!==========================================================================
29 Mallard to HTML - API Extension
30 Support for Mallard API extension elements.
31
32 This stylesheet contains templates to support features from the Mallard API
33 extension.
34 -->
35
36
37 <!--**==========================================================================
38 mal2html.api.links.function
39 Output links as a synopsis of functions.
40
41 [xsl:params]
42 $node: A `links` element to link from.
43 $links: A list of topic links already filtered by group.
44
45 This template outputs links as a synopsis according to the programming language
46 specified by the `api:mime` attribute of $node. If `api:mime` is recognized,
47 one of the language-specific templates in this stylesheet is called. Otherwise,
48 the links are passed to {mal2html.links.ul}.
49
50 This template does not handle titles or other wrapper information for `links`
51 elements. It should be called by an appropriate template that handles the
52 `links` element.
53 -->
54 <xsl:template name="mal2html.api.links.function">
55 <xsl:param name="node" select="."/>
56 <xsl:param name="links"/>
57 <xsl:choose>
58 <xsl:when test="$node/@api:mime = 'text/x-csrc' or $node/@api:mime = 'text/x-chdr'">
59 <xsl:call-template name="mal2html.api.links.function.c">
60 <xsl:with-param name="node" select="$node"/>
61 <xsl:with-param name="links" select="$links"/>
62 </xsl:call-template>
63 </xsl:when>
64 <xsl:otherwise>
65 <xsl:call-template name="mal2html.links.ul">
66 <xsl:with-param name="node" select="$node"/>
67 <xsl:with-param name="links" select="$links"/>
68 </xsl:call-template>
69 </xsl:otherwise>
70 </xsl:choose>
71 </xsl:template>
72
73
74 <!--**==========================================================================
75 mal2html.api.links.function.c
76 Output links as a synopsis of C functions.
77
78 [xsl:params]
79 $node: A `links` element to link from.
80 $links: A list of topic links already filtered by group.
81
82 This template outputs links as a synopsis of C functions. It is called by
83 {mal2html.api.links.function} when the `api:mime` attribute of $node is
84 `text/x-csrc` or `text/x-chdr`. The target nodes of $links are expected
85 to have at least an `api:name` element. Any links whose target does not
86 have an `api:name` element will be passed to {mal2html.links.ul} after
87 the synopsis.
88 -->
89 <xsl:template name="mal2html.api.links.function.c">
90 <xsl:param name="node" select="."/>
91 <xsl:param name="links"/>
92 <xsl:variable name="out_">
93 <xsl:for-each select="$links">
94 <xsl:sort data-type="number" select="@groupsort"/>
95 <xsl:sort select="mal:title[@type = 'sort']"/>
96 <xsl:variable name="link" select="."/>
97 <xsl:for-each select="$mal.cache">
98 <xsl:variable name="target" select="key('mal.cache.key', $link/@xref)"/>
99 <xsl:variable name="function" select="$target/mal:info/api:function"/>
100 <xsl:choose>
101 <xsl:when test="$function/api:name">
102 <api:pre>
103 <div class="{$link/@class}">
104 <xsl:for-each select="$link/@*">
105 <xsl:if test="starts-with(name(.), 'data-')">
106 <xsl:copy-of select="."/>
107 </xsl:if>
108 </xsl:for-each>
109 <xsl:apply-templates mode="mal2html.inline.mode" select="$function/api:returns/api:type/node()"/>
110 <xsl:variable name="tab" select="20 - string-length($function/api:returns/api:type)"/>
111 <xsl:choose>
112 <xsl:when test="$tab > 1">
113 <xsl:call-template name="utils.repeat_string">
114 <xsl:with-param name="string" select="' '"/>
115 <xsl:with-param name="number" select="$tab"/>
116 </xsl:call-template>
117 </xsl:when>
118 <xsl:otherwise>
119 <xsl:text>&#x000A;</xsl:text>
120 <xsl:text> </xsl:text>
121 </xsl:otherwise>
122 </xsl:choose>
123 <a>
124 <xsl:attribute name="href">
125 <xsl:call-template name="mal.link.target">
126 <xsl:with-param name="node" select="$node"/>
127 <xsl:with-param name="xref" select="$link/@xref"/>
128 </xsl:call-template>
129 </xsl:attribute>
130 <xsl:attribute name="title">
131 <xsl:call-template name="mal.link.tooltip">
132 <xsl:with-param name="node" select="$node"/>
133 <xsl:with-param name="xref" select="$link/@xref"/>
134 <!-- FIXME: role -->
135 </xsl:call-template>
136 </xsl:attribute>
137 <xsl:value-of select="$function/api:name"/>
138 </a>
139 <xsl:variable name="paren" select="40 - string-length($function/api:name)"/>
140 <xsl:choose>
141 <xsl:when test="$paren > 1">
142 <xsl:call-template name="utils.repeat_string">
143 <xsl:with-param name="string" select="' '"/>
144 <xsl:with-param name="number" select="$paren"/>
145 </xsl:call-template>
146 </xsl:when>
147 <xsl:otherwise>
148 <xsl:text>&#x000A;</xsl:text>
149 <xsl:text> </xsl:text>
150 </xsl:otherwise>
151 </xsl:choose>
152 <xsl:text>(</xsl:text>
153 <xsl:for-each select="$function/api:arg | $function/api:varargs">
154 <xsl:if test="position() != 1">
155 <xsl:text> </xsl:text>
156 </xsl:if>
157 <xsl:choose>
158 <xsl:when test="self::api:varargs">
159 <xsl:text>...</xsl:text>
160 </xsl:when>
161 <xsl:otherwise>
162 <xsl:apply-templates mode="mal2html.inline.mode" select="api:type/node()"/>
163 <xsl:if test="substring(api:type, string-length(api:type)) != '*'
164 or not(contains(api:type, ' '))">
165 <xsl:text> </xsl:text>
166 </xsl:if>
167 <xsl:apply-templates mode="mal2html.inline.mode" select="api:name/node()"/>
168 </xsl:otherwise>
169 </xsl:choose>
170 <xsl:choose>
171 <xsl:when test="position() != last()">
172 <xsl:text>,</xsl:text>
173 </xsl:when>
174 <xsl:otherwise>
175 <xsl:text>);</xsl:text>
176 </xsl:otherwise>
177 </xsl:choose>
178 <xsl:text>&#x000A;</xsl:text>
179 </xsl:for-each>
180 <xsl:if test="not($function/api:arg or $function/api:varargs)">
181 <xsl:text>void);&#x000A;</xsl:text>
182 </xsl:if>
183 </div>
184 </api:pre>
185 </xsl:when>
186 <xsl:otherwise>
187 <xsl:copy-of select="$link"/>
188 </xsl:otherwise>
189 </xsl:choose>
190 </xsl:for-each>
191 </xsl:for-each>
192 </xsl:variable>
193 <xsl:variable name="out" select="exsl:node-set($out_)"/>
194 <xsl:if test="$out/api:pre">
195 <div class="synopsis">
196 <pre class="contents">
197 <xsl:copy-of select="$out/api:pre/*"/>
198 </pre>
199 </div>
200 </xsl:if>
201 <xsl:if test="$out/mal:link">
202 <xsl:call-template name="mal2html.links.ul">
203 <xsl:with-param name="node" select="$node"/>
204 <xsl:with-param name="links" select="$out/mal:link"/>
205 </xsl:call-template>
206 </xsl:if>
207 </xsl:template>
208
209 </xsl:stylesheet>