1<?xml version="1.0"?>
2
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"
10 >
11
12 <xsl:output method='xml' encoding="UTF-8" />
13
14 <xsl:param name="revision" />
15 <xsl:param name="program" />
16
17
18 <xsl:template match="/expr/list">
19 <appendix xml:id="appendix-configuration-options">
20 <title>Configuration Options</title>
21 <variablelist xml:id="configuration-variable-list">
22 <xsl:for-each select="attrs">
23 <xsl:variable name="id" select="concat('opt-', str:replace(str:replace(str:replace(attr[@name = 'name']/string/@value, '*', '_'), '<', '_'), '>', '_'))" />
24 <varlistentry>
25 <term xlink:href="#{$id}">
26 <xsl:attribute name="xml:id"><xsl:value-of select="$id"/></xsl:attribute>
27 <option>
28 <xsl:value-of select="attr[@name = 'name']/string/@value" />
29 </option>
30 </term>
31
32 <listitem>
33
34 <nixos:option-description>
35 <para>
36 <xsl:value-of disable-output-escaping="yes"
37 select="attr[@name = 'description']/string/@value" />
38 </para>
39 </nixos:option-description>
40
41 <xsl:if test="attr[@name = 'type']">
42 <para>
43 <emphasis>Type:</emphasis>
44 <xsl:text> </xsl:text>
45 <xsl:value-of select="attr[@name = 'type']/string/@value"/>
46 <xsl:if test="attr[@name = 'readOnly']/bool/@value = 'true'">
47 <xsl:text> </xsl:text>
48 <emphasis>(read only)</emphasis>
49 </xsl:if>
50 </para>
51 </xsl:if>
52
53 <xsl:if test="attr[@name = 'default']">
54 <para>
55 <emphasis>Default:</emphasis>
56 <xsl:text> </xsl:text>
57 <xsl:apply-templates select="attr[@name = 'default']" mode="top" />
58 </para>
59 </xsl:if>
60
61 <xsl:if test="attr[@name = 'example']">
62 <para>
63 <emphasis>Example:</emphasis>
64 <xsl:text> </xsl:text>
65 <xsl:choose>
66 <xsl:when test="attr[@name = 'example']/attrs[attr[@name = '_type' and string[@value = 'literalExample']]]">
67 <programlisting><xsl:value-of select="attr[@name = 'example']/attrs/attr[@name = 'text']/string/@value" /></programlisting>
68 </xsl:when>
69 <xsl:otherwise>
70 <xsl:apply-templates select="attr[@name = 'example']" mode="top" />
71 </xsl:otherwise>
72 </xsl:choose>
73 </para>
74 </xsl:if>
75
76 <xsl:if test="attr[@name = 'relatedPackages']">
77 <para>
78 <emphasis>Related packages:</emphasis>
79 <xsl:text> </xsl:text>
80 <xsl:value-of disable-output-escaping="yes"
81 select="attr[@name = 'relatedPackages']/string/@value" />
82 </para>
83 </xsl:if>
84
85 <xsl:if test="count(attr[@name = 'declarations']/list/*) != 0">
86 <para>
87 <emphasis>Declared by:</emphasis>
88 </para>
89 <xsl:apply-templates select="attr[@name = 'declarations']" />
90 </xsl:if>
91
92 <xsl:if test="count(attr[@name = 'definitions']/list/*) != 0">
93 <para>
94 <emphasis>Defined by:</emphasis>
95 </para>
96 <xsl:apply-templates select="attr[@name = 'definitions']" />
97 </xsl:if>
98
99 </listitem>
100
101 </varlistentry>
102
103 </xsl:for-each>
104
105 </variablelist>
106 </appendix>
107 </xsl:template>
108
109
110 <xsl:template match="*" mode="top">
111 <xsl:choose>
112 <xsl:when test="string[contains(@value, '
')]">
113<programlisting>
114<xsl:text>''
115</xsl:text><xsl:value-of select='str:replace(string/@value, "${", "''${")' /><xsl:text>''</xsl:text></programlisting>
116 </xsl:when>
117 <xsl:otherwise>
118 <literal><xsl:apply-templates /></literal>
119 </xsl:otherwise>
120 </xsl:choose>
121 </xsl:template>
122
123
124 <xsl:template match="null">
125 <xsl:text>null</xsl:text>
126 </xsl:template>
127
128
129 <xsl:template match="string">
130 <xsl:choose>
131 <xsl:when test="(contains(@value, '"') or contains(@value, '\')) and not(contains(@value, '
'))">
132 <xsl:text>''</xsl:text><xsl:value-of select='str:replace(@value, "${", "''${")' /><xsl:text>''</xsl:text>
133 </xsl:when>
134 <xsl:otherwise>
135 <xsl:text>"</xsl:text><xsl:value-of select="str:replace(str:replace(str:replace(str:replace(@value, '\', '\\'), '"', '\"'), '
', '\n'), '$', '\$')" /><xsl:text>"</xsl:text>
136 </xsl:otherwise>
137 </xsl:choose>
138 </xsl:template>
139
140
141 <xsl:template match="int">
142 <xsl:value-of select="@value" />
143 </xsl:template>
144
145
146 <xsl:template match="bool[@value = 'true']">
147 <xsl:text>true</xsl:text>
148 </xsl:template>
149
150
151 <xsl:template match="bool[@value = 'false']">
152 <xsl:text>false</xsl:text>
153 </xsl:template>
154
155
156 <xsl:template match="list">
157 [
158 <xsl:for-each select="*">
159 <xsl:apply-templates select="." />
160 <xsl:text> </xsl:text>
161 </xsl:for-each>
162 ]
163 </xsl:template>
164
165
166 <xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalExample']]]">
167 <xsl:value-of select="attr[@name = 'text']/string/@value" />
168 </xsl:template>
169
170
171 <xsl:template match="attrs">
172 {
173 <xsl:for-each select="attr">
174 <xsl:value-of select="@name" />
175 <xsl:text> = </xsl:text>
176 <xsl:apply-templates select="*" /><xsl:text>; </xsl:text>
177 </xsl:for-each>
178 }
179 </xsl:template>
180
181
182 <xsl:template match="derivation">
183 <replaceable>(build of <xsl:value-of select="attr[@name = 'name']/string/@value" />)</replaceable>
184 </xsl:template>
185
186 <xsl:template match="attr[@name = 'declarations' or @name = 'definitions']">
187 <simplelist>
188 <xsl:for-each select="list/string">
189 <member><filename>
190 <!-- Hyperlink the filename either to the NixOS Subversion
191 repository (if it’s a module and we have a revision number),
192 or to the local filesystem. -->
193 <xsl:choose>
194 <xsl:when test="not(starts-with(@value, '/'))">
195 <xsl:choose>
196 <xsl:when test="$revision = 'local'">
197 <xsl:attribute name="xlink:href">https://github.com/NixOS/nixpkgs/blob/master/<xsl:value-of select="@value"/></xsl:attribute>
198 </xsl:when>
199 <xsl:otherwise>
200 <xsl:attribute name="xlink:href">https://github.com/NixOS/nixpkgs/blob/<xsl:value-of select="$revision"/>/<xsl:value-of select="@value"/></xsl:attribute>
201 </xsl:otherwise>
202 </xsl:choose>
203 </xsl:when>
204 <xsl:when test="$revision != 'local' and $program = 'nixops' and contains(@value, '/nix/')">
205 <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>
206 </xsl:when>
207 <xsl:otherwise>
208 <xsl:attribute name="xlink:href">file://<xsl:value-of select="@value"/></xsl:attribute>
209 </xsl:otherwise>
210 </xsl:choose>
211 <!-- Print the filename and make it user-friendly by replacing the
212 /nix/store/<hash> prefix by the default location of nixos
213 sources. -->
214 <xsl:choose>
215 <xsl:when test="not(starts-with(@value, '/'))">
216 <nixpkgs/<xsl:value-of select="@value"/>>
217 </xsl:when>
218 <xsl:when test="contains(@value, 'nixops') and contains(@value, '/nix/')">
219 <nixops/<xsl:value-of select="substring-after(@value, '/nix/')"/>>
220 </xsl:when>
221 <xsl:otherwise>
222 <xsl:value-of select="@value" />
223 </xsl:otherwise>
224 </xsl:choose>
225 </filename></member>
226 </xsl:for-each>
227 </simplelist>
228 </xsl:template>
229
230
231 <xsl:template match="function">
232 <xsl:text>λ</xsl:text>
233 </xsl:template>
234
235
236</xsl:stylesheet>