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
19 <variablelist>
20
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="count(attr[@name = 'declarations']/list/*) != 0">
74 <para>
75 <emphasis>Declared by:</emphasis>
76 </para>
77 <xsl:apply-templates select="attr[@name = 'declarations']" />
78 </xsl:if>
79
80 <xsl:if test="count(attr[@name = 'definitions']/list/*) != 0">
81 <para>
82 <emphasis>Defined by:</emphasis>
83 </para>
84 <xsl:apply-templates select="attr[@name = 'definitions']" />
85 </xsl:if>
86
87 </listitem>
88
89 </varlistentry>
90
91 </xsl:for-each>
92
93 </variablelist>
94
95 </xsl:template>
96
97
98 <xsl:template match="*" mode="top">
99 <xsl:choose>
100 <xsl:when test="string[contains(@value, '
')]">
101<programlisting>
102<xsl:text>''
103</xsl:text><xsl:value-of select='str:replace(string/@value, "${", "''${")' /><xsl:text>''</xsl:text></programlisting>
104 </xsl:when>
105 <xsl:otherwise>
106 <literal><xsl:apply-templates /></literal>
107 </xsl:otherwise>
108 </xsl:choose>
109 </xsl:template>
110
111
112 <xsl:template match="null">
113 <xsl:text>null</xsl:text>
114 </xsl:template>
115
116
117 <xsl:template match="string">
118 <xsl:choose>
119 <xsl:when test="(contains(@value, '"') or contains(@value, '\')) and not(contains(@value, '
'))">
120 <xsl:text>''</xsl:text><xsl:value-of select='str:replace(@value, "${", "''${")' /><xsl:text>''</xsl:text>
121 </xsl:when>
122 <xsl:otherwise>
123 <xsl:text>"</xsl:text><xsl:value-of select="str:replace(str:replace(str:replace(str:replace(@value, '\', '\\'), '"', '\"'), '
', '\n'), '$', '\$')" /><xsl:text>"</xsl:text>
124 </xsl:otherwise>
125 </xsl:choose>
126 </xsl:template>
127
128
129 <xsl:template match="int">
130 <xsl:value-of select="@value" />
131 </xsl:template>
132
133
134 <xsl:template match="bool[@value = 'true']">
135 <xsl:text>true</xsl:text>
136 </xsl:template>
137
138
139 <xsl:template match="bool[@value = 'false']">
140 <xsl:text>false</xsl:text>
141 </xsl:template>
142
143
144 <xsl:template match="list">
145 [
146 <xsl:for-each select="*">
147 <xsl:apply-templates select="." />
148 <xsl:text> </xsl:text>
149 </xsl:for-each>
150 ]
151 </xsl:template>
152
153
154 <xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalExample']]]">
155 <xsl:value-of select="attr[@name = 'text']/string/@value" />
156 </xsl:template>
157
158
159 <xsl:template match="attrs">
160 {
161 <xsl:for-each select="attr">
162 <xsl:value-of select="@name" />
163 <xsl:text> = </xsl:text>
164 <xsl:apply-templates select="*" /><xsl:text>; </xsl:text>
165 </xsl:for-each>
166 }
167 </xsl:template>
168
169
170 <xsl:template match="derivation">
171 <replaceable>(build of <xsl:value-of select="attr[@name = 'name']/string/@value" />)</replaceable>
172 </xsl:template>
173
174 <xsl:template match="attr[@name = 'declarations' or @name = 'definitions']">
175 <simplelist>
176 <xsl:for-each select="list/string">
177 <member><filename>
178 <!-- Hyperlink the filename either to the NixOS Subversion
179 repository (if it’s a module and we have a revision number),
180 or to the local filesystem. -->
181 <xsl:choose>
182 <xsl:when test="not(starts-with(@value, '/'))">
183 <xsl:choose>
184 <xsl:when test="$revision = 'local'">
185 <xsl:attribute name="xlink:href">https://github.com/NixOS/nixpkgs/blob/master/<xsl:value-of select="@value"/></xsl:attribute>
186 </xsl:when>
187 <xsl:otherwise>
188 <xsl:attribute name="xlink:href">https://github.com/NixOS/nixpkgs/blob/<xsl:value-of select="$revision"/>/<xsl:value-of select="@value"/></xsl:attribute>
189 </xsl:otherwise>
190 </xsl:choose>
191 </xsl:when>
192 <xsl:when test="$revision != 'local' and $program = 'nixops' and contains(@value, '/nix/')">
193 <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>
194 </xsl:when>
195 <xsl:otherwise>
196 <xsl:attribute name="xlink:href">file://<xsl:value-of select="@value"/></xsl:attribute>
197 </xsl:otherwise>
198 </xsl:choose>
199 <!-- Print the filename and make it user-friendly by replacing the
200 /nix/store/<hash> prefix by the default location of nixos
201 sources. -->
202 <xsl:choose>
203 <xsl:when test="not(starts-with(@value, '/'))">
204 <nixpkgs/<xsl:value-of select="@value"/>>
205 </xsl:when>
206 <xsl:when test="contains(@value, 'nixops') and contains(@value, '/nix/')">
207 <nixops/<xsl:value-of select="substring-after(@value, '/nix/')"/>>
208 </xsl:when>
209 <xsl:otherwise>
210 <xsl:value-of select="@value" />
211 </xsl:otherwise>
212 </xsl:choose>
213 </filename></member>
214 </xsl:for-each>
215 </simplelist>
216 </xsl:template>
217
218
219 <xsl:template match="function">
220 <xsl:text>λ</xsl:text>
221 </xsl:template>
222
223
224</xsl:stylesheet>