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