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