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