xref: /unit/docs/changes.xslt (revision 794:afd6fc00e8f2)
1<?xml version="1.0" encoding="utf-8"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3
4<xsl:output method="text"/>
5
6<xsl:param select="'generic'" name="format"/>
7<xsl:param select="'unit'" name="pkgname"/>
8<xsl:param select="'change_log_conf.xml'" name="configuration"/>
9
10<xsl:variable select="document($configuration)/configuration" name="conf"/>
11
12<xsl:variable name="start">
13    <xsl:choose>
14        <xsl:when test="$format='rpm'">
15            <xsl:value-of select="$conf/rpm/start"/>
16        </xsl:when>
17        <xsl:when test="$format='deb'">
18            <xsl:value-of select="$conf/deb/start"/>
19        </xsl:when>
20        <xsl:when test="$format='generic'">
21            <xsl:value-of select="$conf/generic/start"/>
22        </xsl:when>
23    </xsl:choose>
24</xsl:variable>
25
26<xsl:variable name="indent">
27    <xsl:choose>
28        <xsl:when test="$format='rpm'">
29            <xsl:value-of select="$conf/rpm/indent"/>
30        </xsl:when>
31        <xsl:when test="$format='deb'">
32            <xsl:value-of select="$conf/deb/indent"/>
33        </xsl:when>
34        <xsl:when test="$format='generic'">
35            <xsl:value-of select="$conf/generic/indent"/>
36        </xsl:when>
37    </xsl:choose>
38</xsl:variable>
39
40<xsl:variable name="max">
41    <xsl:choose>
42        <xsl:when test="$format='rpm'">
43            <xsl:value-of select="$conf/rpm/length"/>
44        </xsl:when>
45        <xsl:when test="$format='deb'">
46            <xsl:value-of select="$conf/deb/length"/>
47        </xsl:when>
48        <xsl:when test="$format='generic'">
49            <xsl:value-of select="$conf/generic/length"/>
50        </xsl:when>
51    </xsl:choose>
52</xsl:variable>
53
54<xsl:variable name="br">&lt;br&gt;</xsl:variable>
55
56
57<xsl:template match="/"> <xsl:apply-templates select="change_log"/> </xsl:template>
58<xsl:template match="change_log"> <xsl:apply-templates select="changes"/> </xsl:template>
59
60
61<xsl:template match="changes">
62    <xsl:variable name="pday"> <xsl:call-template name="padded_day"><xsl:with-param select="@date" name="date"/></xsl:call-template></xsl:variable>
63    <xsl:variable name="dow"> <xsl:call-template name="day_of_week"><xsl:with-param select="@date" name="date"/></xsl:call-template></xsl:variable>
64    <xsl:variable name="apply"> <xsl:call-template name="string_in_list"><xsl:with-param select="@apply" name="list"/><xsl:with-param select="$pkgname" name="string"/></xsl:call-template></xsl:variable>
65    <xsl:variable name="pkgname_"> <xsl:call-template name="beautify"><xsl:with-param select="$pkgname" name="pkgname"/></xsl:call-template></xsl:variable>
66
67    <xsl:choose>
68    <xsl:when test="$pkgname='unit' and $format='generic' and @rev!=1"/>
69    <xsl:otherwise>
70    <xsl:if test="$apply=$pkgname">
71
72    <xsl:if test="$format='generic'">
73        <xsl:text>&#10;</xsl:text>
74
75        <xsl:value-of select="substring(concat($conf/changes/title,
76                           $pkgname_,
77                           ' ', @ver,
78                           '                                                    '),
79                    1, $conf/changes/length)"/>
80
81        <xsl:value-of select="substring(@date, 9, 2)"/>
82        <xsl:value-of select="$conf/changes/month[number(substring(current()/@date,
83                                                            6, 2))]"/>
84        <xsl:value-of select="substring(@date, 1, 4)"/>
85    </xsl:if>
86
87    <xsl:if test="$format='rpm'">
88        <xsl:value-of select="concat('* ', $conf/changes/day[number($dow)],
89                 $conf/changes/month[number(substring(current()/@date, 6, 2))],
90                 $pday, ' ',
91                 substring(@date, 1, 4), ' ', @packager, ' - ',
92                 @ver, '-', @rev, '%{?dist}.ngx')"/>
93    </xsl:if>
94
95    <xsl:if test="$format='deb'">
96        <xsl:value-of select="concat($pkgname, ' (', @ver, '-', @rev,
97                 '~%%CODENAME%%) %%CODENAME%%; urgency=low')"/>
98
99        <xsl:text>&#10;</xsl:text>
100    </xsl:if>
101
102    <xsl:text>&#10;</xsl:text>
103
104    <xsl:apply-templates select="change"/>
105
106    <xsl:text>&#10;</xsl:text>
107
108    <xsl:if test="$format='deb'">
109        <xsl:value-of select="concat(' -- ', @packager, '  ',
110                 $conf/changes/day[number($dow)], ', ',
111                 $pday,
112                 $conf/changes/month[number(substring(current()/@date, 6, 2))],
113                 substring(@date, 1, 4), ' ', @time)"/>
114
115        <xsl:text>&#10;</xsl:text>
116        <xsl:text>&#10;</xsl:text>
117    </xsl:if>
118    </xsl:if>
119    </xsl:otherwise>
120    </xsl:choose>
121</xsl:template>
122
123
124<xsl:template match="change">
125    <xsl:variable select="$conf/changes/*[local-name(.)=current()/@type]" name="prefix"/>
126
127    <xsl:variable name="postfix"> <xsl:if test="$prefix"> <xsl:text>: </xsl:text> </xsl:if> </xsl:variable>
128
129    <xsl:apply-templates select="para"><xsl:with-param select="concat($start, $prefix, $postfix)" name="prefix"/></xsl:apply-templates>
130</xsl:template>
131
132
133<xsl:template name="para" match="para"><xsl:param name="prefix"/>
134    <xsl:variable name="text"> <xsl:apply-templates/> </xsl:variable>
135
136    <xsl:if test="$format='generic'">
137        <xsl:text>&#10;</xsl:text>
138    </xsl:if>
139
140    <xsl:call-template name="wrap"><xsl:with-param select="normalize-space($text)" name="text"/><xsl:with-param name="prefix"> <xsl:choose><xsl:when test="position() = 1"> <xsl:value-of select="$prefix"/> </xsl:when><xsl:otherwise> <xsl:value-of select="$indent"/> </xsl:otherwise></xsl:choose> </xsl:with-param></xsl:call-template></xsl:template>
141
142
143<xsl:template name="wrap"><xsl:param name="text"/><xsl:param name="prefix"/>
144    <xsl:if test="$text">
145        <xsl:variable name="offset">
146            <xsl:choose>
147                <xsl:when test="starts-with($text, concat($br, ' '))">
148                    <xsl:value-of select="string-length($br) + 2"/>
149                </xsl:when>
150                <xsl:when test="starts-with($text, $br)">
151                    <xsl:value-of select="string-length($br) + 1"/>
152                </xsl:when>
153                <xsl:otherwise>
154                    1
155                </xsl:otherwise>
156            </xsl:choose>
157        </xsl:variable>
158
159        <xsl:variable name="length">
160            <xsl:call-template name="length"><xsl:with-param select="substring($text, $offset)" name="text"/><xsl:with-param select="string-length($prefix)" name="prefix"/><xsl:with-param select="$max" name="length"/></xsl:call-template></xsl:variable>
161
162        <xsl:value-of select="$prefix"/>
163
164        <xsl:value-of select="normalize-space(translate(substring($text, $offset, $length),
165                                    '&#xA0;', ' '))"/>
166
167        <xsl:text>&#10;</xsl:text>
168
169        <xsl:call-template name="wrap"><xsl:with-param select="substring($text, $length + $offset)" name="text"/><xsl:with-param select="$indent" name="prefix"/></xsl:call-template></xsl:if>
170</xsl:template>
171
172
173<xsl:template name="length"><xsl:param name="text"/><xsl:param name="prefix"/><xsl:param name="length"/>
174    <xsl:variable select="substring-before(substring($text, 1,
175                                    $length - $prefix + string-length($br)),
176                                    $br)" name="break"/>
177
178    <xsl:choose>
179        <xsl:when test="$break"> <xsl:value-of select="string-length($break)"/> </xsl:when>
180
181        <xsl:when test="$length = 0"> <xsl:value-of select="$max - $prefix"/> </xsl:when>
182
183        <xsl:when test="string-length($text) + $prefix &lt;= $length">
184            <xsl:value-of select="$length - $prefix"/>
185        </xsl:when>
186
187        <xsl:when test="substring($text, $length - $prefix + 1, 1) = ' '">
188            <xsl:value-of select="$length - $prefix + 1"/>
189        </xsl:when>
190
191        <xsl:otherwise>
192            <xsl:call-template name="length"><xsl:with-param select="$text" name="text"/><xsl:with-param select="$prefix" name="prefix"/><xsl:with-param select="$length - 1" name="length"/></xsl:call-template></xsl:otherwise>
193    </xsl:choose>
194</xsl:template>
195
196
197<xsl:template name="day_of_week"><xsl:param name="date"/>
198    <xsl:param select="substring-before($date, '-')" name="year"/>
199    <xsl:param select="substring-before(substring-after($date, '-'), '-')" name="month"/>
200    <xsl:param select="substring-after(substring-after($date, '-'), '-')" name="day"/>
201
202    <xsl:variable select="floor((14 - $month) div 12)" name="a"/>
203
204    <xsl:variable select="$year - $a" name="y"/>
205
206    <xsl:variable select="$month + 12 * $a - 2" name="m"/>
207
208    <xsl:value-of select="($day + $y + floor($y div 4) - floor($y div 100)
209    + floor($y div 400) + floor((31 * $m) div 12)) mod 7 + 1"/>
210</xsl:template>
211
212
213<xsl:template name="padded_day"><xsl:param name="date"/>
214    <xsl:value-of select="substring(concat('  ', format-number(substring($date, 9, 2), '##')),
215           1 + string-length(format-number(substring($date, 9, 2), '##')))"/>
216</xsl:template>
217
218
219<xsl:template name="string_in_list"><xsl:param name="list"/><xsl:param name="string"/>
220    <xsl:choose>
221        <xsl:when test="contains($list, ' ')">
222            <xsl:variable select="substring-before($list, ' ')" name="str"/>
223            <xsl:choose>
224                <xsl:when test="$str=$string">
225                    <xsl:value-of select="$string"/>
226                </xsl:when>
227                <xsl:otherwise>
228                    <xsl:call-template name="string_in_list"><xsl:with-param select="substring-after($list, ' ')" name="list"/><xsl:with-param select="$string" name="string"/></xsl:call-template></xsl:otherwise>
229            </xsl:choose>
230        </xsl:when>
231        <xsl:otherwise>
232            <xsl:if test="$list=$string"> <xsl:value-of select="$string"/> </xsl:if>
233            <xsl:if test="$list='*'"> <xsl:value-of select="$string"/> </xsl:if>
234        </xsl:otherwise>
235    </xsl:choose>
236</xsl:template>
237
238
239<xsl:template name="beautify"><xsl:param name="pkgname"/>
240    <xsl:choose>
241        <xsl:when test="$pkgname='unit'">Unit</xsl:when>
242        <xsl:otherwise>
243            <xsl:value-of select="$pkgname"/>
244        </xsl:otherwise>
245    </xsl:choose>
246</xsl:template>
247
248
249<xsl:template match="at">@</xsl:template>
250<xsl:template match="br"> <xsl:value-of select="$br"/> </xsl:template>
251<xsl:template match="nobr"> <xsl:value-of select="translate(., ' ', '&#xA0;')"/> </xsl:template>
252
253
254</xsl:stylesheet>
255