python3Packages.xknx: 1.1.0 -> 1.2.0
[NixPkgs.git] / nixos / lib / make-options-doc / options-to-docbook.xsl
blob0fe14a6d2d169c34aaf02fdc07b89fc92aa91df6
1 <?xml version="1.0"?>
3 <xsl:stylesheet version="1.0"
4 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5 xmlns:str="http://exslt.org/strings"
6 xmlns:xlink="http://www.w3.org/1999/xlink"
7 xmlns:nixos="tag:nixos.org"
8 xmlns="http://docbook.org/ns/docbook"
9 extension-element-prefixes="str"
12 <xsl:output method='xml' encoding="UTF-8" />
14 <xsl:param name="revision" />
15 <xsl:param name="documentType" />
16 <xsl:param name="program" />
17 <xsl:param name="variablelistId" />
18 <xsl:param name="optionIdPrefix" />
21 <xsl:template match="/expr/list">
22 <xsl:choose>
23 <xsl:when test="$documentType = 'appendix'">
24 <appendix xml:id="appendix-configuration-options">
25 <title>Configuration Options</title>
26 <xsl:call-template name="variable-list"/>
27 </appendix>
28 </xsl:when>
29 <xsl:otherwise>
30 <xsl:call-template name="variable-list"/>
31 </xsl:otherwise>
32 </xsl:choose>
33 </xsl:template>
35 <xsl:template name="variable-list">
36 <variablelist>
37 <xsl:attribute name="id" namespace="http://www.w3.org/XML/1998/namespace"><xsl:value-of select="$variablelistId"/></xsl:attribute>
38 <xsl:for-each select="attrs">
39 <xsl:variable name="id" select="
40 concat($optionIdPrefix,
41 translate(
42 attr[@name = 'name']/string/@value,
43 '*&lt; >[]:&quot;',
44 '________'
45 ))" />
46 <varlistentry>
47 <term xlink:href="#{$id}">
48 <xsl:attribute name="xml:id"><xsl:value-of select="$id"/></xsl:attribute>
49 <option>
50 <xsl:value-of select="attr[@name = 'name']/string/@value" />
51 </option>
52 </term>
54 <listitem>
56 <nixos:option-description>
57 <para>
58 <xsl:value-of disable-output-escaping="yes"
59 select="attr[@name = 'description']/string/@value" />
60 </para>
61 </nixos:option-description>
63 <xsl:if test="attr[@name = 'type']">
64 <para>
65 <emphasis>Type:</emphasis>
66 <xsl:text> </xsl:text>
67 <xsl:value-of select="attr[@name = 'type']/string/@value"/>
68 <xsl:if test="attr[@name = 'readOnly']/bool/@value = 'true'">
69 <xsl:text> </xsl:text>
70 <emphasis>(read only)</emphasis>
71 </xsl:if>
72 </para>
73 </xsl:if>
75 <xsl:if test="attr[@name = 'default']">
76 <para>
77 <emphasis>Default:</emphasis>
78 <xsl:text> </xsl:text>
79 <xsl:apply-templates select="attr[@name = 'default']/*" mode="top" />
80 </para>
81 </xsl:if>
83 <xsl:if test="attr[@name = 'example']">
84 <para>
85 <emphasis>Example:</emphasis>
86 <xsl:text> </xsl:text>
87 <xsl:apply-templates select="attr[@name = 'example']/*" mode="top" />
88 </para>
89 </xsl:if>
91 <xsl:if test="attr[@name = 'relatedPackages']">
92 <para>
93 <emphasis>Related packages:</emphasis>
94 <xsl:text> </xsl:text>
95 <xsl:value-of disable-output-escaping="yes"
96 select="attr[@name = 'relatedPackages']/string/@value" />
97 </para>
98 </xsl:if>
100 <xsl:if test="count(attr[@name = 'declarations']/list/*) != 0">
101 <para>
102 <emphasis>Declared by:</emphasis>
103 </para>
104 <xsl:apply-templates select="attr[@name = 'declarations']" />
105 </xsl:if>
107 <xsl:if test="count(attr[@name = 'definitions']/list/*) != 0">
108 <para>
109 <emphasis>Defined by:</emphasis>
110 </para>
111 <xsl:apply-templates select="attr[@name = 'definitions']" />
112 </xsl:if>
114 </listitem>
116 </varlistentry>
118 </xsl:for-each>
120 </variablelist>
121 </xsl:template>
124 <xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalExpression']]]" mode = "top">
125 <xsl:choose>
126 <xsl:when test="contains(attr[@name = 'text']/string/@value, '&#010;')">
127 <programlisting><xsl:value-of select="attr[@name = 'text']/string/@value" /></programlisting>
128 </xsl:when>
129 <xsl:otherwise>
130 <literal><xsl:value-of select="attr[@name = 'text']/string/@value" /></literal>
131 </xsl:otherwise>
132 </xsl:choose>
133 </xsl:template>
136 <xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalDocBook']]]" mode = "top">
137 <xsl:value-of disable-output-escaping="yes" select="attr[@name = 'text']/string/@value" />
138 </xsl:template>
141 <xsl:template match="string[contains(@value, '&#010;')]" mode="top">
142 <programlisting>
143 <xsl:text>''&#010;</xsl:text>
144 <xsl:value-of select='str:replace(str:replace(@value, "&apos;&apos;", "&apos;&apos;&apos;"), "${", "&apos;&apos;${")' />
145 <xsl:text>''</xsl:text>
146 </programlisting>
147 </xsl:template>
150 <xsl:template match="*" mode="top">
151 <literal><xsl:apply-templates select="." /></literal>
152 </xsl:template>
155 <xsl:template match="null">
156 <xsl:text>null</xsl:text>
157 </xsl:template>
160 <xsl:template match="string">
161 <xsl:choose>
162 <xsl:when test="(contains(@value, '&quot;') or contains(@value, '\')) and not(contains(@value, '&#010;'))">
163 <xsl:text>''</xsl:text><xsl:value-of select='str:replace(str:replace(@value, "&apos;&apos;", "&apos;&apos;&apos;"), "${", "&apos;&apos;${")' /><xsl:text>''</xsl:text>
164 </xsl:when>
165 <xsl:otherwise>
166 <xsl:text>"</xsl:text><xsl:value-of select="str:replace(str:replace(str:replace(str:replace(@value, '\', '\\'), '&quot;', '\&quot;'), '&#010;', '\n'), '${', '\${')" /><xsl:text>"</xsl:text>
167 </xsl:otherwise>
168 </xsl:choose>
169 </xsl:template>
172 <xsl:template match="int">
173 <xsl:value-of select="@value" />
174 </xsl:template>
177 <xsl:template match="bool[@value = 'true']">
178 <xsl:text>true</xsl:text>
179 </xsl:template>
182 <xsl:template match="bool[@value = 'false']">
183 <xsl:text>false</xsl:text>
184 </xsl:template>
187 <xsl:template match="list">
189 <xsl:for-each select="*">
190 <xsl:apply-templates select="." />
191 <xsl:text> </xsl:text>
192 </xsl:for-each>
194 </xsl:template>
197 <xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalExpression']]]">
198 <xsl:value-of select="attr[@name = 'text']/string/@value" />
199 </xsl:template>
202 <xsl:template match="attrs">
204 <xsl:for-each select="attr">
205 <xsl:value-of select="@name" />
206 <xsl:text> = </xsl:text>
207 <xsl:apply-templates select="*" /><xsl:text>; </xsl:text>
208 </xsl:for-each>
210 </xsl:template>
213 <xsl:template match="attrs[attr[@name = '_type' and string[@value = 'derivation']]]">
214 <replaceable>(build of <xsl:value-of select="attr[@name = 'name']/string/@value" />)</replaceable>
215 </xsl:template>
217 <xsl:template match="attr[@name = 'declarations' or @name = 'definitions']">
218 <simplelist>
219 <!--
220 Example:
221 opt.declarations = [ { name = "foo/bar.nix"; url = "https://github.com/....."; } ];
223 <xsl:for-each select="list/attrs[attr[@name = 'name']]">
224 <member><filename>
225 <xsl:if test="attr[@name = 'url']">
226 <xsl:attribute name="xlink:href"><xsl:value-of select="attr[@name = 'url']/string/@value"/></xsl:attribute>
227 </xsl:if>
228 <xsl:value-of select="attr[@name = 'name']/string/@value"/>
229 </filename></member>
230 </xsl:for-each>
232 <!--
233 When the declarations/definitions are raw strings,
234 fall back to hardcoded location logic, specific to Nixpkgs.
236 <xsl:for-each select="list/string">
237 <member><filename>
238 <!-- Hyperlink the filename either to the NixOS Subversion
239 repository (if it’s a module and we have a revision number),
240 or to the local filesystem. -->
241 <xsl:choose>
242 <xsl:when test="not(starts-with(@value, '/'))">
243 <xsl:choose>
244 <xsl:when test="$revision = 'local'">
245 <xsl:attribute name="xlink:href">https://github.com/NixOS/nixpkgs/blob/master/<xsl:value-of select="@value"/></xsl:attribute>
246 </xsl:when>
247 <xsl:otherwise>
248 <xsl:attribute name="xlink:href">https://github.com/NixOS/nixpkgs/blob/<xsl:value-of select="$revision"/>/<xsl:value-of select="@value"/></xsl:attribute>
249 </xsl:otherwise>
250 </xsl:choose>
251 </xsl:when>
252 <xsl:when test="$revision != 'local' and $program = 'nixops' and contains(@value, '/nix/')">
253 <xsl:attribute name="xlink:href">https://github.com/NixOS/nixops/blob/<xsl:value-of select="$revision"/>/nix/<xsl:value-of select="substring-after(@value, '/nix/')"/></xsl:attribute>
254 </xsl:when>
255 <xsl:otherwise>
256 <xsl:attribute name="xlink:href">file://<xsl:value-of select="@value"/></xsl:attribute>
257 </xsl:otherwise>
258 </xsl:choose>
259 <!-- Print the filename and make it user-friendly by replacing the
260 /nix/store/<hash> prefix by the default location of nixos
261 sources. -->
262 <xsl:choose>
263 <xsl:when test="not(starts-with(@value, '/'))">
264 &lt;nixpkgs/<xsl:value-of select="@value"/>&gt;
265 </xsl:when>
266 <xsl:when test="contains(@value, 'nixops') and contains(@value, '/nix/')">
267 &lt;nixops/<xsl:value-of select="substring-after(@value, '/nix/')"/>&gt;
268 </xsl:when>
269 <xsl:otherwise>
270 <xsl:value-of select="@value" />
271 </xsl:otherwise>
272 </xsl:choose>
273 </filename></member>
274 </xsl:for-each>
275 </simplelist>
276 </xsl:template>
279 <xsl:template match="function">
280 <xsl:text>λ</xsl:text>
281 </xsl:template>
284 </xsl:stylesheet>